Skip to content

Instantly share code, notes, and snippets.

@vritant24
Created March 25, 2017 00:55
Show Gist options
  • Select an option

  • Save vritant24/b93b098c7f2cd1fe52df6da232fb89d4 to your computer and use it in GitHub Desktop.

Select an option

Save vritant24/b93b098c7f2cd1fe52df6da232fb89d4 to your computer and use it in GitHub Desktop.
public static String Mirror(){
int i = myCurrentRow;
int j = myCurrentColumn;
Point opp = getOppMove();
if(opp.x - oppLastMove.x == 1) {
//Move Up
if(isInsideBoard(i+1, j)) {
if(gameBoard[i+1][j] != 1 && gameBoard[i+1][j] != -1 && gameBoard[i+1][j] != 2 && gameBoard[i+1][j] != -2) {
return "UP";
}
}
}
if(opp.x - oppLastMove.x == -1) {
//Move Down;
if(isInsideBoard(i-1, j)) {
if(gameBoard[i-1][j] != 1 && gameBoard[i-1][j] != -1 && gameBoard[i-1][j] != 2 && gameBoard[i-1][j] != -2) {
return "DOWN";
}
}
}
if(opp.y - oppLastMove.y == 1) {
//move left;
if(isInsideBoard(i, j-1)) {
if(gameBoard[i][j-1] != 1 && gameBoard[i][j-1] != -1 && gameBoard[i][j-1] != 2 && gameBoard[i][j-1] != -2) {
return "DOWN";
}
}
}
if(opp.y - oppLastMove.y == -1) {
//move right
if(isInsideBoard(i, j+1)) {
if(gameBoard[i][j+1] != 1 && gameBoard[i][j+1] != -1 && gameBoard[i][j+1] != 2 && gameBoard[i][j+1] != -2) {
return "DOWN";
}
}
}
return randomMove();
}
public static Point getOppMove() {
int oppPlayer = 1;
if(myPlayerNumber == 1) {
oppPlayer = 2;
}
for(int i = 0; i < gameBoard.length; i++) {
for(int j = 0; j < gameBoard[].length; j++) {
if(gameBoard[i][j] == oppPlayer) {
Point opp = new Point(i,j);
return opp;
}
}
}
if(myPlayerNumber == 1) {
return new Point(myCurrentRow, myCurrentColumn + 1);
} else {
return new Point(myCurrentRow, myCurrentColumn - 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment