Enhancement + added #8 multipleRounds to the Main
This commit is contained in:
parent
c5f26606f9
commit
574cb1df34
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue