Merge branch '12-bug-fix' into 'master'
fixed bug 12 and improved output of Human.java Closes #12 See merge request !27
This commit is contained in:
commit
68ea8df7fe
|
@ -133,7 +133,7 @@ public class Game {
|
|||
// Start the game
|
||||
this.gameOn = true;
|
||||
while(gameOn) {
|
||||
makeMove(output);
|
||||
if(makeMove(output)){
|
||||
currentP = other(currentP);
|
||||
if(output){
|
||||
logGame(hist.getLast());
|
||||
|
@ -149,11 +149,18 @@ public class Game {
|
|||
AnsiConsole.systemUninstall();
|
||||
return state; // the result of the game
|
||||
}
|
||||
} else{
|
||||
// an illegal move was made
|
||||
if(output){
|
||||
System.out.println(other(currentP).getP().getName() + " wins.");
|
||||
}
|
||||
return other(currentP).getID(); // TODO this only works if the players hav IDs 1 and 2
|
||||
}
|
||||
}
|
||||
// Uninstall Jansi
|
||||
AnsiConsole.systemUninstall();
|
||||
System.out.println("BUG!");
|
||||
return checkState(false); // it is impossible to reach this, but it makes the compiler happy ;)
|
||||
return checkState(false); // this is impossible to reach this, but it makes the compiler happy ;)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -173,19 +180,17 @@ public class Game {
|
|||
/**
|
||||
* Calls a players functions to make a move.
|
||||
*/
|
||||
private void makeMove(boolean output) {
|
||||
private boolean makeMove(boolean output) {
|
||||
// Get a choice from the player, while only giving him a copy of the game.
|
||||
int choice = currentP.getP().move(copyBoard());
|
||||
// Check his choice against the current board.
|
||||
if (choice < 0 || choice > GAME_COLUMNS || this.board[choice][0] != 0) {
|
||||
// If a player makes a false move, the game punishes him.
|
||||
// TODO: Fix this, causes -1 return of checkstate in Simulation mode, breaks the game.
|
||||
// this.gameOn = false;
|
||||
//TODO the game gets stopped, but checkState doesn't know what that means!?
|
||||
this.gameOn = false;
|
||||
if(output){
|
||||
log(currentP.getP().getName() + " made an illegal move and lost!");
|
||||
}
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
// Find the lowest empty field in the board in the choosen column.
|
||||
int pos = 0;
|
||||
|
@ -198,6 +203,7 @@ public class Game {
|
|||
if(output){
|
||||
log(currentP.getP().getName() + " made a move!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,10 +27,16 @@ public class Human implements Player {
|
|||
}
|
||||
}
|
||||
int choice = -1;
|
||||
// make sure that the user chooses a legal move
|
||||
while (!options.contains(new Integer(choice))) {
|
||||
System.out.print("Choose a move from " + options + ": ");
|
||||
System.out.flush();
|
||||
choice = sc.nextInt();
|
||||
if(!options.contains(new Integer(choice))){
|
||||
System.out.println("This is not a legal move!");
|
||||
}
|
||||
}
|
||||
System.out.println(choice);
|
||||
return choice;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue