Enhancement + added #8 multipleRounds to the Main

This commit is contained in:
MaurizioBruetsch 2017-10-15 20:56:12 +02:00
parent c5f26606f9
commit 574cb1df34

View file

@ -20,6 +20,51 @@ public class Player2 implements Player{
return choice;
}
public static boolean checkWin(int[][] board, int player){
int winLength = 4;
boolean win = false;
// check columns for win
for(int i=0;i<board.length;i++){
for(int j=0;j<=(board[0].length-winLength);j++){
if(board[i][j] == player){
win = true;
for(int k=1;k<winLength;k++){
if(board[i][j+k] != board[i][j]){
win = false;
break;
}
}
if(win){
return true;
}
}
}
}
// check rows for win
for(int i=0;i<board[0].length;i++){
for(int j=0;j<=(board.length-winLength);j++){
if(board[j][i] == player){
win = true;
for(int k=1;k<winLength;k++){
if(board[i][j+k] != board[i][j]){
win = false;
break;
}
}
if(win){
return true;
}
}
}
}
// check diagonals for win
//TODO
return false;
}
public String getName(){
return this.name;
}