Skip to content

Commit

Permalink
Human player is now forced to jump. TODO: fix the issue where the com…
Browse files Browse the repository at this point in the history
…puter cannot go after the player jumps until the player clicks on a piece again...
  • Loading branch information
Aaron committed Apr 29, 2016
1 parent c88621f commit 362502e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/controller/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public Game(Board board) {
current_turn = Color.BLACK;
}

public ArrayList<Move> getMoveFrontier(Color color) {
return board.generateAllPossibleMoves(color);
}

public void movePiece(Move move) {
if (move.isJump()) {
board.jump(move);
Expand Down Expand Up @@ -48,11 +52,18 @@ public ArrayList<Move> getAvailableMoves(Location source) {
}
return jumpset;
}
ArrayList<Move> moves = board.generateMoves(board.getPiece(source));
ArrayList<Move> jumps = board.generateJumpMoves(board.getPiece(source));
ArrayList<Move> allMoves = new ArrayList<Move>(moves);
allMoves.addAll(jumps);
return allMoves;

Piece movee = board.getPiece(source);
ArrayList<Move> moves = this.getMoveFrontier(movee.getColor());

ArrayList<Move> moves_of_movee = new ArrayList<Move>();

for (Move move : moves) {
if (move.source.equals(movee.getLocation())) {
moves_of_movee.add(move);
}
}
return moves_of_movee;
}

public void playVsThunk() {
Expand Down Expand Up @@ -80,7 +91,7 @@ public void playVsThunk() {
panel.moveArbitraryPiece(jump);
}
else {
ArrayList<Move> moveset = board.generateAllPossibleMoves(THUNK_COLOR);
ArrayList<Move> moveset = this.getMoveFrontier(THUNK_COLOR);
if (moveset.isEmpty()) {
System.out.println("Thunk is out of moves.");
break;
Expand All @@ -95,8 +106,8 @@ public void playVsThunk() {
}
}
if (this.current_turn == USER_COLOR) {
//ArrayList<Move> moveset = board.generateAllPossibleMoves(USER_COLOR);
//if (moveset.isEmpty()) break;
ArrayList<Move> moveset = this.getMoveFrontier(USER_COLOR);
if (moveset.isEmpty()) break;
}

//board.print();
Expand Down
6 changes: 6 additions & 0 deletions src/model/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ public void jump(Move jump) {

Piece moved = representation[jump.destination.row][jump.destination.column];
this.lastPieceMoved = moved;

this.resetMovesSinceCapture();
}

/**
Expand Down Expand Up @@ -344,6 +346,10 @@ public int getMovesSinceCapture() {
return this.movesSinceCapture;
}

private void resetMovesSinceCapture() {
this.movesSinceCapture = 0;
}

public Piece getLastPieceMoved() {
return this.lastPieceMoved;
}
Expand Down

0 comments on commit 362502e

Please sign in to comment.