|
|
|
@ -132,27 +132,79 @@ void ai_choice(char player){ |
|
|
|
|
char check_win(){ |
|
|
|
|
char flag = ' '; |
|
|
|
|
|
|
|
|
|
//no i know there is a better way to check for a win cond.
|
|
|
|
|
//buuttt ill do what i wanna
|
|
|
|
|
//and repeat all the checks twice (player 1 and player 2)!
|
|
|
|
|
|
|
|
|
|
//check vert
|
|
|
|
|
for (int i = 0; i < COLUMNS; ++i) { |
|
|
|
|
for (int j = 0; j < ROWS; ++j) { |
|
|
|
|
if(board[i][j] == PLAYER1 && board[i][j+1] == PLAYER1 && board[i][j+2] == PLAYER1 && board[i][j+3] == PLAYER1){ |
|
|
|
|
flag = PLAYER1; |
|
|
|
|
for(int i = 0; i < COLUMNS; ++i) { |
|
|
|
|
for(int j = 0; j < ROWS; ++j) { |
|
|
|
|
if(board[i][j] == PLAYER1 && board[i][j+1] == PLAYER1 && board[i][j+2] == PLAYER1 && board[i][j+3] == PLAYER1){ |
|
|
|
|
flag = PLAYER1; |
|
|
|
|
} |
|
|
|
|
}
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//check horiz
|
|
|
|
|
for (int i = 0; i < ROWS; ++i) { |
|
|
|
|
for (int j = 0; j < COLUMNS; ++j) { |
|
|
|
|
if(board[i][j] == PLAYER1 && board[i+1][j] == PLAYER1 && board[i+2][j] == PLAYER1 && board[i+3][j] == PLAYER1){ |
|
|
|
|
flag = PLAYER1; |
|
|
|
|
for(int i = 0; i < ROWS; ++i) { |
|
|
|
|
for(int j = 0; j < COLUMNS; ++j) { |
|
|
|
|
if(board[i][j] == PLAYER1 && board[i+1][j] == PLAYER1 && board[i+2][j] == PLAYER1 && board[i+3][j] == PLAYER1){ |
|
|
|
|
flag = PLAYER1; |
|
|
|
|
} |
|
|
|
|
}
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//check diagright
|
|
|
|
|
for(int i = 0; i < ROWS; ++i){ |
|
|
|
|
for(int j = 0; j < COLUMNS; ++j) { |
|
|
|
|
if(board[i][j] == PLAYER1 && board[i-1][j+1] == PLAYER1 && board[i-2][j+2] == PLAYER1 && board[i-3][j+3] == PLAYER1){ |
|
|
|
|
flag = PLAYER1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//check diagleft
|
|
|
|
|
for(int i = 0; i < ROWS; ++i){ |
|
|
|
|
for(int j = 0; j < COLUMNS; ++j) { |
|
|
|
|
if(board[i][j] == PLAYER1 && board[i-1][j-1] == PLAYER1 && board[i-2][j-2] == PLAYER1 && board[i-3][j-3] == PLAYER1){ |
|
|
|
|
flag = PLAYER1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//check vert
|
|
|
|
|
for(int i = 0; i < COLUMNS; ++i) { |
|
|
|
|
for(int j = 0; j < ROWS; ++j) { |
|
|
|
|
if(board[i][j] == PLAYER2 && board[i][j+1] == PLAYER2 && board[i][j+2] == PLAYER2 && board[i][j+3] == PLAYER2){ |
|
|
|
|
flag = PLAYER2; |
|
|
|
|
} |
|
|
|
|
}
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//check horiz
|
|
|
|
|
for(int i = 0; i < ROWS; ++i) { |
|
|
|
|
for(int j = 0; j < COLUMNS; ++j) { |
|
|
|
|
if(board[i][j] == PLAYER2 && board[i+1][j] == PLAYER2 && board[i+2][j] == PLAYER2 && board[i+3][j] == PLAYER2){ |
|
|
|
|
flag = PLAYER2; |
|
|
|
|
} |
|
|
|
|
}
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//check diagright
|
|
|
|
|
for(int i = 0; i < ROWS; ++i){ |
|
|
|
|
for(int j = 0; j < COLUMNS; ++j) { |
|
|
|
|
if(board[i][j] == PLAYER2 && board[i-1][j+1] == PLAYER2 && board[i-2][j+2] == PLAYER2 && board[i-3][j+3] == PLAYER2){ |
|
|
|
|
flag = PLAYER2; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//check diagleft
|
|
|
|
|
for(int i = 0; i < ROWS; ++i){ |
|
|
|
|
for(int j = 0; j < COLUMNS; ++j) { |
|
|
|
|
if(board[i][j] == PLAYER2 && board[i-1][j-1] == PLAYER2 && board[i-2][j-2] == PLAYER2 && board[i-3][j-3] == PLAYER2){ |
|
|
|
|
flag = PLAYER2; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return flag;
|
|
|
|
|
|
|
|
|
|