/***********************************/ /* Quasigroup Completion Problem */ /* Applet */ /* */ /* */ /* Written by Tammy Bailey */ /* July-August 1997 */ /***********************************/ import java.applet.*; import java.awt.*; import java.net.URL; import java.net.MalformedURLException; public class QCPdemo extends Applet implements Runnable { /********************************************************************/ /* WIDTH -- width of the QCP board */ /* BARWIDTH -- width of the manual preplacement bar */ /* N -- order of the QCP */ /* maxRandomPP -- maximum number of squares drawn in */ /* random preplacement method, applet stops if */ /* this number is exceeded */ /********************************************************************/ final int WIDTH = 350, BARWIDTH = WIDTH + 20, N = 10, maxRandomPP = 3000; int square[], PREPLACED[], counter[], fillCount[], ORDER[], COLORSUSED[][], COLORARRAY[], RANDOMARRAY[], ARRAYSIZE, COLORARRAYSIZE[], MAXARRAY[], colorCount[], maxNumBacktracks = 500, oldMaxNumBacktracks, upperBoundBT, delayOption = 0, upperBoundSP, solveClick, place, place1, colour, colour1, backtrackCount, randomValue, randomValue2, oldRandomValue, oldDelayOption, randomPPCount, nextSquare, numberOfEmptySquares; Point barPoint, boardPoint, optionPoint; boolean PPcolour1, PPplace1, manualPP, arrowMouse, randomMouse, solveMouse, manualPreplacementMouse, manualMouse, patternMouse, patternSelectMouse, backMouse, optionMouse, helpMouse, RANDOM, FAIL, MAXIMUM, ROW, COLUMN, SOLUTION, PAUSE; Image imagePhase, imageComplex, imageArrowUp, imageArrowDown, imageArrowPoint, imagePointer, imagePattern1, imagePattern2, imagePattern3, imagePattern4, imagePattern5; Color squareColor[]; MediaTracker tracker; String targetURL; public void init() { tracker = new MediaTracker(this); String image1 = "phase.gif"; String param1 = getParameter("imagePhase"); if(param1 != null) image1 = param1; imagePhase = getImage(getCodeBase(), image1); tracker.addImage(imagePhase,0); String image2 = "complexityGraph.gif"; String param2 = getParameter("imageComplex"); if(param2 != null) image2 = param2; imageComplex = getImage(getCodeBase(), image2); tracker.addImage(imageComplex,0); String image3 = "ArrowUp.gif"; String param3 = getParameter("imageArrowUp"); if(param3 != null) image3 = param3; imageArrowUp = getImage(getCodeBase(), image3); tracker.addImage(imageArrowUp,0); String image4 = "ArrowDown.gif"; String param4 = getParameter("imageArrowDown"); if(param4 != null) image4 = param4; imageArrowDown = getImage(getCodeBase(), image4); tracker.addImage(imageArrowDown,0); String image5 = "ArrowPoint.gif"; String param5 = getParameter("imageArrowPoint"); if(param5 != null) image5 = param5; imageArrowPoint = getImage(getCodeBase(), image5); tracker.addImage(imageArrowPoint,0); String image6 = "pattern1.gif"; String param6 = getParameter("imagePattern1"); if(param6 != null) image6 = param6; imagePattern1 = getImage(getCodeBase(), image6); tracker.addImage(imagePattern1,0); String image7 = "pattern2.gif"; String param7 = getParameter("imagePattern2"); if(param7 != null) image7 = param7; imagePattern2 = getImage(getCodeBase(), image7); tracker.addImage(imagePattern2,0); String image8 = "pattern3.gif"; String param8 = getParameter("imagePattern3"); if(param8 != null) image8 = param8; imagePattern3 = getImage(getCodeBase(), image8); tracker.addImage(imagePattern3,0); String image9 = "pattern4.gif"; String param9 = getParameter("imagePattern4"); if(param9 != null) image9 = param9; imagePattern4 = getImage(getCodeBase(), image9); tracker.addImage(imagePattern4,0); String image10 = "pattern5.gif"; String param10 = getParameter("imagePattern5"); if(param10 != null) image10 = param10; imagePattern5 = getImage(getCodeBase(), image10); tracker.addImage(imagePattern5,0); String image11 = "pointer.gif"; String param11 = getParameter("imagePointer"); if(param11 != null) image11 = param11; imagePointer = getImage(getCodeBase(), image11); tracker.addImage(imagePointer,0); PREPLACED = new int [N*N]; for (int i = 0; i < N*N; i++) PREPLACED[i] = -1; square = new int [N*N]; for (int i = 0; i < N*N; i++) square[i]=-1; counter = new int [N*N]; for(int i = 0; i < N*N; i++) counter[i]=0; colorCount = new int [N*N]; for(int i = 0; i < N*N; i++) colorCount[i]=0; fillCount = new int [N*N]; for(int i = 0; i < N*N; i++) fillCount[i]=0; ORDER = new int [N*N]; for (int i = 0; i < N*N; i++) ORDER[i]=-1; COLORSUSED = new int [N*N][N]; for (int i = 0; i < N*N; i++) for (int j = 0; j < N; j++) COLORSUSED[i][j]=-1; RANDOMARRAY = new int [N*N]; for (int i = 0; i < N*N; i++) RANDOMARRAY[i]=i; COLORARRAY = new int [N]; for (int j = 0; j < N; j++) COLORARRAY[j]=-1; COLORARRAYSIZE = new int [N*N]; for (int i = 0; i < N*N; i++) COLORARRAYSIZE[i]=0; MAXARRAY = new int [N*N]; for (int i = 0; i < N*N; i++) MAXARRAY[i]=0; ARRAYSIZE = 0; colour = 0; solveClick = 0; arrowMouse = false; randomMouse = true; solveMouse = false; manualPreplacementMouse = false; manualMouse = true; patternMouse = true; backMouse = false; optionMouse = false; helpMouse = true; PPcolour1=false; PPplace1=false; manualPP = false; MAXIMUM = false; RANDOM = false; FAIL = false; ROW = true; COLUMN = true; randomValue = 0; randomValue2 = 0; backtrackCount = 0; randomPPCount = 0; numberOfEmptySquares=0; upperBoundBT = 2000; upperBoundSP = 100; targetURL = getParameter("URL"); } /***********/ /* Start */ /***********/ public void start() { makeColors(); try { tracker.waitForID(0); } catch(InterruptedException e) { } repaint(); } /*********/ /* Run */ /*********/ public void run() { } /**********/ /* Stop */ /**********/ public void stop() { } /************************************/ /* Method used to create a delay. */ /************************************/ void pause(int pauseTime) { try { Thread.sleep(pauseTime); } catch(InterruptedException e) { } } /***********/ /* Paint */ /***********/ public void paint(Graphics g) { setBackground(Color.white); g.setColor(Color.lightGray); g.fill3DRect(0, 355, 70, 30, true); g.fill3DRect(280, 355, 70, 30, true); g.fill3DRect(0, 390, 70, 30, true); g.fill3DRect(280, 390, 70, 30, true); g.fill3DRect(360, 355, 50, 30, true); g.fill3DRect(0, 425, 70, 30, true); g.fill3DRect(280, 425, 70, 30, true); g.setColor(Color.black); g.drawString("MANUAL", 8, 375); g.drawString("RANDOM", 8, 410); g.drawString("PATTERNS", 5, 445); g.drawString("RUN",303, 367); g.drawString("Determine",283, 380); g.drawString("RUN", 303, 402); g.drawString("Stochastic",284, 415); g.drawString("HELP", 369, 375); g.drawString("OPTIONS",288,445); g.drawString("PREPLACEMENT = "+randomValue+" %", 550, 490); drawBoard(g); g.drawImage(imageComplex,WIDTH+90,5,this); g.drawImage(imagePhase,WIDTH+90,224,this); } /***************************************/ /* Generator for random preplacement */ /* of squares */ /***************************************/ public void randomNumber() { int numberOfRPS = 0; int randomSquares = (int)(randomValue*.01*N*N); while (numberOfRPS < randomSquares) { int rp = (int)(Math.random() * 100); int rc = (int)(Math.random() * 100); place = rp%(N*N); colour = rc%N; if (square[place] == -1) { randomPPCount++; preplaceSquare(colour, place); if (square[place] != -1) numberOfRPS++; } if (square[place] != -1) { randomPPCount++; preplaceSquare(colour, place); if (square[place] == -1) numberOfRPS--; } if (randomPPCount > maxRandomPP) { FAIL = true; Graphics g = getGraphics(); failedPreplacement(g); break; } } } /****************************************************/ /* Supplement to the PAUSE method -- gives the */ /* graphics time to "catch up" with the algorithm */ /****************************************************/ void waiting() { Graphics g = getGraphics(); for(int z = 0; z < N*N; z++) { if(PREPLACED[z] == -1) { square[z] = -1; counter[z] = 0; removeSquare(z,g); } } } /*******************************************/ /* Deterministic backtracking algorithm. */ /*******************************************/ public void solve (Graphics g) { solveClick++; solveMouse = false; int i = 0; int PPcolumn=0; int PProw=0; backtrackCount = 0; g.setColor(Color.white); g.fillRect(BARWIDTH,0,WIDTH/N+1,WIDTH+1); g.fillRect(0,455,WIDTH,45); g.fillRect(71,355,209,140); for(int z = 0; z < N*N; z++) { if(PREPLACED[z] == -1) { square[z] = -1; counter[z] = 0; removeSquare(z,g); } } if (RANDOM == true && FAIL == false) { randomNumber(); colour = 0; if(randomValue != 0) { waiting(); waiting(); waiting(); pause(2500); } } if(solveClick > 1) { waiting(); waiting(); waiting(); pause(3000); } RANDOM = false; while(i < N*N) { pause(delayOption); if(FAIL == true) break; g.setColor(Color.black); g.drawString("Solving ...", 150,395); for (int c = colour; c < N; c++) { PPcolumn=0; PProw=0; if(square[i] == -1) { drawSquare(c,i,g); square[i] = c; counter[i]++; } for (int k = 0; k < N; k++) { if (k != (i-i%N)/N && square[N*k+i%N] == square[i]) removeSquare(i,g); if (PREPLACED[N*k+i%N] == 1) PPcolumn++; } for (int m = 0; m < N; m++) { if (m != i%N && square[(i-i%N)+m] == square[i]) removeSquare(i,g); if(PREPLACED[(i-i%N)+m] == 1) PProw++; } if (square[i] != -1) break; } colour=0; if (square[i] == -1 && PPcolumn == N-1) { noSolution(backtrackCount, g); SOLUTION = false; colour=0; break; } if (square[i] == -1 || counter[i] >= N+1) { backtrackCount++; for (int x = 1; x <= i; x++){ if (PREPLACED[(i-x)] == -1) { for (int k = i; k < N*N; k++) counter[k]=0; colour = (square[i-x]+1)%N; for (int k = (i-x); k <=i; k++) { if (PREPLACED[k] == -1) removeSquare(k,g); } i=(i-x-1); if (i==-2) { noSolution(backtrackCount,g); colour=0; } break; } } } if (i != -1) { if (square[i] == -1 && PProw == N-1) { noSolution(backtrackCount, g); colour=0; break; } if (square[i] == -1 || counter[i] >= N+1) { noSolution(backtrackCount, g); colour=0; break; } if (backtrackCount > maxNumBacktracks) { maxBacktracks(backtrackCount, g); colour=0; break; } } i++; if (i == N*N) { yesSolution(backtrackCount, g); colour = 0; } } } /***************************************/ /* Stochastic backtracking algorithm */ /***************************************/ public void solveTwo (Graphics g) { solveClick++; solveMouse = false; ARRAYSIZE = 0; numberOfEmptySquares = 0; int i = 0; backtrackCount = 0; g.setColor(Color.white); g.fillRect(BARWIDTH,0,WIDTH/N+1,WIDTH+1); g.fillRect(0,455,WIDTH,45); g.fillRect(71,355,209,140); for(int z = 0; z < N*N; z++) { if(PREPLACED[z] == -1) { numberOfEmptySquares++; removeSquare(z,g); square[z] = -1; RANDOMARRAY[ARRAYSIZE] = z; ARRAYSIZE++; } colorCount[z]=0; fillCount[z]=0; ORDER[z]=-1; COLORARRAYSIZE[z]=0; MAXARRAY[z]=0; } for (int y = 0; y < N; y++) COLORARRAY[y]=-1; for (int z = 0; z < N*N; z++) for (int y = 0; y < N; y++) COLORSUSED[z][y]=-1; place = ((int)(Math.random() * 100))%(ARRAYSIZE); colour = ((int)(Math.random() * 100))%N; int p = RANDOMARRAY[place]; int c = colour; if (RANDOM == true && FAIL == false) { randomNumber(); colour = 0; if(randomValue != 0) { waiting(); waiting(); waiting(); pause(2500); } } if(solveClick > 1) { waiting(); waiting(); waiting(); pause(3000); } RANDOM = false; while(i < numberOfEmptySquares) { if(FAIL == true) break; pause(delayOption); g.setColor(Color.black); g.drawString("Solving ...", 150,395); square[p]=c; for (int k = 0; k < N; k++) { if (k != (p-p%N)/N && square[N*k+p%N] == square[p]) COLUMN = false; } for (int m = 0; m < N; m++) { if (m != p%N && square[(p-p%N)+m] == square[p]) ROW = false; } if(ROW == true && COLUMN == true) { drawSquare(c,p,g); ORDER[i] = p; COLORSUSED[p][c] = 1; ARRAYSIZE = 0; for(int z = 0; z < N*N; z++) { if(square[z] == -1) { RANDOMARRAY[ARRAYSIZE] = z; ARRAYSIZE++; } } if(ARRAYSIZE == 0) { yesSolution(backtrackCount,g); break; } pickNextSquare(); p = nextSquare; c = ((int)(Math.random() * 100))%(N); i++; } if(ROW == false || COLUMN == false) { square[p] = -1; COLORSUSED[p][c] = 1; colorCount[p]=0; for(int j = 0; j < N; j++) if(COLORSUSED[p][j] == 1) colorCount[p]++; if(colorCount[p] != N) { int l = 0; for(int j = 0; j < N; j++) { if(COLORSUSED[p][j] == -1) { COLORARRAY[l]=j; l++; } } colour = ((int)(Math.random() * 100))%(l); c = COLORARRAY[colour]; } if(colorCount[p] == N && i == 0) { noSolution(backtrackCount,g); break; } if(colorCount[p] == N && i != 0) { backtrackCount++; for(int j = 0; j < N; j++) COLORSUSED[p][j] = -1; colorCount[p]=0; square[p]=-1; int f = i; for (int x = 1; x <= f; x++) { p = ORDER[f-x]; square[p]=-1; int k = 0; for(int j = 0; j < N; j++) { if(COLORSUSED[p][j] == -1) { COLORARRAY[k]=j; k++; } } i=f-x; if(k == 0) { for(int j = 0; j < N; j++) { COLORSUSED[p][j] = -1; colorCount[p]=0; COLORARRAY[j]=-1; } colorCount[p]=0; } if(k !=0) { colour = ((int)(Math.random() * 100))%(k); c = COLORARRAY[colour]; break; } } } } if (i == numberOfEmptySquares) { yesSolution(backtrackCount, g); break; } if(backtrackCount > maxNumBacktracks) { maxBacktracks(backtrackCount, g); break; } ROW = true; COLUMN = true; } } /*****************************************************/ /* How the solveTwo method selects the next square */ /*****************************************************/ public void pickNextSquare() { int maxCount = 0; int max = 0; for(int i = 0; i < ARRAYSIZE; i++) { fillCount[i]=0; for (int k = 0; k < N; k++) { if(square[N*k+(RANDOMARRAY[i])%N] != -1) fillCount[i]++; } for (int m = 0; m < N; m++) { if (square[((RANDOMARRAY[i])-(RANDOMARRAY[i])%N)+m] != -1) fillCount[i]++; } if(fillCount[i] > max) max = fillCount[i]; } int j = 0; for(int i = 0; i < ARRAYSIZE; i++) { if(fillCount[i] == max) { MAXARRAY[j]=RANDOMARRAY[i]; maxCount++; j++; } } place = ((int)(Math.random() * 100))%(maxCount); nextSquare=MAXARRAY[place]; } /************************/ /* Draw the QCP board */ /************************/ void drawBoard(Graphics g) { g.setColor(Color.black); g.drawLine(0,0, 0,WIDTH); g.drawLine(WIDTH,WIDTH, 0,WIDTH); g.drawLine(0,0, WIDTH,0); g.drawLine(WIDTH,0, WIDTH,WIDTH); for (int i = 0; i < N; i++) { g.drawLine(WIDTH*i/N,0, WIDTH*i/N, WIDTH); g.drawLine(0,WIDTH*i/N, WIDTH,WIDTH*i/N); } } /******************************/ /* Clear the QCP board */ /* (only used for patterns) */ /******************************/ void cleanBoard(Graphics g) { for(int z = 0; z < N*N; z++) { square[z] = -1; counter[z] = 0; removeSquare(z,g); } } /**************************************/ /* Draw the manual preplacement bar */ /**************************************/ void drawBar(Graphics g) { g.setColor(Color.black); g.drawLine(BARWIDTH,0, BARWIDTH+(WIDTH/N),0); g.drawLine(BARWIDTH + (WIDTH/N),0, BARWIDTH + (WIDTH/N),WIDTH); g.drawLine(BARWIDTH,WIDTH, BARWIDTH + (WIDTH/N),WIDTH); g.drawLine(BARWIDTH,0, BARWIDTH,WIDTH); for (int i = 0; i < N; i++) { g.setColor(Color.black); g.drawLine(BARWIDTH,WIDTH*i/N, BARWIDTH+(WIDTH/N),WIDTH*i/N); g.setColor(squareColor[i]); g.fill3DRect(BARWIDTH + 2, WIDTH*i/N + 2, WIDTH/N - 3, WIDTH/N - 3, true); } } /****************************************/ /* Draw a colored square on the board */ /****************************************/ public void drawSquare(int clr, int p, Graphics g) { g.setColor(squareColor[clr]); int column = ((p-(p%N))/N); int row = p%N; g.fill3DRect(column * WIDTH / N + 2, row * WIDTH / N + 2, WIDTH / N - 3, WIDTH / N - 3, true); square[p] = clr; } /********************************************/ /* Remove a colored square from the board */ /* by coloring it white */ /********************************************/ public void removeSquare(int p, Graphics g) { g.setColor(Color.white); int column = ((p-(p%N))/N); int row = p%N; g.fillRect(column * WIDTH / N + 2, row * WIDTH / N + 2, WIDTH / N - 3, WIDTH / N - 3); square[p] = -1; } /*********************/ /* Create N colors */ /*********************/ public void makeColors() { squareColor = new Color[N]; squareColor[0] = Color.red; squareColor[1] = Color.orange; squareColor[2] = Color.yellow; squareColor[3] = Color.green; squareColor[4] = Color.blue; squareColor[5] = Color.pink; squareColor[6] = Color.magenta; squareColor[7] = Color.cyan; squareColor[8] = Color.lightGray; squareColor[9] = Color.black; } /************************************************************/ /* Method used for manual/random preplacement of squares. */ /* Checks the row and column of the square to be placed */ /************************************************************/ public void preplaceSquare(int c,int p) { int column = ((p-(p%N))/N); int row = p%N; Graphics g = getGraphics(); g.setColor(Color.white); g.fillRect(0,455,WIDTH,45); g.setColor(squareColor[c]); g.fill3DRect(column * WIDTH / N + 2, row * WIDTH / N + 2, WIDTH / N - 3, WIDTH / N - 3, true); square[p] = c; PREPLACED[p] = 1; for (int k = 0; k < N; k++) { if ((k != (p-p%N)/N) && (square[N*k+p%N] == c) && (square[p] == c)) { removeSquare(p,g); PREPLACED[p] = -1; if (manualPP == true) invalidPreplacement(g); } } for (int m = 0; m < N; m++) { if ((m != p%N) && (square[(p-p%N)+m] == c) && (square[p] == c)) { removeSquare(p,g); PREPLACED[p] = -1; if (manualPP == true) invalidPreplacement(g); } } PPplace1 = false; if (manualPP == true) manualPreplacementLabel(g); } /*********************************************************************/ /* The following display messages in the comment box of the Applet */ /*********************************************************************/ void noSolution(int bc, Graphics g) { g.setColor(Color.red); g.fill3DRect(0, 460, 150, 30, true); g.setColor(Color.lightGray); g.fill3DRect(200, 460, 150, 30, true); g.setColor(Color.white); g.drawString("Proved Unsolvable !", 15, 480); g.drawString("Solving ...", 150,395); g.setColor(Color.black); g.drawString("# Backtracks = "+bc, 220, 480); manualMouse = true; randomMouse = true; solveMouse = true; patternMouse = true; helpMouse = true; } void yesSolution(int bc, Graphics g) { g.setColor(Color.green); g.fill3DRect(0, 460, 150, 30, true); g.setColor(Color.lightGray); g.fill3DRect(200, 460, 150, 30, true); g.setColor(Color.white); g.drawString("Solution !", 45, 480); g.drawString("Solving ...", 150,395); g.setColor(Color.black); g.drawString("# Backtracks = "+bc, 220, 480); manualMouse = true; randomMouse = true; solveMouse = true; patternMouse = true; helpMouse = true; } void maxBacktracks(int bc, Graphics g) { g.setColor(Color.blue); g.fill3DRect(10, 460, 330, 30, true); g.setColor(Color.white); g.drawString("Exceeded Maximum: Number of Backtracks = "+bc, 19, 480); g.drawString("Solving ...", 150,395); manualMouse = true; randomMouse = true; solveMouse = true; patternMouse = true; helpMouse = true; } void invalidPreplacement(Graphics g) { if(manualPP == true) { g.setColor(Color.yellow); g.fill3DRect(100, 460, 150, 30, true); g.setColor(Color.black); g.drawString("Invalid Preplacement", 110, 480); } } void failedPreplacement(Graphics g) { g.setColor(Color.yellow); g.fill3DRect(55, 460, 240, 30, true); g.setColor(Color.black); g.drawString("Random Preplacement Failed", 82, 480); g.setColor(Color.white); g.drawString("Solving ...", 150,395); solveMouse = false; manualMouse = true; randomMouse = true; patternMouse = true; helpMouse = true; } /*******************/ /* Mouse actions */ /*******************/ public synchronized boolean mouseDown(Event event, int x, int y) { Graphics g =getGraphics(); barPoint=new Point(x,y); boardPoint = new Point(x,y); optionPoint = new Point(x,y); /**************************************************************/ /* Records the color clicked on the manual preplacement bar */ /**************************************************************/ for (int i = 0; i < N; i++) { if((barPoint.x > BARWIDTH) && (barPoint.x < (BARWIDTH + WIDTH/N)) && (barPoint.y > WIDTH*i/N) && (barPoint.y < WIDTH*(i+1)/N)) { colour1=i; PPcolour1 = true; } /***************************************************/ /* Records the position clicked on the QCP board */ /***************************************************/ for (int j = 0; j < N*N; j++) { int column = ((j-(j%N))/N); int row = j%N; if((boardPoint.x > WIDTH*(column)/N) && (boardPoint.x < WIDTH*(column+1)/N) && (boardPoint.y > WIDTH*(row)/N) && (boardPoint.y < WIDTH*(row+1)/N)) { place1 = j; PPplace1 = true; } } /********************************************************/ /* If the user has clicked both a color and a square, */ /* try to preplace a square. */ /********************************************************/ if(PPcolour1==true && PPplace1==true && solveMouse==true && manualPreplacementMouse == true) { manualPP = true; randomMouse = false; arrowMouse = false; preplaceSquare(colour1, place1); } } /**********************************/ /* Clicking on the Option 1 bar */ /**********************************/ for(int a = 5; a <= 285; a++) { if((optionPoint.x > a-1) && (optionPoint.x < a+1) && (optionPoint.y > 380) && (optionPoint.y < 405) && optionMouse == true) { drawOptionBarOne(g); int m = ((upperBoundBT)*(a-10))/2700; if(m*10 < 0) maxNumBacktracks = 0; if(m*10 > upperBoundBT) maxNumBacktracks = upperBoundBT; if(m*10 >= 0 && m*10 <= upperBoundBT) maxNumBacktracks = m*10; g.setColor(Color.white); g.drawString(""+oldMaxNumBacktracks,304,394); g.setColor(Color.black); g.drawString(""+maxNumBacktracks,304,394); oldMaxNumBacktracks = maxNumBacktracks; g.drawImage(imagePointer,a-5,400,this); } } /**********************************/ /* Clicking on the Option 2 bar */ /**********************************/ for(int b = 5; b <= 285; b++) { if((optionPoint.x > b-1) && (optionPoint.x < b+1) && (optionPoint.y > 450) && (optionPoint.y < 475) && optionMouse == true) { drawOptionBarTwo(g); int d = ((upperBoundSP)*(b-10))/2700; if(d*10 < 0) delayOption = 0; if(d*10 > upperBoundSP) delayOption = upperBoundSP; if(d*10 >= 0 && d*10 <= upperBoundSP) delayOption = d*10; g.setColor(Color.white); g.drawString(""+oldDelayOption,304,464); g.setColor(Color.black); g.drawString(""+delayOption,304,464); oldDelayOption = delayOption; g.drawImage(imagePointer,b-5,470,this); } } /***********************************/ /* Clicking the "MANUAL" button */ /***********************************/ if(x > 0 && x < 70 && y > 355 && y < 385 && manualMouse == true) { manualMode(g); } /**********************************/ /* Clicking the "RANDOM" button */ /**********************************/ if(x > 0 && x < 70 && y > 390 && y < 420 && randomMouse == true) { randomMode(g); } /************************************/ /* Clicking the "PATTERNS" button */ /************************************/ if(x > 0 && x < 70 && y > 425 && y < 455 && patternMouse == true) { patternMode(g); } /*********************************/ /* Clicking the "RUN D" button */ /*********************************/ if(x > 280 && x < 350 && y > 355 && y < 385) { if (solveMouse == true) { g.setColor(Color.red); g.drawRect(280,355,69,29); g.setColor(Color.lightGray); g.draw3DRect(280,390,69,29,true); g.draw3DRect(280,425,69,29,true); randomMouse = false; arrowMouse = false; manualPreplacementMouse = false; manualMouse = false; patternMouse = false; patternSelectMouse = false; helpMouse = false; solve(g); } } /*********************************/ /* Clicking the "RUN S" button */ /*********************************/ if(x > 280 && x < 350 && y > 390 && y < 420) { if (solveMouse == true) { g.setColor(Color.red); g.drawRect(280,390,69,29); g.setColor(Color.lightGray); g.draw3DRect(280,355,69,29,true); g.draw3DRect(280,425,69,29,true); randomMouse = false; arrowMouse = false; manualPreplacementMouse = false; manualMouse = false; patternMouse = false; patternSelectMouse = false; helpMouse = false; solveTwo(g); } } /***********************************/ /* Clicking the "OPTIONS" button */ /***********************************/ if(x > 280 && x < 350 && y > 425 && y < 455) { g.setColor(Color.red); g.drawRect(280,425,69,29); g.setColor(Color.lightGray); g.draw3DRect(280,390,69,29,true); g.draw3DRect(280,355,69,29,true); optionMode(g); } /********************************/ /* Clicking the "HELP" button */ /********************************/ if(x > 360 && x < 410 && y > 360 && y < 390 && helpMouse == true) { try { getAppletContext().showDocument(new URL(getCodeBase(),"QCPHelp.html")); } catch (MalformedURLException e) { System.err.println(e); } } /********************************/ /* Clicking the "BACK" button */ /********************************/ if(x > 355 && x < 395 && y > 460 && y < 490) { repaint(0,355, WIDTH+89,140); manualPreplacementMouse = false; manualMouse = true; randomMouse = true; solveMouse = true; arrowMouse = false; patternMouse = true; patternSelectMouse = false; backMouse = false; optionMouse = false; helpMouse = true; solveClick = 0; } /*************************************/ /* Clicking the "PATTERN 1" button */ /*************************************/ if(x > 75 && x < 136 && y > 360 && y < 421 && patternSelectMouse == true) { cleanBoard(g); patternOne(g); } /*************************************/ /* Clicking the "PATTERN 2" button */ /*************************************/ if(x >143 && x < 204 && y > 360 && y < 421 && patternSelectMouse == true) { cleanBoard(g); patternTwo(g); } /*************************************/ /* Clicking the "PATTERN 3" button */ /*************************************/ if(x > 214 && x < 275 && y > 360 && y < 421 && patternSelectMouse == true) { cleanBoard(g); patternThree(g); } /*************************************/ /* Clicking the "PATTERN 4" button */ /*************************************/ if(x > 105 && x < 166 && y > 426 && y < 487 && patternSelectMouse == true) { cleanBoard(g); patternFour(g); } /*************************************/ /* Clicking the "PATTERN 5" button */ /*************************************/ if(x > 178 && x < 239 && y > 426 && y < 487 && patternSelectMouse == true) { cleanBoard(g); patternFive(g); } /************************************************/ /* Clicking the "Up" arrow (increment by one) */ /************************************************/ if(x > 125 && x < 155 && y > 375 && y < 405 && arrowMouse == true) { if(randomValue >= 0 && randomValue <= 100) { randomValue++; if (randomValue == 101) { randomValue=0; g.setColor(Color.white); g.drawString("100 %", 160, 400); g.drawString("100 %", 662, 490); } else { g.setColor(Color.white); g.drawString(+(randomValue-1)+ " %", 160, 400); g.drawString(+(randomValue-1)+ " %", 662, 490); } g.setColor(Color.black); g.drawString(+randomValue+" %", 160, 400); g.drawString(+randomValue+" %", 662, 490); phaseTransitionBar(randomValue, g); complexityBar(randomValue, g); return true; } else return false; } /*******************************************/ /* Clicking the "+10" (increment by ten) */ /*******************************************/ if(x > 95 && x < 140 && y > 405 && y < 425 && arrowMouse == true) { if(randomValue >= 0 && randomValue <= 100) { g.setColor(Color.white); g.drawString(+(randomValue)+" %", 160, 400); g.drawString(+(randomValue)+" %", 662, 490); randomValue = randomValue+10; if(randomValue > 100) randomValue = randomValue - 100; g.setColor(Color.black); g.drawString(+randomValue+" %", 160, 400); g.drawString(+randomValue+" %", 662, 490); phaseTransitionBar(randomValue, g); complexityBar(randomValue, g); return true; } else return false; } /**************************************************/ /* Clicking the "Down" arrow (decrement by one) */ /**************************************************/ if(x > 195 && x < 225 && y > 375 && y < 405 && arrowMouse == true) { if(randomValue >= 0 && randomValue <= 100) { randomValue--; if (randomValue == -1) randomValue = 100; g.setColor(Color.white); g.drawString(+(randomValue+1)%101+" %", 160, 400); g.drawString(+(randomValue+1)%101+" %", 662, 490); g.setColor(Color.black); g.drawString(+randomValue+" %", 160, 400); g.drawString(+randomValue+" %", 662, 490); phaseTransitionBar(randomValue, g); complexityBar(randomValue, g); return true; } else return false; } /*******************************************/ /* Clicking the "-10" (decrement by ten) */ /*******************************************/ if(x > 210 && x < 255 && y > 405 && y < 425 && arrowMouse == true) { if(randomValue >= 0 && randomValue <= 100) { g.setColor(Color.white); g.drawString(+(randomValue)+" %", 160, 400); g.drawString(+(randomValue)+" %", 662, 490); randomValue = randomValue-10; if (randomValue < 0 ) randomValue = 100 + randomValue; g.setColor(Color.black); g.drawString(+randomValue+" %", 160, 400); g.drawString(+randomValue+" %", 662, 490); phaseTransitionBar(randomValue, g); complexityBar(randomValue, g); return true; } else return false; } return true; } /**********************************************************/ /* Display the percentage of preplacement when manually */ /* preplacing squares */ /**********************************************************/ public void manualPreplacementLabel(Graphics g) { int randomSquares2 = 0; for(int i = 0; i < N*N; i++) { if (square[i] != -1) randomSquares2++; } g.setColor(Color.white); g.drawString(+randomValue2+" %", 662, 490); g.setColor(Color.black); g.drawString(+(int)(randomSquares2*100/(N*N))+ " %", 662, 490); randomValue2 = (int)(randomSquares2*100/(N*N)); phaseTransitionBar(randomValue2, g); complexityBar(randomValue2, g); } /**********************************************************************/ /* Draw a bar and pointer at the level of preplacement on the Phase */ /* Transition graph when manually or randomly preplacing squares */ /**********************************************************************/ void phaseTransitionBar(int rv, Graphics g) { if(rv <= 90 && rv >= 0) { g.drawImage(imagePhase,WIDTH+90,224,this); int x = (int)(rv*275/90 + WIDTH + 130); g.setColor(Color.red); g.drawLine(x-1,262, x-1,437); g.drawLine(x+1,262, x+1,437); g.setColor(Color.black); g.drawLine(x,262, x,437); g.drawImage(imageArrowPoint,x+5,448,this); } else g.drawImage(imagePhase,WIDTH+90,224,this); } /*******************************************************************/ /* Draw a bar and pointer at the level of preplacement on the */ /* Complexity graph when manually or randomly preplacing squares */ /*******************************************************************/ void complexityBar(int rv, Graphics g) { if(rv <= 90 && rv >= 0) { g.drawImage(imageComplex,WIDTH+90,5,this); int x = (int)(rv*275/90 + WIDTH + 129); g.setColor(Color.red); g.drawLine(x-1,29, x-1,204); g.drawLine(x+1,29, x+1,204); g.setColor(Color.black); g.drawLine(x,29, x,204); g.drawImage(imageArrowPoint,x+5,215,this); } else g.drawImage(imageComplex,WIDTH+90,5,this); } /****************************************************************/ /* Methods for the MODES (Manual, Random, Patterns, Options) */ /****************************************************************/ /*****************/ /* Manual Mode */ /*****************/ public void manualMode(Graphics g) { repaint(0,0,WIDTH,WIDTH); phaseTransitionBar(0, g); complexityBar(0,g); g.setColor(Color.white); g.drawString(+randomValue+" %",662,490); g.drawString(+randomValue2+" %",662,490); init(); g.setColor(Color.black); g.drawString(+randomValue2+" %",662,490); g.setColor(Color.white); g.fillRect(71,355,209,140); g.fillRect(0,455,WIDTH,45); drawBar(g); manualPreplacementMouse = true; manualMouse = true; randomMouse = true; patternMouse = true; patternSelectMouse = false; solveMouse = true; arrowMouse = false; RANDOM = false; g.setColor(Color.red); g.drawRect(0,355,69,29); g.setColor(Color.lightGray); g.draw3DRect(280,390,69,29,true); g.draw3DRect(280,355,69,29,true); g.draw3DRect(280,425,69,29,true); g.draw3DRect(0,390,69,29,true); g.draw3DRect(0,425,69,29,true); } /*****************/ /* Random Mode */ /*****************/ public void randomMode(Graphics g) { repaint(0,0,WIDTH,WIDTH); phaseTransitionBar(0, g); complexityBar(0,g); g.setColor(Color.white); g.drawString(+randomValue+" %",662,490); g.drawString(+randomValue2+" %",662,490); init(); g.setColor(Color.white); g.fillRect(BARWIDTH,0,WIDTH/N+1,WIDTH+1); g.fillRect(0,455,WIDTH,45); g.fillRect(71,355,209,140); manualPreplacementMouse = false; manualMouse = true; randomMouse = true; solveMouse = true; arrowMouse = true; patternMouse = true; patternSelectMouse = false; g.drawImage(imageArrowUp,95,375,this); g.setColor(Color.black); g.drawString(+randomValue+" %",160,400); g.drawString(+randomValue+" %",662,490); g.drawImage(imageArrowDown,195,375,this); RANDOM = true; g.setColor(Color.lightGray); g.draw3DRect(280,390,69,29,true); g.draw3DRect(280,355,69,29,true); g.draw3DRect(280,425,69,29,true); g.draw3DRect(0,355,69,29,true); g.draw3DRect(0,425,69,29,true); g.setColor(Color.red); g.drawRect(0,390,69,29); } /******************/ /* Pattern Mode */ /******************/ public void patternMode(Graphics g) { repaint(0,0,WIDTH,WIDTH); g.setColor(Color.white); g.drawString(+randomValue+" %",662,490); g.drawString(+randomValue2+" %",662,490); init(); g.drawImage(imageComplex,WIDTH+90,5,this); g.drawImage(imagePhase,WIDTH+90,224,this); g.setColor(Color.black); g.drawString(+randomValue2+" %",662,490); g.setColor(Color.white); g.fillRect(0,455,WIDTH,45); g.fillRect(71,355,209,140); g.fillRect(BARWIDTH,0,WIDTH/N+1,WIDTH+1); manualPreplacementMouse = false; manualMouse = true; randomMouse = true; solveMouse = false; arrowMouse = false; patternMouse = true; patternSelectMouse = true; RANDOM = false; g.drawImage(imagePattern1,75, 360,this); g.drawImage(imagePattern2,144, 360,this); g.drawImage(imagePattern3,214, 360,this); g.drawImage(imagePattern4,105, 426,this); g.drawImage(imagePattern5,178, 426,this); g.setColor(Color.lightGray); g.draw3DRect(280,390,69,29,true); g.draw3DRect(280,355,69,29,true); g.draw3DRect(280,425,69,29,true); g.draw3DRect(0,355,69,29,true); g.draw3DRect(0,390,69,29,true); g.setColor(Color.red); g.drawRect(0,425,69,29); } /*****************/ /* Option Mode */ /*****************/ public void optionMode(Graphics g) { waiting(); g.setColor(Color.white); g.fillRect(0,355,WIDTH + 89,140); g.fillRect(BARWIDTH,0,WIDTH/N+1,WIDTH+1); manualPreplacementMouse = false; manualMouse = false; randomMouse = false; solveMouse = false; arrowMouse = false; patternMouse = false; patternSelectMouse = false; helpMouse = false; backMouse = true; optionMouse = true; RANDOM = false; drawOptionBarOne(g); drawOptionBarTwo(g); g.setColor(Color.green); g.fill3DRect(355,460,40,30,true); g.setColor(Color.black); g.drawString("BACK",359,480); oldMaxNumBacktracks = maxNumBacktracks; oldDelayOption = delayOption; int c = (((270*maxNumBacktracks)/upperBoundBT)+10); int d = (((270*delayOption)/upperBoundSP)+10); g.drawImage(imagePointer,c-5,400,this); g.drawImage(imagePointer,d-5,470,this); } /***********************************/ /* Draw the slide bar to set the */ /* max number of backtracks */ /***********************************/ void drawOptionBarOne(Graphics g) { g.setColor(Color.lightGray); g.fill3DRect(0,355,WIDTH,65,true); g.setColor(Color.white); g.fillRect(10,379,270,20); g.fillRect(295,379,45,20); g.setColor(Color.black); g.drawString("0",6,415); g.drawString(""+upperBoundBT,260,415); g.drawLine(10,379,10,399); g.drawLine(280,379,280,399); g.drawLine(10,399,280,399); g.drawString("MAXIMUM NUMBER OF BACKTRACKS",68,369); g.drawString(""+maxNumBacktracks,304,394); for(int z = 1; z <= 17; z++) { int x = (int)(z*15 + 10); g.drawLine(x,389,x,399); } } /***********************************/ /* Draw the slide bar to set the */ /* speed of the algorithms */ /***********************************/ void drawOptionBarTwo(Graphics g) { g.setColor(Color.lightGray); g.fill3DRect(0,425,WIDTH,65,true); g.setColor(Color.white); g.fillRect(10,449,270,20); g.fillRect(295,449,45,20); g.setColor(Color.black); g.drawString("0",6,485); g.drawString(""+upperBoundSP,260,485); g.drawLine(10,449,10,469); g.drawLine(280,449,280,469); g.drawLine(10,469,280,469); g.drawString("SPEED OF ALGORITHM (delay)",87,439); g.drawString(""+delayOption,304,464); for(int z = 1; z <= 17; z++) { int x = (int)(z*15 + 10); g.drawLine(x,459,x,469); } } /***************************************/ /* Draw Pattern One on the QCP board */ /***************************************/ void patternOne(Graphics g) { solveMouse = true; randomValue = 15; phaseTransitionBar(randomValue, g); complexityBar(randomValue, g); g.setColor(Color.black); g.drawRect(74,359,62,62); g.drawRect(73,358,64,64); g.setColor(Color.white); g.drawString("0 %", 662, 490); g.drawString(+(oldRandomValue)+" %", 662, 490); g.drawRect(143,359,62,62); g.drawRect(142,358,64,64); g.drawRect(213,359,62,62); g.drawRect(212,358,64,64); g.drawRect(104,425,62,62); g.drawRect(103,424,64,64); g.drawRect(177,425,62,62); g.drawRect(176,424,64,64); g.setColor(Color.black); g.drawString(+(randomValue)+" %", 662, 490); oldRandomValue = 15; drawSquare(0,3,g); drawSquare(0,12,g); drawSquare(0,21,g); drawSquare(4,25,g); drawSquare(0,30,g); drawSquare(4,34,g); drawSquare(4,43,g); drawSquare(0,44,g); drawSquare(4,52,g); drawSquare(0,55,g); drawSquare(0,66,g); drawSquare(0,77,g); drawSquare(4,79,g); drawSquare(4,88,g); drawSquare(4,97,g); PREPLACED[3]=1; PREPLACED[12]=1; PREPLACED[21]=1; PREPLACED[25]=1; PREPLACED[30]=1; PREPLACED[34]=1; PREPLACED[43]=1; PREPLACED[44]=1; PREPLACED[52]=1; PREPLACED[55]=1; PREPLACED[66]=1; PREPLACED[77]=1; PREPLACED[79]=1; PREPLACED[88]=1; PREPLACED[97]=1; } /***************************************/ /* Draw Pattern Two on the QCP board */ /***************************************/ void patternTwo(Graphics g) { solveMouse = true; randomValue = 27; phaseTransitionBar(randomValue, g); complexityBar(randomValue, g); g.setColor(Color.black); g.drawRect(143,359,62,62); g.drawRect(142,358,64,64); g.setColor(Color.white); g.drawString("0 %", 662, 490); g.drawString(+(oldRandomValue)+" %", 662, 490); g.drawRect(74,359,62,62); g.drawRect(73,358,64,64); g.drawRect(213,359,62,62); g.drawRect(212,358,64,64); g.drawRect(104,425,62,62); g.drawRect(103,424,64,64); g.drawRect(177,425,62,62); g.drawRect(176,424,64,64); g.setColor(Color.black); g.drawString(+(randomValue)+" %", 662, 490); oldRandomValue = 27; drawSquare(0,2,g); drawSquare(1,3,g); drawSquare(7,4,g); drawSquare(6,5,g); drawSquare(0,11,g); drawSquare(1,12,g); drawSquare(7,13,g); drawSquare(2,15,g); drawSquare(6,16,g); drawSquare(0,20,g); drawSquare(1,21,g); drawSquare(7,22,g); drawSquare(2,26,g); drawSquare(6,27,g); drawSquare(1,30,g); drawSquare(7,31,g); drawSquare(2,37,g); drawSquare(6,38,g); drawSquare(7,40,g); drawSquare(2,48,g); drawSquare(6,49,g); drawSquare(3,50,g); drawSquare(2,59,g); drawSquare(3,61,g); drawSquare(3,72,g); drawSquare(3,83,g); drawSquare(3,94,g); PREPLACED[2]=1; PREPLACED[3]=1; PREPLACED[4]=1; PREPLACED[5]=1; PREPLACED[11]=1; PREPLACED[12]=1; PREPLACED[13]=1; PREPLACED[15]=1; PREPLACED[16]=1; PREPLACED[20]=1; PREPLACED[21]=1; PREPLACED[22]=1; PREPLACED[26]=1; PREPLACED[27]=1; PREPLACED[30]=1; PREPLACED[31]=1; PREPLACED[37]=1; PREPLACED[38]=1; PREPLACED[40]=1; PREPLACED[48]=1; PREPLACED[49]=1; PREPLACED[50]=1; PREPLACED[59]=1; PREPLACED[61]=1; PREPLACED[72]=1; PREPLACED[83]=1; PREPLACED[94]=1; } /*****************************************/ /* Draw Pattern Three on the QCP board */ /*****************************************/ void patternThree(Graphics g) { solveMouse = true; randomValue = 42; phaseTransitionBar(randomValue, g); complexityBar(randomValue, g); g.setColor(Color.black); g.drawRect(213,359,62,62); g.drawRect(212,358,64,64); g.setColor(Color.white); g.drawString("0 %", 662, 490); g.drawString(+(oldRandomValue)+" %", 662, 490); g.drawRect(74,359,62,62); g.drawRect(73,358,64,64); g.drawRect(143,359,62,62); g.drawRect(142,358,64,64); g.drawRect(104,425,62,62); g.drawRect(103,424,64,64); g.drawRect(177,425,62,62); g.drawRect(176,424,64,64); g.setColor(Color.black); g.drawString(+(randomValue)+" %", 662, 490); oldRandomValue = 42; drawSquare(0,2,g); drawSquare(1,3,g); drawSquare(7,4,g); drawSquare(6,5,g); drawSquare(0,11,g); drawSquare(1,12,g); drawSquare(7,13,g); drawSquare(2,15,g); drawSquare(6,16,g); drawSquare(0,20,g); drawSquare(1,21,g); drawSquare(7,22,g); drawSquare(2,26,g); drawSquare(6,27,g); drawSquare(1,30,g); drawSquare(7,31,g); drawSquare(2,37,g); drawSquare(6,38,g); drawSquare(7,40,g); drawSquare(2,48,g); drawSquare(6,49,g); drawSquare(3,50,g); drawSquare(4,58,g); drawSquare(9,59,g); drawSquare(5,60,g); drawSquare(3,61,g); drawSquare(4,67,g); drawSquare(9,68,g); drawSquare(8,70,g); drawSquare(5,71,g); drawSquare(3,72,g); drawSquare(4,76,g); drawSquare(9,77,g); drawSquare(8,81,g); drawSquare(5,82,g); drawSquare(3,83,g); drawSquare(4,85,g); drawSquare(9,86,g); drawSquare(8,92,g); drawSquare(5,93,g); drawSquare(3,94,g); drawSquare(9,95,g); PREPLACED[2]=1; PREPLACED[3]=1; PREPLACED[4]=1; PREPLACED[5]=1; PREPLACED[11]=1; PREPLACED[12]=1; PREPLACED[13]=1; PREPLACED[15]=1; PREPLACED[16]=1; PREPLACED[20]=1; PREPLACED[21]=1; PREPLACED[22]=1; PREPLACED[26]=1; PREPLACED[27]=1; PREPLACED[30]=1; PREPLACED[31]=1; PREPLACED[37]=1; PREPLACED[38]=1; PREPLACED[40]=1; PREPLACED[48]=1; PREPLACED[49]=1; PREPLACED[50]=1; PREPLACED[58]=1; PREPLACED[59]=1; PREPLACED[60]=1; PREPLACED[61]=1; PREPLACED[67]=1; PREPLACED[68]=1; PREPLACED[70]=1; PREPLACED[71]=1; PREPLACED[72]=1; PREPLACED[76]=1; PREPLACED[77]=1; PREPLACED[81]=1; PREPLACED[82]=1; PREPLACED[83]=1; PREPLACED[85]=1; PREPLACED[86]=1; PREPLACED[92]=1; PREPLACED[93]=1; PREPLACED[94]=1; PREPLACED[95]=1; } /****************************************/ /* Draw Pattern Four on the QCP board */ /****************************************/ void patternFour(Graphics g) { solveMouse = true; randomValue = 34; phaseTransitionBar(randomValue, g); complexityBar(randomValue, g); g.setColor(Color.black); g.drawRect(104,425,62,62); g.drawRect(103,424,64,64); g.setColor(Color.white); g.drawString("0 %", 662, 490); g.drawString(+(oldRandomValue)+" %", 662, 490); g.drawRect(74,359,62,62); g.drawRect(73,358,64,64); g.drawRect(143,359,62,62); g.drawRect(142,358,64,64); g.drawRect(213,359,62,62); g.drawRect(212,358,64,64); g.drawRect(177,425,62,62); g.drawRect(176,424,64,64); g.setColor(Color.black); g.drawString(+(randomValue)+" %", 662, 490); oldRandomValue = 34; drawSquare(0,0,g); drawSquare(7,1,g); drawSquare(4,2,g); drawSquare(0,11,g); drawSquare(7,12,g); drawSquare(4,13,g); drawSquare(6,19,g); drawSquare(0,22,g); drawSquare(7,23,g); drawSquare(4,24,g); drawSquare(6,28,g); drawSquare(0,33,g); drawSquare(7,34,g); drawSquare(4,35,g); drawSquare(6,37,g); drawSquare(0,44,g); drawSquare(7,45,g); drawSquare(4,46,g); drawSquare(0,55,g); drawSquare(7,56,g); drawSquare(4,57,g); drawSquare(6,64,g); drawSquare(0,66,g); drawSquare(7,67,g); drawSquare(4,68,g); drawSquare(6,73,g); drawSquare(0,77,g); drawSquare(7,78,g); drawSquare(4,79,g); drawSquare(6,82,g); drawSquare(0,88,g); drawSquare(7,89,g); drawSquare(6,91,g); drawSquare(0,99,g); PREPLACED[0]=1; PREPLACED[1]=1; PREPLACED[2]=1; PREPLACED[11]=1; PREPLACED[12]=1; PREPLACED[13]=1; PREPLACED[19]=1; PREPLACED[22]=1; PREPLACED[23]=1; PREPLACED[24]=1; PREPLACED[28]=1; PREPLACED[33]=1; PREPLACED[34]=1; PREPLACED[35]=1; PREPLACED[37]=1; PREPLACED[44]=1; PREPLACED[45]=1; PREPLACED[46]=1; PREPLACED[55]=1; PREPLACED[56]=1; PREPLACED[57]=1; PREPLACED[64]=1; PREPLACED[66]=1; PREPLACED[67]=1; PREPLACED[68]=1; PREPLACED[73]=1; PREPLACED[77]=1; PREPLACED[78]=1; PREPLACED[79]=1; PREPLACED[82]=1; PREPLACED[88]=1; PREPLACED[89]=1; PREPLACED[91]=1; PREPLACED[99]=1; } /****************************************/ /* Draw Pattern Five on the QCP board */ /****************************************/ void patternFive(Graphics g) { solveMouse = true; randomValue = 10; phaseTransitionBar(randomValue, g); complexityBar(randomValue, g); g.setColor(Color.black); g.drawRect(177,425,62,62); g.drawRect(176,424,64,64); g.setColor(Color.white); g.drawString("0 %", 662, 490); g.drawString(+(oldRandomValue)+" %", 662, 490); g.drawRect(74,359,62,62); g.drawRect(73,358,64,64); g.drawRect(143,359,62,62); g.drawRect(142,358,64,64); g.drawRect(213,359,62,62); g.drawRect(212,358,64,64); g.drawRect(104,425,62,62); g.drawRect(103,424,64,64); g.setColor(Color.black); g.drawString(+(randomValue)+" %", 662, 490); oldRandomValue = 10; drawSquare(3,9,g); drawSquare(3,18,g); drawSquare(3,27,g); drawSquare(3,36,g); drawSquare(3,45,g); drawSquare(3,54,g); drawSquare(4,63,g); drawSquare(3,72,g); drawSquare(3,81,g); drawSquare(3,90,g); PREPLACED[9]=1; PREPLACED[18]=1; PREPLACED[27]=1; PREPLACED[36]=1; PREPLACED[45]=1; PREPLACED[54]=1; PREPLACED[63]=1; PREPLACED[72]=1; PREPLACED[81]=1; PREPLACED[90]=1; } /********************************/ /* Override the update method */ /* (not used yet) */ /********************************/ private Image offScreenImage; private Dimension offScreenSize; private Graphics offScreenGraphics; public final synchronized void update (Graphics g) { Dimension d = size(); if((offScreenImage == null) || (d.width != offScreenSize.width) || (d.height != offScreenSize.height)) { offScreenImage = createImage(d.width, d.height); offScreenSize = d; offScreenGraphics = offScreenImage.getGraphics(); } paint(offScreenGraphics); g.drawImage(offScreenImage, 0, 0, null); } }