|
|
@ -132,9 +132,13 @@ void ai_choice(char player){ |
|
|
|
char check_win(){ |
|
|
|
char check_win(){ |
|
|
|
char flag = ' '; |
|
|
|
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
|
|
|
|
//check vert
|
|
|
|
for (int i = 0; i < COLUMNS; ++i) { |
|
|
|
for(int i = 0; i < COLUMNS; ++i) { |
|
|
|
for (int j = 0; j < ROWS; ++j) { |
|
|
|
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){ |
|
|
|
if(board[i][j] == PLAYER1 && board[i][j+1] == PLAYER1 && board[i][j+2] == PLAYER1 && board[i][j+3] == PLAYER1){ |
|
|
|
flag = PLAYER1; |
|
|
|
flag = PLAYER1; |
|
|
|
} |
|
|
|
} |
|
|
@ -142,8 +146,8 @@ char check_win(){ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//check horiz
|
|
|
|
//check horiz
|
|
|
|
for (int i = 0; i < ROWS; ++i) { |
|
|
|
for(int i = 0; i < ROWS; ++i) { |
|
|
|
for (int j = 0; j < COLUMNS; ++j) { |
|
|
|
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){ |
|
|
|
if(board[i][j] == PLAYER1 && board[i+1][j] == PLAYER1 && board[i+2][j] == PLAYER1 && board[i+3][j] == PLAYER1){ |
|
|
|
flag = PLAYER1; |
|
|
|
flag = PLAYER1; |
|
|
|
} |
|
|
|
} |
|
|
@ -151,8 +155,56 @@ char check_win(){ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//check diagright
|
|
|
|
//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
|
|
|
|
//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;
|
|
|
|
return flag;
|
|
|
|
|
|
|
|
|
|
|
|