diff --git a/src/ai/Ai.java b/src/ai/Ai.java index a9ee3d3..0c923d9 100644 --- a/src/ai/Ai.java +++ b/src/ai/Ai.java @@ -65,8 +65,7 @@ public MoveCommand generateMove() { // you can't swap pushPiecePlace = this.generateRandomDirection(randomDirection); } - MoveCommand pushMove = new PushMove(this.game.getBoardState(), pieceCoor, randomDirection, pushPiecePlace, - this.owner, this.game.getNumMoves()); + MoveCommand pushMove = new PushMove(this.game, pieceCoor, randomDirection, pushPiecePlace, this.owner); if (pushMove.isValidMove()) { return pushMove; } @@ -84,8 +83,7 @@ public MoveCommand generateMove() { // you can't swap pullPiecePlace = this.generateRandomDirection(randomDirection); } - MoveCommand pullMove = new PullMove(this.game.getBoardState(), pieceCoor, randomDirection, pullPiecePlace, - this.owner, this.game.getNumMoves()); + MoveCommand pullMove = new PullMove(this.game, pieceCoor, randomDirection, pullPiecePlace, this.owner); if (pullMove.isValidMove()) { return pullMove; } @@ -93,8 +91,7 @@ public MoveCommand generateMove() { return this.generateMove(); } // use regular method - MoveCommand regularMove = new RegularMove(this.game.getBoardState(), pieceCoor, randomDirection, this.owner, - this.game.getNumMoves()); + MoveCommand regularMove = new RegularMove(this.game, pieceCoor, randomDirection, this.owner); if (regularMove.isValidMove()) { return regularMove; } diff --git a/src/listeners/MovementListener.java b/src/listeners/MovementListener.java index 922e902..f7f56d5 100644 --- a/src/listeners/MovementListener.java +++ b/src/listeners/MovementListener.java @@ -55,7 +55,7 @@ public void mousePressed(MouseEvent e) { if (game.isAiTurn()) { return; } - + Coordinate coor = new Coordinate((sourceX - 10) / 80, (sourceY - 10) / 80); // Beginning movement, nothing yet selected // Selecting piece to interact with @@ -70,8 +70,7 @@ public void mousePressed(MouseEvent e) { // AKA move else if (isSelectedPieceAndEmptySpaceClicked(coor)) { // Using move to check for valid move - RegularMove m = new RegularMove(game.getBoardState(), this.selectedPieceCoord, coor, - this.game.getPlayerTurn(), game.getNumMoves()); + RegularMove m = new RegularMove(game, this.selectedPieceCoord, coor, this.game.getPlayerTurn()); if (game.move(m)) { gui.rerenderBoard(); } @@ -92,11 +91,11 @@ else if (pieceSelectedAndSecondPieceClicked(coor)) { } else if (twoPieceSelectedAndEmptySpaceClicked(coor)) { MoveCommand move = null; if (this.secondSelectedPieceCoord.isOrthogonallyAdjacentTo(coor)) { - move = new PushMove(game.getBoardState(), this.selectedPieceCoord, this.secondSelectedPieceCoord, - coor, game.getPlayerTurn(), game.getNumMoves()); + move = new PushMove(game, this.selectedPieceCoord, this.secondSelectedPieceCoord, coor, + game.getPlayerTurn()); } else { - move = new PullMove(game.getBoardState(), this.selectedPieceCoord, coor, - this.secondSelectedPieceCoord, game.getPlayerTurn(), game.getNumMoves()); + move = new PullMove(game, this.selectedPieceCoord, coor, this.secondSelectedPieceCoord, + game.getPlayerTurn()); } if (game.move(move)) { gui.rerenderBoard(); diff --git a/src/move_commands/MoveCommand.java b/src/move_commands/MoveCommand.java index 6527540..b121f1e 100644 --- a/src/move_commands/MoveCommand.java +++ b/src/move_commands/MoveCommand.java @@ -5,6 +5,7 @@ import board.BoardState; import board.Coordinate; +import game.Game; import piece.Owner; public abstract class MoveCommand implements Serializable { @@ -18,16 +19,15 @@ public abstract class MoveCommand implements Serializable { protected Owner turn; protected int movesLeft; - protected MoveCommand(BoardState board, Coordinate originalPosition, Coordinate newPosition, Owner turn, - int movesLeft) { - this.originalBoard = new BoardState(board); - this.newBoard = board; + protected MoveCommand(Game game, Coordinate originalPosition, Coordinate newPosition, Owner turn) { + this.originalBoard = new BoardState(game.getBoardState()); + this.newBoard = game.getBoardState(); this.originalPosition = originalPosition; this.newPosition = newPosition; this.turn = turn; - this.movesLeft = movesLeft; + this.movesLeft = game.getNumMoves(); } abstract public BoardState execute(); diff --git a/src/move_commands/PullMove.java b/src/move_commands/PullMove.java index 4f0e399..8382b21 100644 --- a/src/move_commands/PullMove.java +++ b/src/move_commands/PullMove.java @@ -4,6 +4,7 @@ import board.BoardState; import board.Coordinate; +import game.Game; import piece.AbstractPiece; import piece.Owner; @@ -15,9 +16,9 @@ public class PullMove extends MoveCommand { public static final int NUMBER_OF_MOVES = 2; private Coordinate pullPiecePosition; - public PullMove(BoardState board, Coordinate originalPosition, Coordinate newPosition, Coordinate pullPiecePosition, - Owner turn, int movesLeft) { - super(board, originalPosition, newPosition, turn, movesLeft); + public PullMove(Game game, Coordinate originalPosition, Coordinate newPosition, Coordinate pullPiecePosition, + Owner turn) { + super(game, originalPosition, newPosition, turn); this.pullPiecePosition = pullPiecePosition; } diff --git a/src/move_commands/PushMove.java b/src/move_commands/PushMove.java index 55e2697..0a564d1 100644 --- a/src/move_commands/PushMove.java +++ b/src/move_commands/PushMove.java @@ -4,6 +4,7 @@ import board.BoardState; import board.Coordinate; +import game.Game; import piece.AbstractPiece; import piece.Owner; @@ -15,9 +16,9 @@ public class PushMove extends MoveCommand { public static final int NUMBER_OF_MOVES = 2; private Coordinate pushPiecePosition; - public PushMove(BoardState board, Coordinate originalPosition, Coordinate newPosition, Coordinate pushPiecePosition, - Owner turn, int movesLeft) { - super(board, originalPosition, newPosition, turn, movesLeft); + public PushMove(Game game, Coordinate originalPosition, Coordinate newPosition, Coordinate pushPiecePosition, + Owner turn) { + super(game, originalPosition, newPosition, turn); this.pushPiecePosition = pushPiecePosition; } diff --git a/src/move_commands/RegularMove.java b/src/move_commands/RegularMove.java index 6426469..2161e7b 100644 --- a/src/move_commands/RegularMove.java +++ b/src/move_commands/RegularMove.java @@ -2,6 +2,7 @@ import board.BoardState; import board.Coordinate; +import game.Game; import piece.AbstractPiece; import piece.Owner; import piece.Rabbit; @@ -10,9 +11,8 @@ public class RegularMove extends MoveCommand { private static final long serialVersionUID = 4434841689278271636L; public static final int NUMBER_OF_MOVES = 1; - public RegularMove(BoardState board, Coordinate originalPosition, Coordinate newPosition, Owner turn, - int movesLeft) { - super(board, originalPosition, newPosition, turn, movesLeft); + public RegularMove(Game game, Coordinate originalPosition, Coordinate newPosition, Owner turn) { + super(game, originalPosition, newPosition, turn); } @Override diff --git a/test/ai/TestGenerateRandomMoveOnlyIfEnoughMoves.java b/test/ai/TestGenerateRandomMoveOnlyIfEnoughMoves.java index 0e90a55..e22b4cc 100644 --- a/test/ai/TestGenerateRandomMoveOnlyIfEnoughMoves.java +++ b/test/ai/TestGenerateRandomMoveOnlyIfEnoughMoves.java @@ -32,38 +32,29 @@ private void testOnlyRegularMoves(Ai ai) { @Test public void testNormalNoPushOrPullIf1MoveLeft() { Game game = this.normalAi.getGame(); - game.move(new RegularMove(game.getBoardState(), new Coordinate(1, 1), new Coordinate(1, 2), game.getPlayerTurn(), - game.getNumMoves())); - game.move(new RegularMove(game.getBoardState(), new Coordinate(1, 2), new Coordinate(1, 1), game.getPlayerTurn(), - game.getNumMoves())); - game.move(new RegularMove(game.getBoardState(), new Coordinate(1, 1), new Coordinate(1, 2), game.getPlayerTurn(), - game.getNumMoves())); + game.move(new RegularMove(game, new Coordinate(1, 1), new Coordinate(1, 2), game.getPlayerTurn())); + game.move(new RegularMove(game, new Coordinate(1, 2), new Coordinate(1, 1), game.getPlayerTurn())); + game.move(new RegularMove(game, new Coordinate(1, 1), new Coordinate(1, 2), game.getPlayerTurn())); testOnlyRegularMoves(this.normalAi); } @Test public void testKatLoverNoPushOrPullIf1MoveLeft() { Game game = this.catLoverAi.getGame(); - game.move(new RegularMove(game.getBoardState(), new Coordinate(0, 1), new Coordinate(0, 0), game.getPlayerTurn(), - game.getNumMoves())); - game.move(new RegularMove(game.getBoardState(), new Coordinate(0, 0), new Coordinate(0, 1), game.getPlayerTurn(), - game.getNumMoves())); - game.move(new RegularMove(game.getBoardState(), new Coordinate(0, 1), new Coordinate(0, 0), game.getPlayerTurn(), - game.getNumMoves())); + game.move(new RegularMove(game, new Coordinate(0, 1), new Coordinate(0, 0), game.getPlayerTurn())); + game.move(new RegularMove(game, new Coordinate(0, 0), new Coordinate(0, 1), game.getPlayerTurn())); + game.move(new RegularMove(game, new Coordinate(0, 1), new Coordinate(0, 0), game.getPlayerTurn())); testOnlyRegularMoves(this.catLoverAi); } @Test public void testNotManyMovesNoPushOrPullIf1MoveLeft() { Game game = this.notManyMovesAi.getGame(); - game.move(new RegularMove(game.getBoardState(), new Coordinate(1, 1), new Coordinate(1, 2), game.getPlayerTurn(), - game.getNumMoves())); + game.move(new RegularMove(game, new Coordinate(1, 1), new Coordinate(1, 2), game.getPlayerTurn())); game.getBoardState().movePiece(new Coordinate(1, 2), new Coordinate(1, 1)); - game.move(new RegularMove(game.getBoardState(), new Coordinate(1, 1), new Coordinate(1, 2), game.getPlayerTurn(), - game.getNumMoves())); + game.move(new RegularMove(game, new Coordinate(1, 1), new Coordinate(1, 2), game.getPlayerTurn())); game.getBoardState().movePiece(new Coordinate(1, 2), new Coordinate(1, 1)); - game.move(new RegularMove(game.getBoardState(), new Coordinate(1, 1), new Coordinate(1, 2), game.getPlayerTurn(), - game.getNumMoves())); + game.move(new RegularMove(game, new Coordinate(1, 1), new Coordinate(1, 2), game.getPlayerTurn())); game.getBoardState().movePiece(new Coordinate(1, 2), new Coordinate(1, 1)); testOnlyRegularMoves(this.notManyMovesAi); } @@ -71,12 +62,9 @@ public void testNotManyMovesNoPushOrPullIf1MoveLeft() { @Test public void testStartingNoPushOrPullIf1MoveLeft() { Game game = this.startingAi.getGame(); - game.move(new RegularMove(game.getBoardState(), new Coordinate(1, 1), new Coordinate(1, 2), game.getPlayerTurn(), - game.getNumMoves())); - game.move(new RegularMove(game.getBoardState(), new Coordinate(1, 2), new Coordinate(1, 3), game.getPlayerTurn(), - game.getNumMoves())); - game.move(new RegularMove(game.getBoardState(), new Coordinate(1, 3), new Coordinate(1, 4), game.getPlayerTurn(), - game.getNumMoves())); + game.move(new RegularMove(game, new Coordinate(1, 1), new Coordinate(1, 2), game.getPlayerTurn())); + game.move(new RegularMove(game, new Coordinate(1, 2), new Coordinate(1, 3), game.getPlayerTurn())); + game.move(new RegularMove(game, new Coordinate(1, 3), new Coordinate(1, 4), game.getPlayerTurn())); game.getBoardState().movePiece(new Coordinate(1, 4), new Coordinate(1, 1)); testOnlyRegularMoves(this.startingAi); } diff --git a/test/game/TestEndGame.java b/test/game/TestEndGame.java index da06869..c7367c9 100644 --- a/test/game/TestEndGame.java +++ b/test/game/TestEndGame.java @@ -69,8 +69,7 @@ public void testLoseWithNoMoves1() { noMovesP1.put(new Coordinate(5, 5), new Rabbit(Owner.Player2)); Game game = new Game(new BoardState(noMovesP1)); - assertTrue(game.move(new RegularMove(game.getBoardState(), new Coordinate(4, 3), new Coordinate(4, 4), - game.getPlayerTurn(), game.getNumMoves()))); + assertTrue(game.move(new RegularMove(game, new Coordinate(4, 3), new Coordinate(4, 4), game.getPlayerTurn()))); assertTrue(game.hasNoMoves(game.getPlayerTurn())); assertEquals(Owner.Player2, game.getWinner()); @@ -97,10 +96,8 @@ public void testLoseWithNoMovesIfOnlyPushAvaliableButWeaker() { Game game = new Game(new BoardState(p)); - assertTrue(game.move(new RegularMove(game.getBoardState(), new Coordinate(4, 3), new Coordinate(4, 4), - game.getPlayerTurn(), game.getNumMoves()))); - assertTrue(game.move(new RegularMove(game.getBoardState(), new Coordinate(4, 2), new Coordinate(4, 3), - game.getPlayerTurn(), game.getNumMoves()))); + assertTrue(game.move(new RegularMove(game, new Coordinate(4, 3), new Coordinate(4, 4), game.getPlayerTurn()))); + assertTrue(game.move(new RegularMove(game, new Coordinate(4, 2), new Coordinate(4, 3), game.getPlayerTurn()))); assertTrue(game.hasNoMoves(game.getPlayerTurn())); assertEquals(Owner.Player2, game.getWinner()); @@ -128,10 +125,8 @@ public void testLoseWithNoMovesIfOnlyPushAvaliableButEqualStrength() { Game game = new Game(new BoardState(p)); game.incrementTurn(); - assertTrue(game.move(new RegularMove(game.getBoardState(), new Coordinate(4, 5), new Coordinate(4, 4), - game.getPlayerTurn(), game.getNumMoves()))); - assertTrue(game.move(new RegularMove(game.getBoardState(), new Coordinate(4, 6), new Coordinate(4, 5), - game.getPlayerTurn(), game.getNumMoves()))); + assertTrue(game.move(new RegularMove(game, new Coordinate(4, 5), new Coordinate(4, 4), game.getPlayerTurn()))); + assertTrue(game.move(new RegularMove(game, new Coordinate(4, 6), new Coordinate(4, 5), game.getPlayerTurn()))); assertTrue(game.hasNoMoves(Owner.Player2)); assertEquals(Owner.Player1, game.getWinner()); @@ -159,21 +154,18 @@ public void testLoseWithNoMovesIfOnlyPushAvaliableAndNotEnoughMovesLeft() { p.put(new Coordinate(3, 4), new Rabbit(Owner.Player2)); Game game = new Game(new BoardState(p)); - assertTrue(game.move(new RegularMove(game.getBoardState(), new Coordinate(4, 0), new Coordinate(5, 0), - game.getPlayerTurn(), game.getNumMoves()))); + assertTrue(game.move(new RegularMove(game, new Coordinate(4, 0), new Coordinate(5, 0), game.getPlayerTurn()))); assertEquals(Owner.Nobody, game.getWinner()); - assertTrue(game.move(new RegularMove(game.getBoardState(), new Coordinate(5, 0), new Coordinate(5, 1), - game.getPlayerTurn(), game.getNumMoves()))); + assertTrue(game.move(new RegularMove(game, new Coordinate(5, 0), new Coordinate(5, 1), game.getPlayerTurn()))); assertEquals(Owner.Nobody, game.getWinner()); - assertTrue(game.move(new RegularMove(game.getBoardState(), new Coordinate(5, 1), new Coordinate(5, 2), - game.getPlayerTurn(), game.getNumMoves()))); + assertTrue(game.move(new RegularMove(game, new Coordinate(5, 1), new Coordinate(5, 2), game.getPlayerTurn()))); assertTrue(game.hasNoMoves(Owner.Player1)); assertEquals(Owner.Player2, game.getWinner()); } - + @Test public void testPlayer1WinThroughtRabbitElimination() { HashMap p = new HashMap(); @@ -183,11 +175,11 @@ public void testPlayer1WinThroughtRabbitElimination() { Game game = new Game(new BoardState(p)); assertEquals(Owner.Nobody, game.getWinner()); - assertTrue(game.move(new RegularMove(game.getBoardState(), new Coordinate(3, 3), new Coordinate(3, 4), - game.getPlayerTurn(), game.getNumMoves()))); - + assertTrue(game.move(new RegularMove(game, new Coordinate(3, 3), new Coordinate(3, 4), game.getPlayerTurn()))); + assertEquals(Owner.Player1, game.getWinner()); } + @Test public void testPlayer2WinThroughtRabbitElimination() { HashMap p = new HashMap(); @@ -197,9 +189,8 @@ public void testPlayer2WinThroughtRabbitElimination() { Game game = new Game(new BoardState(p)); assertEquals(Owner.Nobody, game.getWinner()); - assertTrue(game.move(new RegularMove(game.getBoardState(), new Coordinate(3, 3), new Coordinate(3, 4), - game.getPlayerTurn(), game.getNumMoves()))); - + assertTrue(game.move(new RegularMove(game, new Coordinate(3, 3), new Coordinate(3, 4), game.getPlayerTurn()))); + assertEquals(Owner.Player2, game.getWinner()); } @@ -210,7 +201,7 @@ public void testPlayer2Win() { Coordinate start = new Coordinate(1, 1); Coordinate end = start.up(); Owner owner = game.getPlayerTurn(); - MoveCommand move = new RegularMove(game.getBoardState(), start, end, owner, game.getNumMoves()); + MoveCommand move = new RegularMove(game, start, end, owner); assertTrue(game.move(move)); assertEquals(Owner.Player2, game.getWinner()); } @@ -220,7 +211,7 @@ public void testPlayer1Win() { Coordinate start = new Coordinate(1, 6); Coordinate end = start.down(); Owner owner = game.getPlayerTurn(); - MoveCommand move = new RegularMove(game.getBoardState(), start, end, owner, game.getNumMoves()); + MoveCommand move = new RegularMove(game, start, end, owner); assertTrue(game.move(move)); assertEquals(Owner.Player1, game.getWinner()); } @@ -230,7 +221,7 @@ public void testWinWhenP1HasNoRabbits() { Coordinate start = new Coordinate(1, 1); Coordinate end = start.down(); Owner owner = game2.getPlayerTurn(); - MoveCommand move = new RegularMove(game2.getBoardState(), start, end, owner, game2.getNumMoves()); + MoveCommand move = new RegularMove(game2, start, end, owner); game2.move(move); assertEquals(Owner.Player2, game2.getWinner()); } @@ -240,7 +231,7 @@ public void testCheckFriendlyAdjacentDownCase() { Coordinate start = new Coordinate(5, 1); Coordinate end = start.right(); Owner owner = game2.getPlayerTurn(); - MoveCommand move = new RegularMove(game2.getBoardState(), start, end, owner, game2.getNumMoves()); + MoveCommand move = new RegularMove(game2, start, end, owner); assertTrue(game2.move(move)); } @@ -250,42 +241,42 @@ public void testEndMove() { Coordinate start = new Coordinate(0, 1); Coordinate end = start.down(); Owner owner = g.getPlayerTurn(); - MoveCommand move = new RegularMove(g.getBoardState(), start, end, owner, g.getNumMoves()); + MoveCommand move = new RegularMove(g, start, end, owner); assertTrue(g.move(move)); start = new Coordinate(0, 2); end = start.down(); owner = g.getPlayerTurn(); - move = new RegularMove(g.getBoardState(), start, end, owner, g.getNumMoves()); + move = new RegularMove(g, start, end, owner); assertTrue(g.move(move)); start = new Coordinate(0, 3); end = start.down(); owner = g.getPlayerTurn(); - move = new RegularMove(g.getBoardState(), start, end, owner, g.getNumMoves()); + move = new RegularMove(g, start, end, owner); assertTrue(g.move(move)); start = new Coordinate(0, 4); end = start.down(); owner = g.getPlayerTurn(); - move = new RegularMove(g.getBoardState(), start, end, owner, g.getNumMoves()); + move = new RegularMove(g, start, end, owner); assertTrue(g.move(move)); start = new Coordinate(1, 6); end = start.up(); owner = g.getPlayerTurn(); - move = new RegularMove(g.getBoardState(), start, end, owner, g.getNumMoves()); + move = new RegularMove(g, start, end, owner); assertTrue(g.move(move)); start = new Coordinate(1, 5); end = start.up(); owner = g.getPlayerTurn(); - move = new RegularMove(g.getBoardState(), start, end, owner, g.getNumMoves()); + move = new RegularMove(g, start, end, owner); assertTrue(g.move(move)); start = new Coordinate(1, 4); end = start.up(); owner = g.getPlayerTurn(); - move = new RegularMove(g.getBoardState(), start, end, owner, g.getNumMoves()); + move = new RegularMove(g, start, end, owner); assertTrue(g.move(move)); start = new Coordinate(1, 3); end = start.up(); owner = g.getPlayerTurn(); - move = new RegularMove(g.getBoardState(), start, end, owner, g.getNumMoves()); + move = new RegularMove(g, start, end, owner); assertTrue(g.move(move)); } } diff --git a/test/game/TestGame.java b/test/game/TestGame.java index e41781f..7291490 100644 --- a/test/game/TestGame.java +++ b/test/game/TestGame.java @@ -227,15 +227,13 @@ public void testGetMoves() { assertTrue(game.getMoves().isEmpty()); ArrayList list = new ArrayList(); - RegularMove move = new RegularMove(game.getBoardState(), new Coordinate(1, 1), new Coordinate(1, 2), - game.getPlayerTurn(), game.getNumMoves()); + RegularMove move = new RegularMove(game, new Coordinate(1, 1), new Coordinate(1, 2), game.getPlayerTurn()); list.add(move); game.move(move); assertEquals(list, game.getMoves()); - move = new RegularMove(game.getBoardState(), new Coordinate(1, 2), new Coordinate(1, 3), game.getPlayerTurn(), - game.getNumMoves()); + move = new RegularMove(game, new Coordinate(1, 2), new Coordinate(1, 3), game.getPlayerTurn()); list.add(move); game.move(move); @@ -248,14 +246,12 @@ public void testGetLastMove() { assertNull(game.getLastMove()); - RegularMove move = new RegularMove(game.getBoardState(), new Coordinate(1, 1), new Coordinate(1, 2), - game.getPlayerTurn(), game.getNumMoves()); + RegularMove move = new RegularMove(game, new Coordinate(1, 1), new Coordinate(1, 2), game.getPlayerTurn()); game.move(move); assertEquals(move, game.getLastMove()); - move = new RegularMove(game.getBoardState(), new Coordinate(1, 2), new Coordinate(1, 3), game.getPlayerTurn(), - game.getNumMoves()); + move = new RegularMove(game, new Coordinate(1, 2), new Coordinate(1, 3), game.getPlayerTurn()); game.move(move); assertEquals(move, game.getLastMove()); @@ -266,15 +262,13 @@ public void testDeadCoorsAreRemoved() { Game game = new Game(); HashSet deadCoors = new HashSet(); - RegularMove move = new RegularMove(game.getBoardState(), new Coordinate(2, 1), new Coordinate(2, 2), - game.getPlayerTurn(), game.getNumMoves()); + RegularMove move = new RegularMove(game, new Coordinate(2, 1), new Coordinate(2, 2), game.getPlayerTurn()); game.move(move); deadCoors.add(new Coordinate(2, 2)); assertEquals(deadCoors, game.getDeadCoors()); - move = new RegularMove(game.getBoardState(), new Coordinate(5, 1), new Coordinate(5, 2), game.getPlayerTurn(), - game.getNumMoves()); + move = new RegularMove(game, new Coordinate(5, 1), new Coordinate(5, 2), game.getPlayerTurn()); game.move(move); deadCoors.add(new Coordinate(5, 2)); @@ -425,7 +419,7 @@ public void testRemovePieceValid() { Coordinate start = new Coordinate(3, 6); Coordinate end = start.up(); Owner owner = game.getPlayerTurn(); - MoveCommand move = new RegularMove(game.getBoardState(), start, end, owner, game.getNumMoves()); + MoveCommand move = new RegularMove(game, start, end, owner); assertTrue(game.move(move)); // g.currentBoard.printBoard(); assertFalse(game.isPieceAt(new Coordinate(2, 2))); @@ -453,7 +447,7 @@ public void testRemovePiece2() { Coordinate start = new Coordinate(2, 2); Coordinate end = start.up(); Owner owner = game.getPlayerTurn(); - MoveCommand move = new RegularMove(game.getBoardState(), start, end, owner, game.getNumMoves()); + MoveCommand move = new RegularMove(game, start, end, owner); game.move(move); assertTrue(game.isPieceAt(end)); assertTrue(game.getDeadCoors().isEmpty()); @@ -461,7 +455,7 @@ public void testRemovePiece2() { start = new Coordinate(5, 1); end = start.up(); owner = game.getPlayerTurn(); - move = new RegularMove(game.getBoardState(), start, end, owner, game.getNumMoves()); + move = new RegularMove(game, start, end, owner); game.move(move); assertFalse(game.isPieceAt(new Coordinate(5, 2))); diff --git a/test/game/TestGameEquality.java b/test/game/TestGameEquality.java index 6357380..e69c146 100644 --- a/test/game/TestGameEquality.java +++ b/test/game/TestGameEquality.java @@ -19,10 +19,8 @@ public class TestGameEquality { public void setup() { this.g1 = new Game(); this.g2 = new Game(); - this.g1.move(new RegularMove(this.g1.getBoardState(), new Coordinate(0, 1), new Coordinate(0, 2), Owner.Player1, - this.g1.getNumMoves())); - this.g2.move(new RegularMove(this.g2.getBoardState(), new Coordinate(0, 1), new Coordinate(0, 2), Owner.Player1, - this.g2.getNumMoves())); + this.g1.move(new RegularMove(this.g1, new Coordinate(0, 1), new Coordinate(0, 2), Owner.Player1)); + this.g2.move(new RegularMove(this.g2, new Coordinate(0, 1), new Coordinate(0, 2), Owner.Player1)); } public void testNotEquals(VoidMethod method) { @@ -54,8 +52,7 @@ public void testGameEqualIsSymmetric() { @Test public void testGameNotEqualIfDifferentMoves() { testNotEquals(() -> { - RegularMove move = new RegularMove(this.g1.getBoardState(), new Coordinate(0, 2), new Coordinate(0, 3), - Owner.Player1, this.g1.getNumMoves()); + RegularMove move = new RegularMove(this.g1, new Coordinate(0, 2), new Coordinate(0, 3), Owner.Player1); this.g1.getMoves().add(move); }); } @@ -89,26 +86,22 @@ public void testGameNotEqualIfDifferentTurnCounter() { testNotEquals(() -> { // to increment the turn counter, make moves and delete them // 1st move - RegularMove move = new RegularMove(this.g1.getBoardState(), new Coordinate(0, 2), new Coordinate(0, 3), - Owner.Player1, this.g1.getNumMoves()); + RegularMove move = new RegularMove(this.g1, new Coordinate(0, 2), new Coordinate(0, 3), Owner.Player1); this.g1.move(move); this.g1.getBoardState().movePiece(new Coordinate(0, 3), new Coordinate(0, 2)); // 2nd move - move = new RegularMove(this.g1.getBoardState(), new Coordinate(0, 2), new Coordinate(0, 3), Owner.Player1, - this.g1.getNumMoves()); + move = new RegularMove(this.g1, new Coordinate(0, 2), new Coordinate(0, 3), Owner.Player1); this.g1.move(move); this.g1.getBoardState().movePiece(new Coordinate(0, 3), new Coordinate(0, 2)); // 3rd move - move = new RegularMove(this.g1.getBoardState(), new Coordinate(0, 2), new Coordinate(0, 3), Owner.Player1, - this.g1.getNumMoves()); + move = new RegularMove(this.g1, new Coordinate(0, 2), new Coordinate(0, 3), Owner.Player1); this.g1.move(move); this.g1.getBoardState().movePiece(new Coordinate(0, 3), new Coordinate(0, 2)); // 4th move - move = new RegularMove(this.g1.getBoardState(), new Coordinate(0, 6), new Coordinate(0, 5), Owner.Player2, - this.g1.getNumMoves()); + move = new RegularMove(this.g1, new Coordinate(0, 6), new Coordinate(0, 5), Owner.Player2); this.g1.move(move); this.g1.getBoardState().movePiece(new Coordinate(0, 5), new Coordinate(0, 6)); @@ -134,8 +127,7 @@ public void testGameNotEqualIfDifferentWinner() { @Test public void testGameNotEqualIfDifferentNumberOfMoves() { testNotEquals(() -> { - RegularMove move = new RegularMove(this.g1.getBoardState(), new Coordinate(0, 2), new Coordinate(0, 3), - Owner.Player1, this.g1.getNumMoves()); + RegularMove move = new RegularMove(this.g1, new Coordinate(0, 2), new Coordinate(0, 3), Owner.Player1); this.g1.move(move); // remove last move this.g1.getMoves().remove(this.g1.getMoves().size() - 1); diff --git a/test/game/TestGameHashCodeEquality.java b/test/game/TestGameHashCodeEquality.java index 468091d..190f7a7 100644 --- a/test/game/TestGameHashCodeEquality.java +++ b/test/game/TestGameHashCodeEquality.java @@ -19,10 +19,8 @@ public class TestGameHashCodeEquality { public void setup() { this.g1 = new Game(); this.g2 = new Game(); - this.g1.move(new RegularMove(this.g1.getBoardState(), new Coordinate(0, 1), new Coordinate(0, 2), Owner.Player1, - this.g1.getNumMoves())); - this.g2.move(new RegularMove(this.g2.getBoardState(), new Coordinate(0, 1), new Coordinate(0, 2), Owner.Player1, - this.g2.getNumMoves())); + this.g1.move(new RegularMove(this.g1, new Coordinate(0, 1), new Coordinate(0, 2), Owner.Player1)); + this.g2.move(new RegularMove(this.g2, new Coordinate(0, 1), new Coordinate(0, 2), Owner.Player1)); } public void testHashCodeNotEquals(VoidMethod method) { @@ -54,8 +52,7 @@ public void testGameEqualIsSymmetric() { @Test public void testGameNotEqualIfDifferentMoves() { testHashCodeNotEquals(() -> { - RegularMove move = new RegularMove(this.g1.getBoardState(), new Coordinate(0, 2), new Coordinate(0, 3), - Owner.Player1, this.g1.getNumMoves()); + RegularMove move = new RegularMove(this.g1, new Coordinate(0, 2), new Coordinate(0, 3), Owner.Player1); this.g1.getMoves().add(move); }); } @@ -67,8 +64,7 @@ public void testGameNotEqualIfDifferentDeadCoors() { }); } - -@Test + @Test public void testGameNotEqualIfDifferentBoardStates() { testHashCodeNotEquals(() -> { this.g1.getBoardState().movePiece(new Coordinate(0, 2), new Coordinate(0, 3)); @@ -90,26 +86,22 @@ public void testGameNotEqualIfDifferentTurnCounter() { testHashCodeNotEquals(() -> { // to increment the turn counter, make moves and delete them // 1st move - RegularMove move = new RegularMove(this.g1.getBoardState(), new Coordinate(0, 2), new Coordinate(0, 3), - Owner.Player1, this.g1.getNumMoves()); + RegularMove move = new RegularMove(this.g1, new Coordinate(0, 2), new Coordinate(0, 3), Owner.Player1); this.g1.move(move); this.g1.getBoardState().movePiece(new Coordinate(0, 3), new Coordinate(0, 2)); // 2nd move - move = new RegularMove(this.g1.getBoardState(), new Coordinate(0, 2), new Coordinate(0, 3), Owner.Player1, - this.g1.getNumMoves()); + move = new RegularMove(this.g1, new Coordinate(0, 2), new Coordinate(0, 3), Owner.Player1); this.g1.move(move); this.g1.getBoardState().movePiece(new Coordinate(0, 3), new Coordinate(0, 2)); // 3rd move - move = new RegularMove(this.g1.getBoardState(), new Coordinate(0, 2), new Coordinate(0, 3), Owner.Player1, - this.g1.getNumMoves()); + move = new RegularMove(this.g1, new Coordinate(0, 2), new Coordinate(0, 3), Owner.Player1); this.g1.move(move); this.g1.getBoardState().movePiece(new Coordinate(0, 3), new Coordinate(0, 2)); // 4th move - move = new RegularMove(this.g1.getBoardState(), new Coordinate(0, 6), new Coordinate(0, 5), Owner.Player2, - this.g1.getNumMoves()); + move = new RegularMove(this.g1, new Coordinate(0, 6), new Coordinate(0, 5), Owner.Player2); this.g1.move(move); this.g1.getBoardState().movePiece(new Coordinate(0, 5), new Coordinate(0, 6)); @@ -135,8 +127,7 @@ public void testGameNotEqualIfDifferentWinner() { @Test public void testGameNotEqualIfDifferentNumberOfMoves() { testHashCodeNotEquals(() -> { - RegularMove move = new RegularMove(this.g1.getBoardState(), new Coordinate(0, 2), new Coordinate(0, 3), - Owner.Player1, this.g1.getNumMoves()); + RegularMove move = new RegularMove(this.g1, new Coordinate(0, 2), new Coordinate(0, 3), Owner.Player1); this.g1.move(move); // remove last move this.g1.getMoves().remove(this.g1.getMoves().size() - 1); diff --git a/test/game/TestHasNoMoves.java b/test/game/TestHasNoMoves.java index 1514050..eb2b1d0 100644 --- a/test/game/TestHasNoMoves.java +++ b/test/game/TestHasNoMoves.java @@ -215,12 +215,9 @@ public void testHasNoMovesReturnsTrueIfOnlyPushAvaliableAndNotEnoughMovesLeft() p.put(new Coordinate(3, 4), new Rabbit(Owner.Player2)); Game game = new Game(new BoardState(p)); - game.move(new RegularMove(game.getBoardState(), new Coordinate(4, 0), new Coordinate(5, 0), - game.getPlayerTurn(), game.getNumMoves())); - game.move(new RegularMove(game.getBoardState(), new Coordinate(5, 0), new Coordinate(5, 1), - game.getPlayerTurn(), game.getNumMoves())); - game.move(new RegularMove(game.getBoardState(), new Coordinate(5, 1), new Coordinate(5, 2), - game.getPlayerTurn(), game.getNumMoves())); + game.move(new RegularMove(game, new Coordinate(4, 0), new Coordinate(5, 0), game.getPlayerTurn())); + game.move(new RegularMove(game, new Coordinate(5, 0), new Coordinate(5, 1), game.getPlayerTurn())); + game.move(new RegularMove(game, new Coordinate(5, 1), new Coordinate(5, 2), game.getPlayerTurn())); exhaustivelyCheckHasNoMoves(game, new Coordinate(4, 4)); assertTrue(game.hasNoMoves(Owner.Player1)); diff --git a/test/game/TestHasPushMove.java b/test/game/TestHasPushMove.java index 6cc4db8..e7dc7f5 100644 --- a/test/game/TestHasPushMove.java +++ b/test/game/TestHasPushMove.java @@ -97,8 +97,7 @@ public void testHasPushMoveReturnsTrueIfThereAre3MovesLeft() { p.put(new Coordinate(4, 3), new Rabbit(Owner.Player2)); Game game = new Game(new BoardState(p)); - game.move(new RegularMove(game.getBoardState(), new Coordinate(5, 4), new Coordinate(4, 4), - game.getPlayerTurn(), game.getNumMoves())); + game.move(new RegularMove(game, new Coordinate(5, 4), new Coordinate(4, 4), game.getPlayerTurn())); exhaustivelyCheckPushMoves(game, new Coordinate(4, 4)); } @@ -110,10 +109,8 @@ public void testHasPushMoveReturnsTrueIfThereAre2MovesLeft() { p.put(new Coordinate(4, 3), new Rabbit(Owner.Player2)); Game game = new Game(new BoardState(p)); - game.move(new RegularMove(game.getBoardState(), new Coordinate(4, 4), new Coordinate(5, 4), - game.getPlayerTurn(), game.getNumMoves())); - game.move(new RegularMove(game.getBoardState(), new Coordinate(5, 4), new Coordinate(4, 4), - game.getPlayerTurn(), game.getNumMoves())); + game.move(new RegularMove(game, new Coordinate(4, 4), new Coordinate(5, 4), game.getPlayerTurn())); + game.move(new RegularMove(game, new Coordinate(5, 4), new Coordinate(4, 4), game.getPlayerTurn())); exhaustivelyCheckPushMoves(game, new Coordinate(4, 4)); } @@ -125,12 +122,9 @@ public void testHasPushMoveReturnsTrueIfThereIs1MoveLeft() { p.put(new Coordinate(4, 3), new Rabbit(Owner.Player2)); Game game = new Game(new BoardState(p)); - game.move(new RegularMove(game.getBoardState(), new Coordinate(5, 4), new Coordinate(4, 4), - game.getPlayerTurn(), game.getNumMoves())); - game.move(new RegularMove(game.getBoardState(), new Coordinate(4, 4), new Coordinate(5, 4), - game.getPlayerTurn(), game.getNumMoves())); - game.move(new RegularMove(game.getBoardState(), new Coordinate(5, 4), new Coordinate(4, 4), - game.getPlayerTurn(), game.getNumMoves())); + game.move(new RegularMove(game, new Coordinate(5, 4), new Coordinate(4, 4), game.getPlayerTurn())); + game.move(new RegularMove(game, new Coordinate(4, 4), new Coordinate(5, 4), game.getPlayerTurn())); + game.move(new RegularMove(game, new Coordinate(5, 4), new Coordinate(4, 4), game.getPlayerTurn())); exhaustivelyCheckNoPushMoves(game, new Coordinate(4, 4)); } diff --git a/test/game/TestUndo.java b/test/game/TestUndo.java index 0a499ac..7edc5ba 100644 --- a/test/game/TestUndo.java +++ b/test/game/TestUndo.java @@ -25,8 +25,7 @@ public void testBaseUndoCase() { Coordinate start = new Coordinate(0, 1); Coordinate end = start.down(); Owner owner = standardStart.getPlayerTurn(); - MoveCommand move = new RegularMove(standardStart.getBoardState(), start, end, owner, - standardStart.getNumMoves()); + MoveCommand move = new RegularMove(standardStart, start, end, owner); standardStart.move(move); assertEquals(new Rabbit(Owner.Player1), standardStart.getPieceAt(end)); standardStart.undoMove(); @@ -38,11 +37,11 @@ public void testUndoTwoMoves() { Coordinate start = new Coordinate(0, 1); Coordinate end = start.down(); Owner owner = g.getPlayerTurn(); - MoveCommand move = new RegularMove(g.getBoardState(), start, end, owner, g.getNumMoves()); + MoveCommand move = new RegularMove(g, start, end, owner); g.move(move); start = new Coordinate(0, 2); end = start.down(); - move = new RegularMove(g.getBoardState(), start, end, owner, g.getNumMoves()); + move = new RegularMove(g, start, end, owner); g.move(move); assertEquals(new Rabbit(Owner.Player1), g.getPieceAt(end)); g.undoMove(); @@ -54,15 +53,15 @@ public void testUndoThreeMoves() { Coordinate start = new Coordinate(0, 1); Coordinate end = start.down(); Owner owner = g.getPlayerTurn(); - MoveCommand move = new RegularMove(g.getBoardState(), start, end, owner, g.getNumMoves()); + MoveCommand move = new RegularMove(g, start, end, owner); g.move(move); start = new Coordinate(0, 2); end = start.down(); - move = new RegularMove(g.getBoardState(), start, end, owner, g.getNumMoves()); + move = new RegularMove(g, start, end, owner); g.move(move); start = new Coordinate(0, 3); end = start.down(); - move = new RegularMove(g.getBoardState(), start, end, owner, g.getNumMoves()); + move = new RegularMove(g, start, end, owner); g.move(move); assertEquals(new Rabbit(Owner.Player1), g.getPieceAt(end)); g.undoMove(); @@ -74,19 +73,19 @@ public void testThatUndoCantCrossTurns() { Coordinate start = new Coordinate(0, 1); Coordinate end = start.down(); Owner owner = g.getPlayerTurn(); - MoveCommand move = new RegularMove(g.getBoardState(), start, end, owner, g.getNumMoves()); + MoveCommand move = new RegularMove(g, start, end, owner); g.move(move); start = new Coordinate(0, 2); end = start.down(); - move = new RegularMove(g.getBoardState(), start, end, owner, g.getNumMoves()); + move = new RegularMove(g, start, end, owner); g.move(move); start = new Coordinate(0, 3); end = start.down(); - move = new RegularMove(g.getBoardState(), start, end, owner, g.getNumMoves()); + move = new RegularMove(g, start, end, owner); g.move(move); start = new Coordinate(0, 4); end = start.down(); - move = new RegularMove(g.getBoardState(), start, end, owner, g.getNumMoves()); + move = new RegularMove(g, start, end, owner); g.move(move); g.undoMove(); assertEquals(new Rabbit(Owner.Player1), g.getPieceAt(new Coordinate(0, 5))); @@ -97,7 +96,7 @@ public void testThatUndoGrantsMoves() { Coordinate start = new Coordinate(0, 1); Coordinate end = start.down(); Owner owner = g.getPlayerTurn(); - MoveCommand move = new RegularMove(g.getBoardState(), start, end, owner, g.getNumMoves()); + MoveCommand move = new RegularMove(g, start, end, owner); g.move(move); g.undoMove(); assertEquals(4, g.getNumMoves()); diff --git a/test/move_commands/TestMoveCommandEquality.java b/test/move_commands/TestMoveCommandEquality.java index 47c7b72..b53c46f 100644 --- a/test/move_commands/TestMoveCommandEquality.java +++ b/test/move_commands/TestMoveCommandEquality.java @@ -7,15 +7,14 @@ import org.junit.Before; import org.junit.Test; -import board.BoardState; import board.Coordinate; +import game.Game; import piece.Owner; public class TestMoveCommandEquality { - private static final int NUMBER_OF_MOVES = 4; private Owner owner; private Owner otherOwner; - private BoardState board; + private Game game; private RegularMove regularMove; private PullMove pullMove; @@ -25,17 +24,16 @@ public class TestMoveCommandEquality { public void setup() { this.owner = Owner.Player1; this.otherOwner = Owner.Player2; - this.board = new BoardState(); - this.board.movePiece(new Coordinate(3, 0), new Coordinate(3, 3)); - this.board.movePiece(new Coordinate(3, 6), new Coordinate(3, 4)); - this.board.movePiece(new Coordinate(2, 6), new Coordinate(2, 3)); - - this.regularMove = new RegularMove(new BoardState(this.board), new Coordinate(3, 3), new Coordinate(4, 3), this.owner, - NUMBER_OF_MOVES); - this.pullMove = new PullMove(new BoardState(this.board), new Coordinate(3, 3), new Coordinate(4, 3), - new Coordinate(3, 4), this.owner, NUMBER_OF_MOVES); - this.pushMove = new PushMove(new BoardState(this.board), new Coordinate(3, 3), new Coordinate(3, 4), - new Coordinate(4, 4), this.owner, NUMBER_OF_MOVES); + this.game = new Game(); + this.game.getBoardState().movePiece(new Coordinate(3, 0), new Coordinate(3, 3)); + this.game.getBoardState().movePiece(new Coordinate(3, 6), new Coordinate(3, 4)); + this.game.getBoardState().movePiece(new Coordinate(2, 6), new Coordinate(2, 3)); + + this.regularMove = new RegularMove(new Game(this.game), new Coordinate(3, 3), new Coordinate(4, 3), this.owner); + this.pullMove = new PullMove(new Game(this.game), new Coordinate(3, 3), new Coordinate(4, 3), + new Coordinate(3, 4), this.owner); + this.pushMove = new PushMove(new Game(this.game), new Coordinate(3, 3), new Coordinate(3, 4), + new Coordinate(4, 4), this.owner); } @Test @@ -44,16 +42,16 @@ public void testEqualityRegularMove() { assertEquals(this.regularMove, this.regularMove); assertEquals(this.regularMove, - new RegularMove(this.board, new Coordinate(3, 3), new Coordinate(4, 3), this.owner, NUMBER_OF_MOVES)); + new RegularMove(this.game, new Coordinate(3, 3), new Coordinate(4, 3), this.owner)); - assertNotEquals(this.regularMove, new RegularMove(new BoardState(), new Coordinate(3, 3), new Coordinate(4, 3), - this.owner, NUMBER_OF_MOVES)); assertNotEquals(this.regularMove, - new RegularMove(this.board, new Coordinate(5, 3), new Coordinate(4, 3), this.owner, NUMBER_OF_MOVES)); + new RegularMove(new Game(), new Coordinate(3, 3), new Coordinate(4, 3), this.owner)); assertNotEquals(this.regularMove, - new RegularMove(this.board, new Coordinate(3, 3), new Coordinate(3, 2), this.owner, NUMBER_OF_MOVES)); - assertNotEquals(this.regularMove, new RegularMove(this.board, new Coordinate(3, 3), new Coordinate(4, 3), - this.otherOwner, NUMBER_OF_MOVES)); + new RegularMove(this.game, new Coordinate(5, 3), new Coordinate(4, 3), this.owner)); + assertNotEquals(this.regularMove, + new RegularMove(this.game, new Coordinate(3, 3), new Coordinate(3, 2), this.owner)); + assertNotEquals(this.regularMove, + new RegularMove(this.game, new Coordinate(3, 3), new Coordinate(4, 3), this.otherOwner)); assertNotEquals(this.regularMove, this.pullMove); assertNotEquals(this.regularMove, this.pushMove); @@ -64,19 +62,19 @@ public void testEqualityPullMove() { assertNotEquals(this.pullMove, null); assertEquals(this.pullMove, this.pullMove); - assertEquals(this.pullMove, new PullMove(this.board, new Coordinate(3, 3), new Coordinate(4, 3), - new Coordinate(3, 4), this.owner, NUMBER_OF_MOVES)); - - assertNotEquals(this.pullMove, new PullMove(new BoardState(), new Coordinate(3, 3), new Coordinate(4, 3), - new Coordinate(3, 4), this.owner, NUMBER_OF_MOVES)); - assertNotEquals(this.pullMove, new PullMove(this.board, new Coordinate(5, 3), new Coordinate(4, 3), - new Coordinate(3, 4), this.owner, NUMBER_OF_MOVES)); - assertNotEquals(this.pullMove, new PullMove(this.board, new Coordinate(3, 3), new Coordinate(3, 2), - new Coordinate(3, 4), this.owner, NUMBER_OF_MOVES)); - assertNotEquals(this.pullMove, new PullMove(this.board, new Coordinate(3, 3), new Coordinate(4, 3), - new Coordinate(2, 3), this.owner, NUMBER_OF_MOVES)); - assertNotEquals(this.pullMove, new PullMove(this.board, new Coordinate(3, 3), new Coordinate(4, 3), - new Coordinate(3, 4), this.otherOwner, NUMBER_OF_MOVES)); + assertEquals(this.pullMove, + new PullMove(this.game, new Coordinate(3, 3), new Coordinate(4, 3), new Coordinate(3, 4), this.owner)); + + assertNotEquals(this.pullMove, + new PullMove(new Game(), new Coordinate(3, 3), new Coordinate(4, 3), new Coordinate(3, 4), this.owner)); + assertNotEquals(this.pullMove, + new PullMove(this.game, new Coordinate(5, 3), new Coordinate(4, 3), new Coordinate(3, 4), this.owner)); + assertNotEquals(this.pullMove, + new PullMove(this.game, new Coordinate(3, 3), new Coordinate(3, 2), new Coordinate(3, 4), this.owner)); + assertNotEquals(this.pullMove, + new PullMove(this.game, new Coordinate(3, 3), new Coordinate(4, 3), new Coordinate(2, 3), this.owner)); + assertNotEquals(this.pullMove, new PullMove(this.game, new Coordinate(3, 3), new Coordinate(4, 3), + new Coordinate(3, 4), this.otherOwner)); assertNotEquals(this.pullMove, this.regularMove); assertNotEquals(this.pullMove, this.pushMove); @@ -87,19 +85,19 @@ public void testEqualityPushMove() { assertNotEquals(this.pushMove, null); assertEquals(this.pushMove, this.pushMove); - assertEquals(this.pushMove, new PushMove(this.board, new Coordinate(3, 3), new Coordinate(3, 4), - new Coordinate(4, 4), this.owner, NUMBER_OF_MOVES)); - - assertNotEquals(this.pushMove, new PushMove(new BoardState(), new Coordinate(3, 3), new Coordinate(3, 4), - new Coordinate(4, 4), this.owner, NUMBER_OF_MOVES)); - assertNotEquals(this.pushMove, new PushMove(this.board, new Coordinate(4, 4), new Coordinate(3, 4), - new Coordinate(4, 4), this.owner, NUMBER_OF_MOVES)); - assertNotEquals(this.pushMove, new PushMove(this.board, new Coordinate(3, 3), new Coordinate(2, 3), - new Coordinate(4, 4), this.owner, NUMBER_OF_MOVES)); - assertNotEquals(this.pushMove, new PushMove(this.board, new Coordinate(3, 3), new Coordinate(3, 4), - new Coordinate(2, 4), this.owner, NUMBER_OF_MOVES)); - assertNotEquals(this.pushMove, new PushMove(this.board, new Coordinate(3, 3), new Coordinate(3, 4), - new Coordinate(4, 4), this.otherOwner, NUMBER_OF_MOVES)); + assertEquals(this.pushMove, + new PushMove(this.game, new Coordinate(3, 3), new Coordinate(3, 4), new Coordinate(4, 4), this.owner)); + + assertNotEquals(this.pushMove, + new PushMove(new Game(), new Coordinate(3, 3), new Coordinate(3, 4), new Coordinate(4, 4), this.owner)); + assertNotEquals(this.pushMove, + new PushMove(this.game, new Coordinate(4, 4), new Coordinate(3, 4), new Coordinate(4, 4), this.owner)); + assertNotEquals(this.pushMove, + new PushMove(this.game, new Coordinate(3, 3), new Coordinate(2, 3), new Coordinate(4, 4), this.owner)); + assertNotEquals(this.pushMove, + new PushMove(this.game, new Coordinate(3, 3), new Coordinate(3, 4), new Coordinate(2, 4), this.owner)); + assertNotEquals(this.pushMove, new PushMove(this.game, new Coordinate(3, 3), new Coordinate(3, 4), + new Coordinate(4, 4), this.otherOwner)); assertNotEquals(this.pushMove, this.regularMove); assertNotEquals(this.pushMove, this.pullMove); @@ -111,19 +109,16 @@ public void testHashCodeRegularMove() { assertEquals(this.regularMove.hashCode(), this.regularMove.hashCode()); assertEquals(this.regularMove.hashCode(), - new RegularMove(this.board, new Coordinate(3, 3), new Coordinate(4, 3), this.owner, NUMBER_OF_MOVES) - .hashCode()); + new RegularMove(this.game, new Coordinate(3, 3), new Coordinate(4, 3), this.owner).hashCode()); - assertNotEquals(this.regularMove.hashCode(), new RegularMove(new BoardState(), new Coordinate(3, 3), - new Coordinate(4, 3), this.owner, NUMBER_OF_MOVES).hashCode()); assertNotEquals(this.regularMove.hashCode(), - new RegularMove(this.board, new Coordinate(5, 3), new Coordinate(4, 3), this.owner, NUMBER_OF_MOVES) - .hashCode()); + new RegularMove(new Game(), new Coordinate(3, 3), new Coordinate(4, 3), this.owner).hashCode()); assertNotEquals(this.regularMove.hashCode(), - new RegularMove(this.board, new Coordinate(3, 3), new Coordinate(3, 2), this.owner, NUMBER_OF_MOVES) - .hashCode()); - assertNotEquals(this.regularMove.hashCode(), new RegularMove(this.board, new Coordinate(3, 3), - new Coordinate(4, 3), this.otherOwner, NUMBER_OF_MOVES).hashCode()); + new RegularMove(this.game, new Coordinate(5, 3), new Coordinate(4, 3), this.owner).hashCode()); + assertNotEquals(this.regularMove.hashCode(), + new RegularMove(this.game, new Coordinate(3, 3), new Coordinate(3, 2), this.owner).hashCode()); + assertNotEquals(this.regularMove.hashCode(), + new RegularMove(this.game, new Coordinate(3, 3), new Coordinate(4, 3), this.otherOwner).hashCode()); assertNotEquals(this.regularMove.hashCode(), this.pullMove.hashCode()); assertNotEquals(this.regularMove.hashCode(), this.pushMove.hashCode()); @@ -134,19 +129,24 @@ public void testHashCodePullMove() { assertNotNull(this.pullMove.hashCode()); assertEquals(this.pullMove.hashCode(), this.pullMove.hashCode()); - assertEquals(this.pullMove.hashCode(), new PullMove(this.board, new Coordinate(3, 3), new Coordinate(4, 3), - new Coordinate(3, 4), this.owner, NUMBER_OF_MOVES).hashCode()); - - assertNotEquals(this.pullMove.hashCode(), new PullMove(new BoardState(), new Coordinate(3, 3), - new Coordinate(4, 3), new Coordinate(3, 4), this.owner, NUMBER_OF_MOVES).hashCode()); - assertNotEquals(this.pullMove.hashCode(), new PullMove(this.board, new Coordinate(5, 3), new Coordinate(4, 3), - new Coordinate(3, 4), this.owner, NUMBER_OF_MOVES).hashCode()); - assertNotEquals(this.pullMove.hashCode(), new PullMove(this.board, new Coordinate(3, 3), new Coordinate(3, 2), - new Coordinate(3, 4), this.owner, NUMBER_OF_MOVES).hashCode()); - assertNotEquals(this.pullMove.hashCode(), new PullMove(this.board, new Coordinate(3, 3), new Coordinate(4, 3), - new Coordinate(2, 3), this.owner, NUMBER_OF_MOVES).hashCode()); - assertNotEquals(this.pullMove.hashCode(), new PullMove(this.board, new Coordinate(3, 3), new Coordinate(4, 3), - new Coordinate(3, 4), this.otherOwner, NUMBER_OF_MOVES).hashCode()); + assertEquals(this.pullMove.hashCode(), + new PullMove(this.game, new Coordinate(3, 3), new Coordinate(4, 3), new Coordinate(3, 4), this.owner) + .hashCode()); + + assertNotEquals(this.pullMove.hashCode(), + new PullMove(new Game(), new Coordinate(3, 3), new Coordinate(4, 3), new Coordinate(3, 4), this.owner) + .hashCode()); + assertNotEquals(this.pullMove.hashCode(), + new PullMove(this.game, new Coordinate(5, 3), new Coordinate(4, 3), new Coordinate(3, 4), this.owner) + .hashCode()); + assertNotEquals(this.pullMove.hashCode(), + new PullMove(this.game, new Coordinate(3, 3), new Coordinate(3, 2), new Coordinate(3, 4), this.owner) + .hashCode()); + assertNotEquals(this.pullMove.hashCode(), + new PullMove(this.game, new Coordinate(3, 3), new Coordinate(4, 3), new Coordinate(2, 3), this.owner) + .hashCode()); + assertNotEquals(this.pullMove.hashCode(), new PullMove(this.game, new Coordinate(3, 3), new Coordinate(4, 3), + new Coordinate(3, 4), this.otherOwner).hashCode()); assertNotEquals(this.pullMove.hashCode(), this.regularMove); assertNotEquals(this.pullMove.hashCode(), this.pushMove.hashCode()); @@ -157,19 +157,24 @@ public void testHashCodePushMove() { assertNotEquals(this.pushMove.hashCode(), null); assertEquals(this.pushMove.hashCode(), this.pushMove.hashCode()); - assertEquals(this.pushMove.hashCode(), new PushMove(this.board, new Coordinate(3, 3), new Coordinate(3, 4), - new Coordinate(4, 4), this.owner, NUMBER_OF_MOVES).hashCode()); - - assertNotEquals(this.pushMove.hashCode(), new PushMove(new BoardState(), new Coordinate(3, 3), - new Coordinate(3, 4), new Coordinate(4, 4), this.owner, NUMBER_OF_MOVES).hashCode()); - assertNotEquals(this.pushMove.hashCode(), new PushMove(this.board, new Coordinate(4, 4), new Coordinate(3, 4), - new Coordinate(4, 4), this.owner, NUMBER_OF_MOVES).hashCode()); - assertNotEquals(this.pushMove.hashCode(), new PushMove(this.board, new Coordinate(3, 3), new Coordinate(2, 3), - new Coordinate(4, 4), this.owner, NUMBER_OF_MOVES).hashCode()); - assertNotEquals(this.pushMove.hashCode(), new PushMove(this.board, new Coordinate(3, 3), new Coordinate(3, 4), - new Coordinate(2, 4), this.owner, NUMBER_OF_MOVES).hashCode()); - assertNotEquals(this.pushMove.hashCode(), new PushMove(this.board, new Coordinate(3, 3), new Coordinate(3, 4), - new Coordinate(4, 4), this.otherOwner, NUMBER_OF_MOVES).hashCode()); + assertEquals(this.pushMove.hashCode(), + new PushMove(this.game, new Coordinate(3, 3), new Coordinate(3, 4), new Coordinate(4, 4), this.owner) + .hashCode()); + + assertNotEquals(this.pushMove.hashCode(), + new PushMove(new Game(), new Coordinate(3, 3), new Coordinate(3, 4), new Coordinate(4, 4), this.owner) + .hashCode()); + assertNotEquals(this.pushMove.hashCode(), + new PushMove(this.game, new Coordinate(4, 4), new Coordinate(3, 4), new Coordinate(4, 4), this.owner) + .hashCode()); + assertNotEquals(this.pushMove.hashCode(), + new PushMove(this.game, new Coordinate(3, 3), new Coordinate(2, 3), new Coordinate(4, 4), this.owner) + .hashCode()); + assertNotEquals(this.pushMove.hashCode(), + new PushMove(this.game, new Coordinate(3, 3), new Coordinate(3, 4), new Coordinate(2, 4), this.owner) + .hashCode()); + assertNotEquals(this.pushMove.hashCode(), new PushMove(this.game, new Coordinate(3, 3), new Coordinate(3, 4), + new Coordinate(4, 4), this.otherOwner).hashCode()); assertNotEquals(this.pushMove.hashCode(), this.regularMove); assertNotEquals(this.pushMove.hashCode(), this.pullMove.hashCode()); diff --git a/test/move_commands/TestPullInvalid.java b/test/move_commands/TestPullInvalid.java index f71d462..7b65826 100644 --- a/test/move_commands/TestPullInvalid.java +++ b/test/move_commands/TestPullInvalid.java @@ -27,127 +27,127 @@ public void testInvalidPull(MoveCommand move) { @Test public void testExecutingAnInvalidMoveReturnsTheOriginalBoard() { - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(5, -1), new Coordinate(5, 0), - new Coordinate(5, -2), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(5, -1), new Coordinate(5, 0), new Coordinate(5, -2), + pullingGame.getPlayerTurn()); BoardState board = new BoardState(pullingGame.getBoardState()); assertEquals(board, move.execute()); } @Test public void testOffBoard1() { - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(5, -1), new Coordinate(5, 0), - new Coordinate(5, -2), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(5, -1), new Coordinate(5, 0), new Coordinate(5, -2), + pullingGame.getPlayerTurn()); testInvalidPull(move); } @Test public void testOffBoard2() { - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(7, 0), new Coordinate(7, -1), - new Coordinate(7, 1), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(7, 0), new Coordinate(7, -1), new Coordinate(7, 1), + pullingGame.getPlayerTurn()); testInvalidPull(move); } @Test public void testOffBoard3() { - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(3, 0), new Coordinate(4, 0), - new Coordinate(3, -1), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(3, 0), new Coordinate(4, 0), new Coordinate(3, -1), + pullingGame.getPlayerTurn()); testInvalidPull(move); } @Test public void testCantSwap() { - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(5, 5), new Coordinate(5, 4), - new Coordinate(5, 4), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(5, 5), new Coordinate(5, 4), new Coordinate(5, 4), + pullingGame.getPlayerTurn()); testInvalidPull(move); } @Test public void testMustMove() { - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(5, 5), new Coordinate(5, 5), - new Coordinate(5, 6), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(5, 5), new Coordinate(5, 5), new Coordinate(5, 6), + pullingGame.getPlayerTurn()); testInvalidPull(move); } @Test public void testCantPullSelf() { - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(5, 5), new Coordinate(5, 4), - new Coordinate(5, 5), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(5, 5), new Coordinate(5, 4), new Coordinate(5, 5), + pullingGame.getPlayerTurn()); testInvalidPull(move); } @Test public void testDestinationMustBeAdjacent() { - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(4, 4), new Coordinate(5, 2), - new Coordinate(3, 4), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(4, 4), new Coordinate(5, 2), new Coordinate(3, 4), + pullingGame.getPlayerTurn()); testInvalidPull(move); } @Test public void testPulledPieceMustBeAdjacent() { - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(4, 4), new Coordinate(5, 4), - new Coordinate(3, 2), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(4, 4), new Coordinate(5, 4), new Coordinate(3, 2), + pullingGame.getPlayerTurn()); testInvalidPull(move); } @Test public void testNullPiece() { - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(7, 5), new Coordinate(7, 6), - new Coordinate(6, 5), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(7, 5), new Coordinate(7, 6), new Coordinate(6, 5), + pullingGame.getPlayerTurn()); testInvalidPull(move); } @Test public void testCantPullNothing() { - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(5, 3), new Coordinate(5, 4), - new Coordinate(4, 3), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(5, 3), new Coordinate(5, 4), new Coordinate(4, 3), + pullingGame.getPlayerTurn()); testInvalidPull(move); } @Test public void testCantPullIntoOccupiedSpace() { - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(2, 2), new Coordinate(2, 1), - new Coordinate(2, 3), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(2, 2), new Coordinate(2, 1), new Coordinate(2, 3), + pullingGame.getPlayerTurn()); testInvalidPull(move); } @Test public void testCantPullOnEnemyTurn() { - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(1, 6), new Coordinate(2, 6), - new Coordinate(0, 6), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(1, 6), new Coordinate(2, 6), new Coordinate(0, 6), + pullingGame.getPlayerTurn()); testInvalidPull(move); } @Test public void testCantPullOwnPiece() { - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(1, 2), new Coordinate(1, 3), - new Coordinate(2, 2), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(1, 2), new Coordinate(1, 3), new Coordinate(2, 2), + pullingGame.getPlayerTurn()); testInvalidPull(move); } @Test public void testCantPullPieceOfGreaterStrength() { - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(3, 7), new Coordinate(2, 7), - new Coordinate(4, 7), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(3, 7), new Coordinate(2, 7), new Coordinate(4, 7), + pullingGame.getPlayerTurn()); testInvalidPull(move); } @Test public void testCantPullIfFrozen() { - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(1, 5), new Coordinate(1, 4), - new Coordinate(2, 5), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(1, 5), new Coordinate(1, 4), new Coordinate(2, 5), + pullingGame.getPlayerTurn()); testInvalidPull(move); } @Test public void testCantPullWith1Move() { - assertTrue(pullingGame.move(new RegularMove(pullingGame.getBoardState(), new Coordinate(6, 0), - new Coordinate(5, 0), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()))); - assertTrue(pullingGame.move(new RegularMove(pullingGame.getBoardState(), new Coordinate(5, 0), - new Coordinate(6, 0), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()))); - assertTrue(pullingGame.move(new RegularMove(pullingGame.getBoardState(), new Coordinate(6, 0), - new Coordinate(5, 0), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()))); - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(5, 5), new Coordinate(5, 4), - new Coordinate(5, 4), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + assertTrue(pullingGame.move( + new RegularMove(pullingGame, new Coordinate(6, 0), new Coordinate(5, 0), pullingGame.getPlayerTurn()))); + assertTrue(pullingGame.move( + new RegularMove(pullingGame, new Coordinate(5, 0), new Coordinate(6, 0), pullingGame.getPlayerTurn()))); + assertTrue(pullingGame.move( + new RegularMove(pullingGame, new Coordinate(6, 0), new Coordinate(5, 0), pullingGame.getPlayerTurn()))); + MoveCommand move = new PullMove(pullingGame, new Coordinate(5, 5), new Coordinate(5, 4), new Coordinate(5, 4), + pullingGame.getPlayerTurn()); testInvalidPull(move); } } diff --git a/test/move_commands/TestPullValid.java b/test/move_commands/TestPullValid.java index e8f38ad..077485f 100644 --- a/test/move_commands/TestPullValid.java +++ b/test/move_commands/TestPullValid.java @@ -18,8 +18,8 @@ public class TestPullValid extends PullSetup { @Test public void testCanGetPullPiece() { Coordinate coor = new Coordinate(5, 6); - PullMove move = new PullMove(pullingGame.getBoardState(), new Coordinate(5, 5), new Coordinate(5, 4), coor, - pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + PullMove move = new PullMove(pullingGame, new Coordinate(5, 5), new Coordinate(5, 4), coor, + pullingGame.getPlayerTurn()); assertEquals(coor, move.getPullPiecePlace()); } @@ -33,16 +33,15 @@ public void testCanGetAffectedCoordinates() { map.add(new CoordinatePair(c1, c2)); map.add(new CoordinatePair(c3, c1)); - PullMove move = new PullMove(pullingGame.getBoardState(), c1, c2, c3, pullingGame.getPlayerTurn(), - pullingGame.getNumMoves()); + PullMove move = new PullMove(pullingGame, c1, c2, c3, pullingGame.getPlayerTurn()); assertEquals(map, move.getAffectedCoordinates()); } @Test public void testGetAffectedPiecesIsEmptyIfInvalid() { - PullMove move = new PullMove(pullingGame.getBoardState(), new Coordinate(1, 5), new Coordinate(5, 4), - new Coordinate(5, 6), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + PullMove move = new PullMove(pullingGame, new Coordinate(1, 5), new Coordinate(5, 4), new Coordinate(5, 6), + pullingGame.getPlayerTurn()); assertTrue(move.getAffectedCoordinates().isEmpty()); } @@ -52,8 +51,8 @@ public void testBasicPullUp() { AbstractPiece p1 = pullingGame.getPieceAt(new Coordinate(5, 5)); AbstractPiece p2 = pullingGame.getPieceAt(new Coordinate(5, 6)); - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(5, 5), new Coordinate(5, 4), - new Coordinate(5, 6), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(5, 5), new Coordinate(5, 4), new Coordinate(5, 6), + pullingGame.getPlayerTurn()); assertTrue(move.isValidMove()); assertTrue(pullingGame.move(move)); @@ -67,8 +66,8 @@ public void testBasicPullRight() { AbstractPiece p1 = pullingGame.getPieceAt(new Coordinate(4, 4)); AbstractPiece p2 = pullingGame.getPieceAt(new Coordinate(3, 4)); - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(4, 4), new Coordinate(5, 4), - new Coordinate(3, 4), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(4, 4), new Coordinate(5, 4), new Coordinate(3, 4), + pullingGame.getPlayerTurn()); assertTrue(move.isValidMove()); assertTrue(pullingGame.move(move)); @@ -82,8 +81,8 @@ public void testBasicPullDown() { AbstractPiece p1 = pullingGame.getPieceAt(new Coordinate(5, 3)); AbstractPiece p2 = pullingGame.getPieceAt(new Coordinate(5, 2)); - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(5, 3), new Coordinate(5, 4), - new Coordinate(5, 2), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(5, 3), new Coordinate(5, 4), new Coordinate(5, 2), + pullingGame.getPlayerTurn()); assertTrue(move.isValidMove()); assertTrue(pullingGame.move(move)); @@ -97,8 +96,8 @@ public void testBasicPullLeft() { AbstractPiece p1 = pullingGame.getPieceAt(new Coordinate(6, 4)); AbstractPiece p2 = pullingGame.getPieceAt(new Coordinate(7, 4)); - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(6, 4), new Coordinate(5, 4), - new Coordinate(7, 4), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(6, 4), new Coordinate(5, 4), new Coordinate(7, 4), + pullingGame.getPlayerTurn()); assertTrue(move.isValidMove()); assertTrue(pullingGame.move(move)); @@ -112,8 +111,8 @@ public void testBidirectionalPullUpRight() { AbstractPiece p1 = pullingGame.getPieceAt(new Coordinate(4, 4)); AbstractPiece p2 = pullingGame.getPieceAt(new Coordinate(3, 4)); - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(4, 4), new Coordinate(4, 3), - new Coordinate(3, 4), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(4, 4), new Coordinate(4, 3), new Coordinate(3, 4), + pullingGame.getPlayerTurn()); assertTrue(move.isValidMove()); assertTrue(pullingGame.move(move)); @@ -127,8 +126,8 @@ public void testBidirectionalPullRightDown() { AbstractPiece p1 = pullingGame.getPieceAt(new Coordinate(5, 3)); AbstractPiece p2 = pullingGame.getPieceAt(new Coordinate(5, 2)); - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(5, 3), new Coordinate(6, 3), - new Coordinate(5, 2), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(5, 3), new Coordinate(6, 3), new Coordinate(5, 2), + pullingGame.getPlayerTurn()); assertTrue(move.isValidMove()); assertTrue(pullingGame.move(move)); @@ -142,8 +141,8 @@ public void testBidirectionalPullDownLeft() { AbstractPiece p1 = pullingGame.getPieceAt(new Coordinate(6, 4)); AbstractPiece p2 = pullingGame.getPieceAt(new Coordinate(7, 4)); - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(6, 4), new Coordinate(6, 3), - new Coordinate(7, 4), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(6, 4), new Coordinate(6, 3), new Coordinate(7, 4), + pullingGame.getPlayerTurn()); assertTrue(move.isValidMove()); assertTrue(pullingGame.move(move)); @@ -157,8 +156,8 @@ public void testBidirectionalPullLeftUp() { AbstractPiece p1 = pullingGame.getPieceAt(new Coordinate(5, 5)); AbstractPiece p2 = pullingGame.getPieceAt(new Coordinate(5, 6)); - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(5, 5), new Coordinate(4, 5), - new Coordinate(5, 6), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(5, 5), new Coordinate(4, 5), new Coordinate(5, 6), + pullingGame.getPlayerTurn()); assertTrue(move.isValidMove()); assertTrue(pullingGame.move(move)); @@ -173,8 +172,8 @@ public void testCanPullIfFrozenButThawed() { AbstractPiece p1 = pullingGame.getPieceAt(new Coordinate(1, 5)); AbstractPiece p2 = pullingGame.getPieceAt(new Coordinate(2, 5)); - MoveCommand move = new PullMove(pullingGame.getBoardState(), new Coordinate(1, 5), new Coordinate(1, 4), - new Coordinate(2, 5), pullingGame.getPlayerTurn(), pullingGame.getNumMoves()); + MoveCommand move = new PullMove(pullingGame, new Coordinate(1, 5), new Coordinate(1, 4), new Coordinate(2, 5), + pullingGame.getPlayerTurn()); assertTrue(move.isValidMove()); assertTrue(pullingGame.move(move)); diff --git a/test/move_commands/TestPushInvalid.java b/test/move_commands/TestPushInvalid.java index 5b93df8..5710203 100644 --- a/test/move_commands/TestPushInvalid.java +++ b/test/move_commands/TestPushInvalid.java @@ -21,152 +21,152 @@ public void testInvalidPush(MoveCommand move) { @Test public void testExecutingAnInvalidPushReturnsTheOriginalBoard() { - MoveCommand move = new PushMove(g2.getBoardState(), new Coordinate(1, 1), new Coordinate(1, 0), - new Coordinate(1, -1), g2.getPlayerTurn(), g2.getNumMoves()); + MoveCommand move = new PushMove(g2, new Coordinate(1, 1), new Coordinate(1, 0), new Coordinate(1, -1), + g2.getPlayerTurn()); BoardState board = new BoardState(g2.getBoardState()); assertEquals(board, move.execute()); } @Test public void testOffBoard1() { - MoveCommand move = new PushMove(g2.getBoardState(), new Coordinate(-1, 6), new Coordinate(0, 6), - new Coordinate(1, 6), g2.getPlayerTurn(), g2.getNumMoves()); + MoveCommand move = new PushMove(g2, new Coordinate(-1, 6), new Coordinate(0, 6), new Coordinate(1, 6), + g2.getPlayerTurn()); testInvalidPush(move); } @Test public void testOffBoard2() { - MoveCommand move = new PushMove(g2.getBoardState(), new Coordinate(0, 7), new Coordinate(0, 8), - new Coordinate(0, 9), g2.getPlayerTurn(), g2.getNumMoves()); + MoveCommand move = new PushMove(g2, new Coordinate(0, 7), new Coordinate(0, 8), new Coordinate(0, 9), + g2.getPlayerTurn()); testInvalidPush(move); } @Test public void testOffBoard3() { - MoveCommand move = new PushMove(g2.getBoardState(), new Coordinate(1, 1), new Coordinate(1, 0), - new Coordinate(1, -1), g2.getPlayerTurn(), g2.getNumMoves()); + MoveCommand move = new PushMove(g2, new Coordinate(1, 1), new Coordinate(1, 0), new Coordinate(1, -1), + g2.getPlayerTurn()); testInvalidPush(move); } @Test public void testPushWithNullPiece() { - MoveCommand move = new PushMove(pushingGame.getBoardState(), new Coordinate(2, 7), new Coordinate(1, 7), - new Coordinate(1, 6), pushingGame.getPlayerTurn(), pushingGame.getNumMoves()); + MoveCommand move = new PushMove(pushingGame, new Coordinate(2, 7), new Coordinate(1, 7), new Coordinate(1, 6), + pushingGame.getPlayerTurn()); testInvalidPush(move); } @Test public void testCantPushToEmptySpace() { - MoveCommand move = new PushMove(pushingGame.getBoardState(), new Coordinate(4, 6), new Coordinate(5, 6), - new Coordinate(6, 6), pushingGame.getPlayerTurn(), pushingGame.getNumMoves()); + MoveCommand move = new PushMove(pushingGame, new Coordinate(4, 6), new Coordinate(5, 6), new Coordinate(6, 6), + pushingGame.getPlayerTurn()); testInvalidPush(move); } @Test public void testCantPushIntoOccupiedPiece() { - MoveCommand move = new PushMove(pushingGame.getBoardState(), new Coordinate(2, 6), new Coordinate(3, 6), - new Coordinate(4, 6), pushingGame.getPlayerTurn(), pushingGame.getNumMoves()); + MoveCommand move = new PushMove(pushingGame, new Coordinate(2, 6), new Coordinate(3, 6), new Coordinate(4, 6), + pushingGame.getPlayerTurn()); testInvalidPush(move); } @Test public void testCantSwap() { - MoveCommand move = new PushMove(pushingGame.getBoardState(), new Coordinate(5, 4), new Coordinate(6, 4), - new Coordinate(5, 4), pushingGame.getPlayerTurn(), pushingGame.getNumMoves()); + MoveCommand move = new PushMove(pushingGame, new Coordinate(5, 4), new Coordinate(6, 4), new Coordinate(5, 4), + pushingGame.getPlayerTurn()); testInvalidPush(move); } @Test public void testCantNotMove() { - MoveCommand move = new PushMove(pushingGame.getBoardState(), new Coordinate(2, 6), new Coordinate(2, 6), - new Coordinate(4, 6), pushingGame.getPlayerTurn(), pushingGame.getNumMoves()); + MoveCommand move = new PushMove(pushingGame, new Coordinate(2, 6), new Coordinate(2, 6), new Coordinate(4, 6), + pushingGame.getPlayerTurn()); testInvalidPush(move); } @Test public void testCantNotMoveOtherPiece() { - MoveCommand move = new PushMove(pushingGame.getBoardState(), new Coordinate(5, 4), new Coordinate(6, 4), - new Coordinate(6, 4), pushingGame.getPlayerTurn(), pushingGame.getNumMoves()); + MoveCommand move = new PushMove(pushingGame, new Coordinate(5, 4), new Coordinate(6, 4), new Coordinate(6, 4), + pushingGame.getPlayerTurn()); testInvalidPush(move); } @Test public void testMustBeToAdjacentCoordinate() { - MoveCommand move = new PushMove(pushingGame.getBoardState(), new Coordinate(5, 4), new Coordinate(0, 1), - new Coordinate(0, 2), pushingGame.getPlayerTurn(), pushingGame.getNumMoves()); + MoveCommand move = new PushMove(pushingGame, new Coordinate(5, 4), new Coordinate(0, 1), new Coordinate(0, 2), + pushingGame.getPlayerTurn()); testInvalidPush(move); } @Test public void testPieceMustBeAdjacent() { - MoveCommand move = new PushMove(pushingGame.getBoardState(), new Coordinate(5, 4), new Coordinate(4, 4), - new Coordinate(2, 7), pushingGame.getPlayerTurn(), pushingGame.getNumMoves()); + MoveCommand move = new PushMove(pushingGame, new Coordinate(5, 4), new Coordinate(4, 4), new Coordinate(2, 7), + pushingGame.getPlayerTurn()); testInvalidPush(move); } @Test public void testCantMoveEnemyPiece() { - MoveCommand move = new PushMove(pushingGame.getBoardState(), new Coordinate(7, 0), new Coordinate(6, 0), - new Coordinate(5, 0), pushingGame.getPlayerTurn(), pushingGame.getNumMoves()); + MoveCommand move = new PushMove(pushingGame, new Coordinate(7, 0), new Coordinate(6, 0), new Coordinate(5, 0), + pushingGame.getPlayerTurn()); testInvalidPush(move); } @Test public void testCantPushUpOwnPiece() { - MoveCommand move = new PushMove(pushingGame.getBoardState(), new Coordinate(2, 2), new Coordinate(2, 1), - new Coordinate(2, 0), pushingGame.getPlayerTurn(), pushingGame.getNumMoves()); + MoveCommand move = new PushMove(pushingGame, new Coordinate(2, 2), new Coordinate(2, 1), new Coordinate(2, 0), + pushingGame.getPlayerTurn()); testInvalidPush(move); } @Test public void testCantPushRightOwnPiece() { - MoveCommand move = new PushMove(pushingGame.getBoardState(), new Coordinate(2, 2), new Coordinate(3, 2), - new Coordinate(4, 2), pushingGame.getPlayerTurn(), pushingGame.getNumMoves()); + MoveCommand move = new PushMove(pushingGame, new Coordinate(2, 2), new Coordinate(3, 2), new Coordinate(4, 2), + pushingGame.getPlayerTurn()); testInvalidPush(move); } @Test public void testCantPushDownOwnPiece() { - MoveCommand move = new PushMove(pushingGame.getBoardState(), new Coordinate(2, 2), new Coordinate(2, 3), - new Coordinate(2, 4), pushingGame.getPlayerTurn(), pushingGame.getNumMoves()); + MoveCommand move = new PushMove(pushingGame, new Coordinate(2, 2), new Coordinate(2, 3), new Coordinate(2, 4), + pushingGame.getPlayerTurn()); testInvalidPush(move); } @Test public void testCantPushLeftOwnPiece() { - MoveCommand move = new PushMove(pushingGame.getBoardState(), new Coordinate(2, 2), new Coordinate(1, 2), - new Coordinate(0, 2), pushingGame.getPlayerTurn(), pushingGame.getNumMoves()); + MoveCommand move = new PushMove(pushingGame, new Coordinate(2, 2), new Coordinate(1, 2), new Coordinate(0, 2), + pushingGame.getPlayerTurn()); testInvalidPush(move); } @Test public void testThatPiecesMustBeStrongerToPush() { pushingGame.incrementTurn(); - MoveCommand move = new PushMove(pushingGame.getBoardState(), new Coordinate(3, 6), new Coordinate(3, 5), - new Coordinate(3, 4), pushingGame.getPlayerTurn(), pushingGame.getNumMoves()); + MoveCommand move = new PushMove(pushingGame, new Coordinate(3, 6), new Coordinate(3, 5), new Coordinate(3, 4), + pushingGame.getPlayerTurn()); testInvalidPush(move); } @Test public void testCantPushIfFrozen() { pushingGame.incrementTurn(); - MoveCommand move = new PushMove(pushingGame.getBoardState(), new Coordinate(5, 5), new Coordinate(6, 5), - new Coordinate(7, 5), pushingGame.getPlayerTurn(), pushingGame.getNumMoves()); + MoveCommand move = new PushMove(pushingGame, new Coordinate(5, 5), new Coordinate(6, 5), new Coordinate(7, 5), + pushingGame.getPlayerTurn()); testInvalidPush(move); } @Test public void testNotEnoughMoves() { - assertTrue(pushingGame.move(new RegularMove(pushingGame.getBoardState(), new Coordinate(7, 1), - new Coordinate(7, 2), pushingGame.getPlayerTurn(), pushingGame.getNumMoves()))); - assertTrue(pushingGame.move(new RegularMove(pushingGame.getBoardState(), new Coordinate(7, 2), - new Coordinate(7, 3), pushingGame.getPlayerTurn(), pushingGame.getNumMoves()))); - assertTrue(pushingGame.move(new RegularMove(pushingGame.getBoardState(), new Coordinate(7, 3), - new Coordinate(7, 4), pushingGame.getPlayerTurn(), pushingGame.getNumMoves()))); - - MoveCommand move = new PushMove(pushingGame.getBoardState(), new Coordinate(5, 4), new Coordinate(5, 3), - new Coordinate(5, 2), pushingGame.getPlayerTurn(), pushingGame.getNumMoves()); + assertTrue(pushingGame.move( + new RegularMove(pushingGame, new Coordinate(7, 1), new Coordinate(7, 2), pushingGame.getPlayerTurn()))); + assertTrue(pushingGame.move( + new RegularMove(pushingGame, new Coordinate(7, 2), new Coordinate(7, 3), pushingGame.getPlayerTurn()))); + assertTrue(pushingGame.move( + new RegularMove(pushingGame, new Coordinate(7, 3), new Coordinate(7, 4), pushingGame.getPlayerTurn()))); + + MoveCommand move = new PushMove(pushingGame, new Coordinate(5, 4), new Coordinate(5, 3), new Coordinate(5, 2), + pushingGame.getPlayerTurn()); testInvalidPush(move); } } diff --git a/test/move_commands/TestPushValid.java b/test/move_commands/TestPushValid.java index 6b33c02..098b39e 100644 --- a/test/move_commands/TestPushValid.java +++ b/test/move_commands/TestPushValid.java @@ -18,8 +18,7 @@ public class TestPushValid extends PushSetup { @Test public void testPushCanGetPushPiece() { Coordinate coor = new Coordinate(4, 2); - PushMove move = new PushMove(g2.getBoardState(), new Coordinate(4, 4), new Coordinate(4, 3), coor, - g2.getPlayerTurn(), g2.getNumMoves()); + PushMove move = new PushMove(g2, new Coordinate(4, 4), new Coordinate(4, 3), coor, g2.getPlayerTurn()); assertEquals(coor, move.getPushPiecePlace()); } @@ -33,15 +32,15 @@ public void testCanGetAffectedCoordinates() { map.add(new CoordinatePair(c2, c3)); map.add(new CoordinatePair(c1, c2)); - PushMove move = new PushMove(g2.getBoardState(), c1, c2, c3, g2.getPlayerTurn(), g2.getNumMoves()); + PushMove move = new PushMove(g2, c1, c2, c3, g2.getPlayerTurn()); assertEquals(map, move.getAffectedCoordinates()); } @Test public void testGetAffectedPiecesIsEmptyIfInvalid() { - PushMove move = new PushMove(g2.getBoardState(), new Coordinate(-1, 4), new Coordinate(4, 3), - new Coordinate(4, 2), g2.getPlayerTurn(), g2.getNumMoves()); + PushMove move = new PushMove(g2, new Coordinate(-1, 4), new Coordinate(4, 3), new Coordinate(4, 2), + g2.getPlayerTurn()); assertTrue(move.getAffectedCoordinates().isEmpty()); } @@ -51,8 +50,8 @@ public void testBasicPushUp() { AbstractPiece p1 = g2.getPieceAt(new Coordinate(4, 4)); AbstractPiece p2 = g2.getPieceAt(new Coordinate(4, 3)); - MoveCommand move = new PushMove(g2.getBoardState(), new Coordinate(4, 4), new Coordinate(4, 3), - new Coordinate(4, 2), g2.getPlayerTurn(), g2.getNumMoves()); + MoveCommand move = new PushMove(g2, new Coordinate(4, 4), new Coordinate(4, 3), new Coordinate(4, 2), + g2.getPlayerTurn()); assertTrue(move.isValidMove()); assertTrue(g2.move(move)); @@ -66,8 +65,8 @@ public void testBasicPushDown() { AbstractPiece p1 = g2.getPieceAt(new Coordinate(4, 4)); AbstractPiece p2 = g2.getPieceAt(new Coordinate(4, 5)); - MoveCommand move = new PushMove(g2.getBoardState(), new Coordinate(4, 4), new Coordinate(4, 5), - new Coordinate(4, 6), g2.getPlayerTurn(), g2.getNumMoves()); + MoveCommand move = new PushMove(g2, new Coordinate(4, 4), new Coordinate(4, 5), new Coordinate(4, 6), + g2.getPlayerTurn()); assertTrue(move.isValidMove()); assertTrue(g2.move(move)); @@ -81,8 +80,8 @@ public void testBasicPushRight() { AbstractPiece p1 = g2.getPieceAt(new Coordinate(4, 4)); AbstractPiece p2 = g2.getPieceAt(new Coordinate(5, 4)); - MoveCommand move = new PushMove(g2.getBoardState(), new Coordinate(4, 4), new Coordinate(5, 4), - new Coordinate(6, 4), g2.getPlayerTurn(), g2.getNumMoves()); + MoveCommand move = new PushMove(g2, new Coordinate(4, 4), new Coordinate(5, 4), new Coordinate(6, 4), + g2.getPlayerTurn()); assertTrue(move.isValidMove()); assertTrue(g2.move(move)); @@ -96,8 +95,8 @@ public void testBasicPushLeft() { AbstractPiece p1 = g2.getPieceAt(new Coordinate(6, 7)); AbstractPiece p2 = g2.getPieceAt(new Coordinate(5, 7)); - MoveCommand move = new PushMove(g2.getBoardState(), new Coordinate(6, 7), new Coordinate(5, 7), - new Coordinate(4, 7), g2.getPlayerTurn(), g2.getNumMoves()); + MoveCommand move = new PushMove(g2, new Coordinate(6, 7), new Coordinate(5, 7), new Coordinate(4, 7), + g2.getPlayerTurn()); assertTrue(move.isValidMove()); assertTrue(g2.move(move)); @@ -108,8 +107,8 @@ public void testBasicPushLeft() { @Test public void testPushWithDifferentDirections() { - MoveCommand move = new PushMove(pushingGame.getBoardState(), new Coordinate(5, 4), new Coordinate(6, 4), - new Coordinate(6, 3), pushingGame.getPlayerTurn(), pushingGame.getNumMoves()); + MoveCommand move = new PushMove(pushingGame, new Coordinate(5, 4), new Coordinate(6, 4), new Coordinate(6, 3), + pushingGame.getPlayerTurn()); assertTrue(move.isValidMove()); assertTrue(pushingGame.move(move)); @@ -125,8 +124,8 @@ public void testCanPushIfFrozenButThawed() { AbstractPiece p2 = pushingGame.getPieceAt(new Coordinate(6, 5)); pushingGame.getBoardState().movePiece(new Coordinate(4, 4), new Coordinate(4, 5)); - MoveCommand move = new PushMove(pushingGame.getBoardState(), new Coordinate(5, 5), new Coordinate(6, 5), - new Coordinate(7, 5), pushingGame.getPlayerTurn(), pushingGame.getNumMoves()); + MoveCommand move = new PushMove(pushingGame, new Coordinate(5, 5), new Coordinate(6, 5), new Coordinate(7, 5), + pushingGame.getPlayerTurn()); assertTrue(move.isValidMove()); assertTrue(pushingGame.move(move)); diff --git a/test/move_commands/TestRegularInvalid.java b/test/move_commands/TestRegularInvalid.java index d444037..52e6b0d 100644 --- a/test/move_commands/TestRegularInvalid.java +++ b/test/move_commands/TestRegularInvalid.java @@ -21,76 +21,68 @@ public void testInvalidMove(Game game, MoveCommand move) { @Test public void testExecutingAnInvalidMoveReturnsTheOriginalBoard() { - MoveCommand move = new RegularMove(g.getBoardState(), new Coordinate(0, 0), new Coordinate(0, -1), g.getPlayerTurn(), - g.getNumMoves()); + MoveCommand move = new RegularMove(g, new Coordinate(0, 0), new Coordinate(0, -1), g.getPlayerTurn()); BoardState board = new BoardState(g.getBoardState()); assertEquals(board, move.execute()); } - + @Test - public void testCantMoveWith0MovesLeft() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + public void testCantMoveWith0MovesLeft() + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { Field field = this.g.getClass().getDeclaredField("numMoves"); field.setAccessible(true); field.setInt(g, 0); - MoveCommand move = new RegularMove(this.g.getBoardState(), new Coordinate(0, 1), new Coordinate(0, 2), this.g.getPlayerTurn(), - this.g.getNumMoves()); + MoveCommand move = new RegularMove(this.g, new Coordinate(0, 1), new Coordinate(0, 2), this.g.getPlayerTurn()); testInvalidMove(this.g, move); } @Test public void testDestinationOffBoard() { - MoveCommand move = new RegularMove(g.getBoardState(), new Coordinate(0, 0), new Coordinate(0, -1), g.getPlayerTurn(), - g.getNumMoves()); + MoveCommand move = new RegularMove(g, new Coordinate(0, 0), new Coordinate(0, -1), g.getPlayerTurn()); testInvalidMove(g, move); } @Test public void testOffBoardPiece() { - MoveCommand move = new RegularMove(freezingGame.getBoardState(), new Coordinate(0, -1), new Coordinate(0, 0), - freezingGame.getPlayerTurn(), freezingGame.getNumMoves()); + MoveCommand move = new RegularMove(freezingGame, new Coordinate(0, -1), new Coordinate(0, 0), + freezingGame.getPlayerTurn()); testInvalidMove(freezingGame, move); } @Test public void testMustMoveToDifferentCoordinate() { - MoveCommand move = new RegularMove(g.getBoardState(), new Coordinate(0, 1), new Coordinate(0, 1), g.getPlayerTurn(), - g.getNumMoves()); + MoveCommand move = new RegularMove(g, new Coordinate(0, 1), new Coordinate(0, 1), g.getPlayerTurn()); testInvalidMove(g, move); } @Test public void testMustBeAdjacent() { - MoveCommand move = new RegularMove(g.getBoardState(), new Coordinate(0, 1), new Coordinate(0, 3), g.getPlayerTurn(), - g.getNumMoves()); + MoveCommand move = new RegularMove(g, new Coordinate(0, 1), new Coordinate(0, 3), g.getPlayerTurn()); testInvalidMove(g, move); } @Test public void testCantMoveNothing() { - MoveCommand move = new RegularMove(g.getBoardState(), new Coordinate(0, 2), new Coordinate(0, 3), g.getPlayerTurn(), - g.getNumMoves()); + MoveCommand move = new RegularMove(g, new Coordinate(0, 2), new Coordinate(0, 3), g.getPlayerTurn()); testInvalidMove(g, move); } @Test public void testCantMoveIntoOccupiedSpace() { - MoveCommand move = new RegularMove(g.getBoardState(), new Coordinate(1, 7), new Coordinate(1, 6), g.getPlayerTurn(), - g.getNumMoves()); + MoveCommand move = new RegularMove(g, new Coordinate(1, 7), new Coordinate(1, 6), g.getPlayerTurn()); testInvalidMove(g, move); } @Test public void testCantMoveEnemyPiece() { - MoveCommand move = new RegularMove(g.getBoardState(), new Coordinate(7, 6), new Coordinate(7, 5), g.getPlayerTurn(), - g.getNumMoves()); + MoveCommand move = new RegularMove(g, new Coordinate(7, 6), new Coordinate(7, 5), g.getPlayerTurn()); testInvalidMove(g, move); } @Test public void testRabbitCantMoveBackwards1() { g.getBoardState().movePiece(new Coordinate(0, 1), new Coordinate(0, 2)); - MoveCommand move = new RegularMove(g.getBoardState(), new Coordinate(0, 2), new Coordinate(0, 1), g.getPlayerTurn(), - g.getNumMoves()); + MoveCommand move = new RegularMove(g, new Coordinate(0, 2), new Coordinate(0, 1), g.getPlayerTurn()); testInvalidMove(g, move); } @@ -98,15 +90,14 @@ public void testRabbitCantMoveBackwards1() { public void testRabbitCantMoveBackwards2() { g.incrementTurn(); g.getBoardState().movePiece(new Coordinate(0, 6), new Coordinate(0, 5)); - MoveCommand move = new RegularMove(g.getBoardState(), new Coordinate(0, 5), new Coordinate(0, 6), g.getPlayerTurn(), - g.getNumMoves()); + MoveCommand move = new RegularMove(g, new Coordinate(0, 5), new Coordinate(0, 6), g.getPlayerTurn()); testInvalidMove(g, move); } @Test public void testCannotMoveIfFrozenByStrongerOpposingPiece() { - MoveCommand move = new RegularMove(freezingGame.getBoardState(), new Coordinate(3, 4), new Coordinate(2, 4), - freezingGame.getPlayerTurn(), freezingGame.getNumMoves()); + MoveCommand move = new RegularMove(freezingGame, new Coordinate(3, 4), new Coordinate(2, 4), + freezingGame.getPlayerTurn()); testInvalidMove(freezingGame, move); } } diff --git a/test/move_commands/TestRegularValid.java b/test/move_commands/TestRegularValid.java index 7146888..27d62e4 100644 --- a/test/move_commands/TestRegularValid.java +++ b/test/move_commands/TestRegularValid.java @@ -29,15 +29,14 @@ public void testCanGetAffectedCoordinates() { ArrayList map = new ArrayList(); map.add(new CoordinatePair(c1, c2)); - MoveCommand move = new RegularMove(g.getBoardState(), c1, c2, g.getPlayerTurn(), g.getNumMoves()); + MoveCommand move = new RegularMove(g, c1, c2, g.getPlayerTurn()); assertEquals(map, move.getAffectedCoordinates()); } @Test public void testGetAffectedCoordinatesIsEmptyIfInvalid() { - MoveCommand move = new RegularMove(g.getBoardState(), new Coordinate(-1, 6), new Coordinate(1, 5), - g.getPlayerTurn(), g.getNumMoves()); + MoveCommand move = new RegularMove(g, new Coordinate(-1, 6), new Coordinate(1, 5), g.getPlayerTurn()); assertTrue(move.getAffectedCoordinates().isEmpty()); } @@ -58,7 +57,7 @@ public void testMoveLegal() { Coordinate start = new Coordinate(7, 7); Coordinate end = new Coordinate(7, 6); Owner owner = g1.getPlayerTurn(); - MoveCommand move = new RegularMove(g1.getBoardState(), start, end, owner, g1.getNumMoves()); + MoveCommand move = new RegularMove(g1, start, end, owner); assertTrue(g1.move(move)); assertEquals(new Cat(Owner.Player1), g1.getPieceAt(new Coordinate(6, 7))); @@ -67,8 +66,7 @@ public void testMoveLegal() { @Test public void testRabbitCanMoveForwards1() { - MoveCommand move = new RegularMove(g.getBoardState(), new Coordinate(0, 1), new Coordinate(0, 2), - g.getPlayerTurn(), g.getNumMoves()); + MoveCommand move = new RegularMove(g, new Coordinate(0, 1), new Coordinate(0, 2), g.getPlayerTurn()); assertTrue(move.isValidMove()); assertTrue(g.move(move)); @@ -80,8 +78,7 @@ public void testRabbitCanMoveForwards1() { @Test public void testRabbitCanMoveForwards2() { g.incrementTurn(); - MoveCommand move = new RegularMove(g.getBoardState(), new Coordinate(0, 6), new Coordinate(0, 5), - g.getPlayerTurn(), g.getNumMoves()); + MoveCommand move = new RegularMove(g, new Coordinate(0, 6), new Coordinate(0, 5), g.getPlayerTurn()); assertTrue(move.isValidMove()); assertTrue(g.move(move)); @@ -92,8 +89,8 @@ public void testRabbitCanMoveForwards2() { @Test public void testCanMoveIfFrozenByStrongerOpposingPieceButThawedByFriendlyPiece() { - MoveCommand move = new RegularMove(freezingGame.getBoardState(), new Coordinate(4, 3), new Coordinate(3, 3), - freezingGame.getPlayerTurn(), freezingGame.getNumMoves()); + MoveCommand move = new RegularMove(freezingGame, new Coordinate(4, 3), new Coordinate(3, 3), + freezingGame.getPlayerTurn()); assertTrue(move.isValidMove()); assertTrue(freezingGame.move(move));