From 0707f2d628646fbdec651013404926d9724e2cec Mon Sep 17 00:00:00 2001 From: Nick Stolbov Date: Sun, 30 Jan 2022 01:45:05 +0100 Subject: [PATCH] Added getOutput method and helper method getCellSymbols with test --- src/main/java/Game/ChessObj/ChessBoard.java | 52 +++++++++++++++++++ .../java/Game/ChessObj/ChessBoardTest.java | 15 ++++++ 2 files changed, 67 insertions(+) diff --git a/src/main/java/Game/ChessObj/ChessBoard.java b/src/main/java/Game/ChessObj/ChessBoard.java index 0b327c7..0099da5 100644 --- a/src/main/java/Game/ChessObj/ChessBoard.java +++ b/src/main/java/Game/ChessObj/ChessBoard.java @@ -1,5 +1,7 @@ package Game.ChessObj; +import java.util.ArrayList; + public class ChessBoard { private ChessFigure[][] board; @@ -24,6 +26,56 @@ public class ChessBoard { } } + /* + a b c d e f g h + ┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐ + 1 │ |T| │ |Z| │ |I| │ |Q| │ |K| │ |I| │ |Z| │ |T| │ + ├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ + 2 │ |o| │ |o| │ |o| │ |o| │ |o| │ |o| │ |o| │ |o| │ + ├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ + 3 │ │ │ │ │ │ │ │ │ + ├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ + 4 │ │ │ │ │ │ │ │ │ + ├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ + 5 │ │ │ │ │ │ │ │ │ + ├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ + 6 │ │ │ │ │ │ │ │ │ + ├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ + 7 │ o │ o │ o │ o │ o │ o │ o │ o │ + ├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤ + 8 │ T │ Z │ I │ Q │ K │ I │ Z │ T │ + └─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘ + */ + + public ArrayList getOutputBoard() { + ArrayList outputBoard = new ArrayList<>(); + String[][] cellSymbol = getCellSymbols(); + outputBoard.add(" a b c d e f g h"); + outputBoard.add(" ┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐"); + for (int y = 0; y < board.length; y++) { + String line = ""; + line += " " + (y + 1) + " │ "; + for (int x = 0; x < board[0].length; x++) { + line += (cellSymbol[y][x] + " │ "); + } + outputBoard.add(line); + if (y < 7) + outputBoard.add(" ├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤"); + } + outputBoard.add(" └─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘"); + return outputBoard; + } + + public String[][] getCellSymbols() { + String[][] cellSymbol = new String[8][8]; + for (int y = 0; y < board.length; y++) { + for (int x = 0; x < board[0].length; x++) { + cellSymbol[y][x] = (board[y][x] == null)?" ": board[y][x].getSymbol(); + } + } + return cellSymbol; + } + public ChessFigure[][] getBoard() { return this.board; } diff --git a/src/test/java/Game/ChessObj/ChessBoardTest.java b/src/test/java/Game/ChessObj/ChessBoardTest.java index 8c90997..d39bb27 100644 --- a/src/test/java/Game/ChessObj/ChessBoardTest.java +++ b/src/test/java/Game/ChessObj/ChessBoardTest.java @@ -51,4 +51,19 @@ class ChessBoardTest { } } } + + @Test + void getCellSymbols() { + String[][] expectedArray = { + {"|T|","|Z|","|I|","|Q|","|K|","|I|","|Z|","|T|"}, + {"|o|","|o|","|o|","|o|","|o|","|o|","|o|","|o|"}, + {" "," "," "," "," "," "," "," "}, + {" "," "," "," "," "," "," "," "}, + {" "," "," "," "," "," "," "," "}, + {" "," "," "," "," "," "," "," "}, + {" o "," o "," o "," o "," o "," o "," o "," o "}, + {" T "," Z "," I "," Q "," K "," I "," Z "," T "} + }; + assertArrayEquals(expectedArray, chessBoard.getCellSymbols()); + } } \ No newline at end of file