SO IM LIKE MAKING AN OTHELLO GAME AND I NEED TO CHECK WHY MY DIAGONAL FLANK (TOP LEFT) IS NOT WORKING
/**
* Othello.java
*
* This class represents a Othello (TM)
* game, which allows two players to place
* pieces onto a board. Each move can
* result in outflanking 0 or more opponent's
* piece.
*/
public class Othello
{
/* constants */
final int MAXGAME; // the number of games a player needs to win to win the match
final int NUMPLAYER; // number of players in the game
final int NUMROW; // number of rows in the game board
final int NUMCOL; // number of columns in the game board
final int EMPTY = -1; // represents an empty square on the game board
final int PLAYER1 = 0; // identification of player 1
final int PLAYER2 = 1; // identification of player 2
OthelloGUI gui;
int numMove;
int curPlayer;
int board[][];
int score[];
/**
* Constructor: Othello
*/
public Othello(OthelloGUI gui)
{
this.gui = gui;
NUMPLAYER = gui.NUMPLAYER;
NUMROW = gui.NUMROW;
NUMCOL = gui.NUMCOL;
MAXGAME = gui.MAXGAME;
board = new int [NUMROW][NUMCOL];
curPlayer = PLAYER1;
for (int i = 0; i < NUMROW; i++)
{
for (int j = 0; j < NUMCOL; j++)
{
board [i][j] = EMPTY;
}
}
initBoard ();
// TO DO: creation of arrays, and initialization of variables should be added here
}
/**
* play
* This method will be called when a square is clicked. Parameter "row" and "column" is
* the location of the square that is clicked by the user
*/
public void play (int row, int column)
{
if (validMove(row,column) == true)
{
gui.setPiece (row,column,curPlayer);
board [row][column] = curPlayer;
outFlankHori (row,column);
outFlankVert (row,column);
gui.showOutflankMessage(curPlayer,outFlankDiag (row,column));
if (curPlayer == PLAYER1)
{
curPlayer = PLAYER2;
}
else
{
curPlayer = PLAYER1;
}
gui.setNextPlayer(curPlayer);
}
} // TO DO: implement the logic of the game
private void initBoard ()
{
gui.setPiece (3,3,PLAYER1);
board [3][3] = PLAYER1;
gui.setPiece (4,4,PLAYER1);
board [4][4] = PLAYER1;
gui.setPiece (3,4,PLAYER2);
board [3][4] = PLAYER2;
gui.setPiece (4,3,PLAYER2);
board [4][3] = PLAYER2;
}
public boolean validMove (int row, int column)
{
boolean valid = false;
if (board [row][column] == EMPTY)
{
for (int i = row - 1; i <= row + 1; i++)
{
for (int j = column - 1; j <= column + 1; j++)
{
if ( i >= 0 && i < NUMROW && j >= 0 && j < NUMCOL)
{
if (board [i][j] != EMPTY)
{
valid = true;
}
}
}
}
}
return valid;
}
private int outFlankHori (int row, int column)
{
int flipped = 0;
int flippedLeft = 0;
int flippedRight = 0;
boolean checkLeft = false;
boolean checkRight = false;
if (column != 0)
{
if (board [row][column - 1] != EMPTY && board [row][column - 1] != curPlayer)
{
for (int i = 1; column - i >= 0 && board [row][column - i] != EMPTY; i++)
{
if (board [row][column - i] == curPlayer && checkLeft == false)
{
checkLeft = true;
flippedLeft = i;
}
}
}
}
if (column != 7)
{
if (board [row][column + 1] != EMPTY && board [row][column + 1] != curPlayer)
{
for (int i = 1; column + i <= 7 && board [row][column + i] != EMPTY; i++)
{
if (board [row][column + i] == curPlayer && checkRight == false)
{
checkRight = true;
flippedRight = i;
}
}
}
}
if (checkLeft == true)
{
for (int i = 1; i <= flippedLeft; i++)
{
gui.setPiece (row,column - i,curPlayer);
board [row][column - i] = curPlayer;
}
}
if (checkRight == true)
{
for (int i = 1; i <= flippedRight; i++)
{
gui.setPiece (row,column + i,curPlayer);
board [row][column + i] = curPlayer;
}
}
flipped = flippedLeft + flippedRight;
return flipped;
}
private int outFlankVert (int row, int column)
{
int flipped = 0;
int flippedUp = 0;
int flippedDown = 0;
boolean checkUp = false;
boolean checkDown = false;
if (row != 0)
{
if (board [row - 1][column] != EMPTY && board [row - 1][column] != curPlayer)
{
for (int i = 1; row - i >= 0 && board [row - i][column] != EMPTY; i++)
{
if (board [row - i][column] == curPlayer && checkUp == false)
{
checkUp = true;
flippedUp = i;
}
}
}
}
if (row != 7)
{
if (board [row + 1][column] != EMPTY && board [row + 1][column] != curPlayer)
{
for (int i = 1; row + i <= 7 && board [row + i][column] != EMPTY; i++)
{
if (board [row + i][column] == curPlayer && checkDown == false)
{
checkDown = true;
flippedDown = i;
}
}
}
}
if (checkUp == true)
{
for (int i = 1; i <= flippedUp; i++)
{
gui.setPiece (row - i,column,curPlayer);
board [row - i][column] = curPlayer;
}
}
if (checkDown == true)
{
for (int i = 1; i <= flippedDown; i++)
{
gui.setPiece (row + i,column,curPlayer);
board [row + i][column] = curPlayer;
}
}
flipped = flippedUp + flippedDown;
return flipped;
}
private int outFlankDiag (int row, int column) right here
{
int flipped = 0;
int flippedUpLeft = 0;
int flippedUpRight = 0;
int flippedDownLeft = 0;
int flippedDownRight = 0;
boolean checkUpLeft = false;
boolean checkUpRight = false;
boolean checkDownLeft = false;
boolean checkDownRight = false;
if (row != 0 && column != 7)
{
if (board [row - 1][column + 1] != EMPTY && board [row - 1][column + 1] != curPlayer)
{
for (int i = 1; row - i >= 0 && column + i <= 7 && board [row - i][column + i] != EMPTY; i++)
{
if (board [row - i][column + i] == curPlayer && checkUpRight == false)
{
checkUpRight = true;
flippedUpRight = i;
}
}
}
}
if (row != 7 && column !=0)
{
if (board [row + 1][column - 1] != EMPTY && board [row + 1][column - 1] != curPlayer)
{
for (int i = 1; row + i <= 7 && column - i >= 0 && board [row + i][column - i] != EMPTY; i++)
{
if (board [row + i][column - i] == curPlayer && checkDownLeft == false)
{
checkDownLeft = true;
flippedDownLeft = i;
}
}
}
}
if (row != 0 && column != 0) this one
{
if (board [row - 1][column - 1] != EMPTY && board [row - 1][column - 1] != curPlayer)
{
for (int i = 1; row - i >= 0 && column - i >= 0 && board [row - i][column - i] != EMPTY; i++)
{
if (board [row - i][column - 1] == curPlayer && checkUpLeft == false)
{
checkUpLeft = true;
flippedUpLeft = i;
}
}
}
}
if (row != 7 && column != 7)
{
if (board [row + 1][column + 1] != EMPTY && board [row + 1][column + 1] != curPlayer)
{
for (int i = 1; row + i <= 7 && column + i <= 7 && board [row + i][column + i] != EMPTY; i++)
{
if (board [row + i][column + i] == curPlayer && checkDownRight == false)
{
checkDownRight = true;
flippedDownRight = i;
}
}
}
}
for (int i = 1; i < flippedUpLeft; i++)
{
gui.setPiece (row - i,column - i,curPlayer);
board [row - i][column - i] = curPlayer;
}
if (checkUpRight == true)
{
for (int i = 1; i < flippedUpRight; i++)
{
gui.setPiece (row - i,column + i,curPlayer);
board [row - i][column + i] = curPlayer;
}
}
if (checkDownLeft == true)
{
for (int i = 1; i < flippedDownLeft; i++)
{
gui.setPiece (row + i,column - i,curPlayer);
board [row + i][column - i] = curPlayer;
}
}
if (checkDownRight == true)
{
for (int i = 1; i < flippedDownRight; i++)
{
gui.setPiece (row + i,column + i,curPlayer);
board [row + i][column + i] = curPlayer;
}
}
flipped = flippedUpLeft + flippedUpRight + flippedDownLeft + flippedDownRight;
return flipped;
}
}
PLEASE SEND HELP EVERY OTHER CODE FOR FLANK WORKS