I am making a connect 4 game, and I am trying to check for a win, so far I have been able to check right diagonally anywhere on the game board, How do I now check diagonally left, horizontally and vertically, I tried reversing the direction to check on diagonally left but that did not work? What can I change to check towards the left? horizontal and vertical
//Column Size
private static final int COLS = 7;
//Row Size
private static final int ROWS = 6;
//Dynamic Array
private State [][]count = new State[COLS][ROWS];
//Length of Pattern to check FOUR counters in a row
public static final int LEN=4;
//trajectory
public State checkWinner() {
for(int col=0; col<count.length;++col) {
for(int row=0; row<count[col].length; ++row) {
State result = checkWinner(col,row);
if (result!=null) {
return result;
}
}
}
return null;
}
public State checkWinner(int col, int row) {
State cell = count[col][row];
if (cell==null ||cell==State.BLANK) { return null; }
// check Diagonally Right
if((col+LEN<=COLS) && (row+LEN<=ROWS)){
boolean same = true;
for(int i=1;i<LEN;++i) {
if (count[col+i][row+i]!=cell) {
same=false;
break;
}
}
if (same) {
return cell;
}
}
return null;
}