Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean findValidMoves(playerColor turn)
- {
- for(int i = 0; i < 8; i++)
- {
- for(int j = 0; j < 8; j++)
- {
- int[] dir = {0, 0, 0, 0};
- int xDiffPos = 0;
- int xDiffNeg = 0;
- int yDiffPos = 0;
- int yDiffNeg = 0;
- if(i == 0)
- {
- //y diff pos
- dir[2] = 1;
- }
- else if(i == 7)
- {
- //y diff neg
- dir[3] = -1;
- }
- else
- {
- //y diff pos
- dir[2] = 1;
- //y diff neg
- dir[3] = -1;
- }
- if(j == 0)
- {
- //x diff pos
- dir[0] = 1;
- }
- else if(j == 7)
- {
- //x diff neg
- dir[1] = -1;
- }
- else
- {
- //x diff pos
- dir[0] = 1;
- //x diff neg
- dir[1] = -1;
- }
- //generatePossibilities(j, i, xDiffPos, xDiffNeg, yDiffPos, yDiffNeg, turn);
- if(turn == playerColor.BLACK)
- {
- blackMoves[j][i] = checkLoc(j, i, dir, turn, board);
- //System.out.println(blackMoves[j][i].takenPieces.size());
- }
- else
- {
- whiteMoves[j][i] = checkLoc(j, i, dir, turn, board);
- }
- }
- }
- //testPrintPotential(blackMoves);
- return false;
- }
- private potentialMove checkLoc(int xPos, int yPos, int[] dir, playerColor turnTemp, boardSpace[][] tempBoard)
- {
- //System.out.print("(" + xPos + ", " + yPos + ")");
- int iterations = 0;
- potentialMove p = new potentialMove();
- p.location.x = xPos;
- p.location.y = yPos;
- p.valid = false;
- p = initTakenPieces(p);
- boardSpace opposing;
- boardSpace playing;
- if (turnTemp == playerColor.BLACK)
- {
- opposing = boardSpace.WHITE;
- playing = boardSpace.BLACK;
- }
- else
- {
- opposing = boardSpace.BLACK;
- playing = boardSpace.WHITE;
- }
- for(int i = 0; i < dir.length; i++)
- {
- if (dir[i] != 0) iterations++;
- }
- if(iterations == 0)
- {
- p.valid = false;
- return p;
- }
- int yDir = 0;
- int xDir = 0;
- boardSpace currSpace = boardSpace.EMPTY;
- int count = 0;
- for(int i = (yPos + dir[3]); i < (yPos + dir[2] + 1); i++) {
- if(i == yPos - 1)
- {
- yDir = -1;
- }
- else if(i == yPos + 1)
- {
- yDir = 1;
- }
- else
- {
- yDir = 0;
- }
- for (int j = (xPos + dir[1]); j < (xPos + dir[0] + 1); j++) {
- if ((j != xPos) || (i != yPos)) {
- //System.out.print( " " + j + ", " + i + " || ");
- if(j == xPos - 1)
- {
- xDir = -1;
- }
- else if(j == xPos + 1)
- {
- xDir = 1;
- }
- else
- {
- xDir = 0;
- }
- //System.out.print("Directions: " + xDir + " " + yDir + " | ");
- int tempXpos = j;
- int tempYpos = i;
- boolean valid = false;
- currSpace = tempBoard[tempXpos][tempYpos];
- //Point tempPoint = new Point();
- //tempPoint.x = -1;
- //tempPoint.y = -1;
- //p.takenPieces[count].add(tempPoint);
- while(currSpace == opposing)
- {
- if(currSpace == opposing && tempBoard[tempXpos + xDir][tempYpos + yDir] == playing)
- {
- valid = true;
- //System.out.print(" hi");
- }
- else
- {
- valid = false;
- }
- Point temp = new Point();
- temp.x = tempXpos;
- temp.y = tempYpos;
- p.takenPieces[count].add(temp);
- tempXpos += xDir;
- tempYpos += yDir;
- currSpace = tempBoard[tempXpos][tempYpos];
- }
- if(!valid)
- {
- if(p.takenPieces[count].size() > 0 && p.takenPieces[count].get(0).x >= 0 && p.takenPieces[count].get(0).y >=0)
- {
- p.takenPieces[count].clear();
- }
- }
- else
- {
- p.valid = true;
- //System.out.print("Valid Move");
- //System.out.print(" " + p.takenPieces.size() + " pieces taken");
- //for(int k = 0; k < p.takenPieces.size(); k++)
- //{
- // System.out.print(p.takenPieces.get(k));
- // }
- }
- count++;
- }
- //if(count >= 8) count--;
- }
- }
- //System.out.println();
- //System.out.println();
- return p;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement