mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-25 12:25:10 -08:00
Implemented GameFinished
does it work? Unsure...
This commit is contained in:
@@ -93,7 +93,26 @@ public class HighIQ {
|
||||
|
||||
|
||||
public boolean isGameFinished() {
|
||||
return false;
|
||||
for(Integer key : board.getKeySet()) {
|
||||
if(board.get(key)) {
|
||||
//Spacing is either 1 or 9
|
||||
for(int space = 1; space <= 9; space += 8) {
|
||||
//Next val is the next spot, prev and next after are the two spots where the peg would go if a move was possible
|
||||
Boolean nextVal = board.get(key + space);
|
||||
Boolean prevAfter = board.get(key - space);
|
||||
Boolean nextAfter = board.get(key + space * 2);
|
||||
|
||||
if(nextVal != null && nextVal) {
|
||||
if((prevAfter != null && !prevAfter) || (nextAfter != null && !nextAfter)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void printBoard() {
|
||||
|
||||
Reference in New Issue
Block a user