Created
March 25, 2017 00:55
-
-
Save vritant24/b93b098c7f2cd1fe52df6da232fb89d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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