diff --git a/app/src/main/java/org/toop/app/game/ReversiGame.java b/app/src/main/java/org/toop/app/game/ReversiGame.java index a5aadd5..ec9a5e6 100644 --- a/app/src/main/java/org/toop/app/game/ReversiGame.java +++ b/app/src/main/java/org/toop/app/game/ReversiGame.java @@ -322,7 +322,6 @@ public final class ReversiGame { if (isLegalMove) { moves = game.getFlipsForPotentialMove( new Point(cellEntered%game.getColumnSize(),cellEntered/game.getRowSize()), - game.makeBoardAGrid(), game.getCurrentPlayer()); } canvas.drawHighlightDots(moves); diff --git a/game/src/main/java/org/toop/game/reversi/Reversi.java b/game/src/main/java/org/toop/game/reversi/Reversi.java index 92db367..6654e85 100644 --- a/game/src/main/java/org/toop/game/reversi/Reversi.java +++ b/game/src/main/java/org/toop/game/reversi/Reversi.java @@ -53,7 +53,7 @@ public final class Reversi extends TurnBasedGame { char currentPlayer = (this.getCurrentTurn()==0) ? 'B' : 'W'; Set adjCell = getAdjacentCells(boardGrid); for (Point point : adjCell){ - Move[] moves = getFlipsForPotentialMove(point,boardGrid,currentPlayer); + Move[] moves = getFlipsForPotentialMove(point,currentPlayer); int score = moves.length; if (score > 0){ legalMoves.add(new Move(point.x + point.y * this.getRowSize(), currentPlayer)); @@ -81,14 +81,14 @@ public final class Reversi extends TurnBasedGame { return possibleCells; } - public Move[] getFlipsForPotentialMove(Point point, char[][] boardGrid, char currentPlayer) { + public Move[] getFlipsForPotentialMove(Point point, char currentPlayer) { final ArrayList movesToFlip = new ArrayList<>(); for (int deltaColumn = -1; deltaColumn <= 1; deltaColumn++) { for (int deltaRow = -1; deltaRow <= 1; deltaRow++) { if (deltaColumn == 0 && deltaRow == 0){ continue; } - Move[] moves = getFlipsInDirection(point,boardGrid,currentPlayer,deltaColumn,deltaRow); + Move[] moves = getFlipsInDirection(point,makeBoardAGrid(),currentPlayer,deltaColumn,deltaRow); if (moves != null) { movesToFlip.addAll(Arrays.asList(moves)); } @@ -123,13 +123,14 @@ public final class Reversi extends TurnBasedGame { return x >= 0 && x < this.getColumnSize() && y >= 0 && y < this.getRowSize(); } - public char[][] makeBoardAGrid() { + private char[][] makeBoardAGrid() { char[][] boardGrid = new char[this.getRowSize()][this.getColumnSize()]; for (int i = 0; i < 64; i++) { boardGrid[i / this.getRowSize()][i % this.getColumnSize()] = this.getBoard()[i]; //boardGrid[y / row] [x / column] } return boardGrid; } + @Override public GameState play(Move move) { Move[] legalMoves = getLegalMoves(); @@ -141,7 +142,7 @@ public final class Reversi extends TurnBasedGame { } } if (moveIsLegal) { - Move[] moves = sortMovesFromCenter(getFlipsForPotentialMove(new Point(move.position()%this.getColumnSize(),move.position()/this.getRowSize()), makeBoardAGrid(), move.value()),move); + Move[] moves = sortMovesFromCenter(getFlipsForPotentialMove(new Point(move.position()%this.getColumnSize(),move.position()/this.getRowSize()), move.value()),move); mostRecentlyFlippedPieces = moves; this.setBoard(move); for (Move m : moves) { @@ -169,9 +170,9 @@ public final class Reversi extends TurnBasedGame { return null; } - public void skipMyTurn(){ + private void skipMyTurn(){ IO.println("TURN " + getCurrentPlayer() + " SKIPPED"); - //todo notify user that a turn has been skipped + //TODO: notify user that a turn has been skipped nextTurn(); } diff --git a/game/src/test/java/org/toop/game/tictactoe/ReversiTest.java b/game/src/test/java/org/toop/game/tictactoe/ReversiTest.java index c1b2b10..f2586a5 100644 --- a/game/src/test/java/org/toop/game/tictactoe/ReversiTest.java +++ b/game/src/test/java/org/toop/game/tictactoe/ReversiTest.java @@ -113,11 +113,11 @@ class ReversiTest { Reversi.Score score = game.getScore(); IO.println(score.player1Score()); IO.println(score.player2Score()); - char[][] grid = game.makeBoardAGrid(); - for (char[] chars : grid) { - IO.println(Arrays.toString(chars)); - } + for (int r = 0; r < game.getRowSize(); r++) { + char[] row = Arrays.copyOfRange(game.getBoard(), r * game.getColumnSize(), (r + 1) * game.getColumnSize()); + IO.println(Arrays.toString(row)); + } } }