Changed makeMove such that illegal moves will be punished
Signed-off-by: Malte Tammena <malte.tammena@gmx.de>
This commit is contained in:
parent
47903da1a7
commit
0dda4b6d0c
|
@ -93,24 +93,13 @@ public class Game {
|
|||
* Calls a players functions to make a move.
|
||||
*/
|
||||
private void makeMove(Player p, boolean turn) {
|
||||
boolean invalid = true;
|
||||
// So the compiler doesn't complain, that choice hasn't been initialized,
|
||||
// but the loop will always be entered.
|
||||
int choice = 0;
|
||||
while (invalid) {
|
||||
log(p.getName() + " makes a move!");
|
||||
choice = p.move(copyBoard());// TODO does the player only get a copy of the board now??
|
||||
log(p.getName() + " makes a move!");
|
||||
int choice = p.move(copyBoard());
|
||||
|
||||
// TODO check wether there is a winner after every move instead of this
|
||||
if(choice == -1){
|
||||
this.gameOn = false;
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println(choice);
|
||||
if (this.board[choice][0] == 0) {
|
||||
invalid = false;
|
||||
}
|
||||
if (choice < 0 || choice > GAME_COLUMNS || this.board[choice][0] != 0) {
|
||||
this.gameOn = false;
|
||||
log(p.getName() + " made an illegal move and lost!");
|
||||
return;
|
||||
}
|
||||
|
||||
int pos = 0;
|
||||
|
@ -132,8 +121,8 @@ public class Game {
|
|||
*/
|
||||
private int[][] copyBoard() {
|
||||
int[][] ret = new int[GAME_COLUMNS][GAME_ROWS];
|
||||
for (int i = 0; i < this.board; i++) {
|
||||
for (int j = 0; j < this.board[i]; j++) {
|
||||
for (int i = 0; i < this.board.length; i++) {
|
||||
for (int j = 0; j < this.board[i].length; j++) {
|
||||
ret[i][j] = this.board[i][j];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue