diff --git a/src/controller/Game.java b/src/controller/Game.java index 8e5a462..afb92ea 100755 --- a/src/controller/Game.java +++ b/src/controller/Game.java @@ -21,6 +21,10 @@ public Game(Board board) { current_turn = Color.BLACK; } + public ArrayList getMoveFrontier(Color color) { + return board.generateAllPossibleMoves(color); + } + public void movePiece(Move move) { if (move.isJump()) { board.jump(move); @@ -48,11 +52,18 @@ public ArrayList getAvailableMoves(Location source) { } return jumpset; } - ArrayList moves = board.generateMoves(board.getPiece(source)); - ArrayList jumps = board.generateJumpMoves(board.getPiece(source)); - ArrayList allMoves = new ArrayList(moves); - allMoves.addAll(jumps); - return allMoves; + + Piece movee = board.getPiece(source); + ArrayList moves = this.getMoveFrontier(movee.getColor()); + + ArrayList moves_of_movee = new ArrayList(); + + for (Move move : moves) { + if (move.source.equals(movee.getLocation())) { + moves_of_movee.add(move); + } + } + return moves_of_movee; } public void playVsThunk() { @@ -80,7 +91,7 @@ public void playVsThunk() { panel.moveArbitraryPiece(jump); } else { - ArrayList moveset = board.generateAllPossibleMoves(THUNK_COLOR); + ArrayList moveset = this.getMoveFrontier(THUNK_COLOR); if (moveset.isEmpty()) { System.out.println("Thunk is out of moves."); break; @@ -95,8 +106,8 @@ public void playVsThunk() { } } if (this.current_turn == USER_COLOR) { - //ArrayList moveset = board.generateAllPossibleMoves(USER_COLOR); - //if (moveset.isEmpty()) break; + ArrayList moveset = this.getMoveFrontier(USER_COLOR); + if (moveset.isEmpty()) break; } //board.print(); diff --git a/src/model/Board.java b/src/model/Board.java index fbb5ceb..e8abdc1 100755 --- a/src/model/Board.java +++ b/src/model/Board.java @@ -169,6 +169,8 @@ public void jump(Move jump) { Piece moved = representation[jump.destination.row][jump.destination.column]; this.lastPieceMoved = moved; + + this.resetMovesSinceCapture(); } /** @@ -344,6 +346,10 @@ public int getMovesSinceCapture() { return this.movesSinceCapture; } + private void resetMovesSinceCapture() { + this.movesSinceCapture = 0; + } + public Piece getLastPieceMoved() { return this.lastPieceMoved; }