I am making a game four in a row, where the number of rows and colomns is determined by the player(so can be anything, as long as more than four). So users input is stored in the variables "rows" and "column". The field looks smth like this, so the first row is always numbers.
I have trouble with the search algorithm for the winner. While my algorithm for the horizontal search works fine, the vertical one with the same logic gives me the out of bound error.If you could please help me to spot the mistake, I would be very grateful. Thank you! 1 2 3 4 5 |-|-|-|-| |-|-|-|-| |-|-|-|-|
public static String checkWinner(String [][]field){
//horizontally, which works
for(int i=1; i<=rows; i++){
for (int j=0; j<=column-1;j++){
if (((j>=3 || j==column-1) && field[i][j]!="|_" && field[i][j]==field[i][j-1] && field[i][j]==field[i][j-2] && field[i][j]==field[i][j-3])
|| (field[i][j]!="|_" && field[i][j]==field[i][j+1] && field[i][j]==field[i][j+2] && field[i][j]==field[i][j+3]))
{
return field[i][j];
}
}
}
//vertically which doesn't work
for(int i=0; i<column; i++){
for (int j=1; j<=rows-1;j++){
if (((j>=4 || j==rows-1) && field[j][i]!="|_" && field[j][i]==field[j-1][i] && field[j][i]==field[j-2][i] && field[j][i]==field[j-3][i])
|| (field[j][i]!="|_" && field[j][i]==field[j+1][i] && field[j][i]==field[j+2][i] && field[j][i]==field[j+3][i]))
{
return field[i][j];
}
}
}
return null;
}