From 26c8e9b7e25c4881e0ccc09e91bff7c464125e7a Mon Sep 17 00:00:00 2001 From: Paul H Date: Sat, 15 Feb 2025 15:07:13 +0100 Subject: [PATCH] Init --- .gitignore | 38 ++++++ .idea/encodings.xml | 9 ++ .idea/misc.xml | 13 ++ .idea/uiDesigner.xml | 124 ++++++++++++++++++ .idea/vcs.xml | 6 + .idea/workspace.xml | 90 +++++++++++++ chess/example-output.txt | 49 +++++++ chess/pom.xml | 20 +++ chess/src/main/java/de/vivi/chess/Main.java | 12 ++ .../main/java/de/vivi/chess/board/Board.java | 85 ++++++++++++ .../main/java/de/vivi/chess/board/Field.java | 43 ++++++ .../main/java/de/vivi/chess/game/Game.java | 29 ++++ .../main/java/de/vivi/chess/pieces/Color.java | 7 + .../main/java/de/vivi/chess/pieces/Piece.java | 39 ++++++ .../main/java/de/vivi/chess/pieces/Type.java | 17 +++ chess/todo.txt | 5 + 16 files changed, 586 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 chess/example-output.txt create mode 100644 chess/pom.xml create mode 100644 chess/src/main/java/de/vivi/chess/Main.java create mode 100644 chess/src/main/java/de/vivi/chess/board/Board.java create mode 100644 chess/src/main/java/de/vivi/chess/board/Field.java create mode 100644 chess/src/main/java/de/vivi/chess/game/Game.java create mode 100644 chess/src/main/java/de/vivi/chess/pieces/Color.java create mode 100644 chess/src/main/java/de/vivi/chess/pieces/Piece.java create mode 100644 chess/src/main/java/de/vivi/chess/pieces/Type.java create mode 100644 chess/todo.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..b32a862 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..2d293e9 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..194ad84 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1739621092112 + + + + \ No newline at end of file diff --git a/chess/example-output.txt b/chess/example-output.txt new file mode 100644 index 0000000..6ce9049 --- /dev/null +++ b/chess/example-output.txt @@ -0,0 +1,49 @@ +Welcome to Vivi's Chess Game! + + A B C D E F G H +1 ■ □ ■ □ ■ □ ■ □ +2 □ ■ □ ■ □ ■ □ ■ +3 ■ □ ■ □ ■ □ ■ □ +4 □ ■ □ ■ □ ■ □ ■ +5 ■ □ ■ □ ■ □ ■ □ +6 □ ■ □ ■ □ ■ □ ■ +7 ■ □ ■ □ ■ □ ■ □ +8 □ ■ □ ■ □ ■ □ ■ + +It is white's turn: [from:to] +A7:A5 <-- user input +Moving white 'Pawn' from A7 to A5 + + A B C D E F G H +1 ■ □ ■ □ ■ □ ■ □ +2 □ ■ □ ■ □ ■ □ ■ +3 ■ □ ■ □ ■ □ ■ □ +4 □ ■ □ ■ □ ■ □ ■ +5 ■ □ ■ □ ■ □ ■ □ +6 □ ■ □ ■ □ ■ □ ■ +7 ■ □ ■ □ ■ □ ■ □ +8 □ ■ □ ■ □ ■ □ ■ + +It is black's turn: [from:to] +D2:D3 +Moving black 'Pawn' from D2 to D3 + + A B C D E F G H +1 ■ □ ■ □ ■ □ ■ □ +2 □ ■ □ ■ □ ■ □ ■ +3 ■ □ ■ □ ■ □ ■ □ +4 □ ■ □ ■ □ ■ □ ■ +5 ■ □ ■ □ ■ □ ■ □ +6 □ ■ □ ■ □ ■ □ ■ +7 ■ □ ■ □ ■ □ ■ □ +8 □ ■ □ ■ □ ■ □ ■ + +It is white's turn: [from:to] +B2:B3 +Illegal move, try again: [from:to] +A8:A1 +Illegal move, try again: [from:to] +Hello World! +Illegal input, try again: [from:to] +Z6:X9 +Illegal input, try again: [from:to] \ No newline at end of file diff --git a/chess/pom.xml b/chess/pom.xml new file mode 100644 index 0000000..7cf8220 --- /dev/null +++ b/chess/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + org.example + vivi-certificate + 1.0-SNAPSHOT + + + chess + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/chess/src/main/java/de/vivi/chess/Main.java b/chess/src/main/java/de/vivi/chess/Main.java new file mode 100644 index 0000000..8d2fb91 --- /dev/null +++ b/chess/src/main/java/de/vivi/chess/Main.java @@ -0,0 +1,12 @@ +package de.vivi.chess; + +import de.vivi.chess.board.Board; +import de.vivi.chess.game.Game; + +public class Main { + + public static void main(String[] args) { + Game game = new Game(); + game.play(); + } +} diff --git a/chess/src/main/java/de/vivi/chess/board/Board.java b/chess/src/main/java/de/vivi/chess/board/Board.java new file mode 100644 index 0000000..7c7b246 --- /dev/null +++ b/chess/src/main/java/de/vivi/chess/board/Board.java @@ -0,0 +1,85 @@ +package de.vivi.chess.board; + +import de.vivi.chess.pieces.Piece; + +public class Board { + + private static final int SIZE = 8; + + private final Piece[/* column */][/* row */] grid; + + public Board() { + grid = new Piece[SIZE][SIZE]; + setup(); + } + + /** + * TODO: implement + *

+ * This method should setup the board like it is common + * for a chess game. Black is in the top two rows, white + * in the bottom two rows. "White queen, white field, black + * queen, black field". + */ + private void setup() { + + } + + /** + * TODO: implement + *

+ * Moves the piece at the from field to the to field. + * Doesn't check for validity, this has to be done somewhere + * else. If a piece is already at the to field, this piece is + * just getting replaced. + */ + public void move(Field from, Field to) { + + } + + /** + * TODO: implement + *

+ * Returns the piece at the given field. If no piece is + * present it just returns null. + */ + public Piece getPiece(Field field) { + return null; + } + + @Override + public String toString() { + StringBuilder result = new StringBuilder(); + boolean whiteField = true; + + result.append(" "); + + for (int column = 0; column < SIZE; column++) { + result.append((char) ('A' + column)).append(' '); + } + + result.append('\n'); + + for (int row = 0; row < SIZE; row++) { + result.append((char) ('1' + (char) row)).append(' '); + + for (int column = 0; column < SIZE; column++) { + Piece piece = grid[column][row]; + + if (piece == null) { + result.append(whiteField ? '\u25a0' : '\u25a1'); + } else { + result.append(piece.getSymbol()); + } + + result.append(' '); + whiteField = !whiteField; + } + + result.append('\n'); + whiteField = !whiteField; + } + + return result.toString(); + } +} diff --git a/chess/src/main/java/de/vivi/chess/board/Field.java b/chess/src/main/java/de/vivi/chess/board/Field.java new file mode 100644 index 0000000..735b06b --- /dev/null +++ b/chess/src/main/java/de/vivi/chess/board/Field.java @@ -0,0 +1,43 @@ +package de.vivi.chess.board; + +/** + * TODO: implement fields and constructor + *

+ * This class contains information to identify a single field + * on the board by its column and row. + */ +public class Field { + + /** + * TODO: implement + *

+ * Returns a new field that represents the field at the + * column and row indices. + */ + public static Field from(int column, int row) { + return null; + } + + /** + * TODO: implement + *

+ * Returns a new field that represents the field represented + * by the provided string (like "A5", "E7", ...). If the string + * is not valid, because it is garbage (like "hello", "world", ...) + * or the indices are out of bounds (like "K3", "B9", ...") + * it should throw an IllegalArgument exception. + */ + public static Field fromString(String value) throws IllegalArgumentException { + return null; + } + + public int getColumn() { + // TODO: implement + return -1; + } + + public int getRow() { + // TODO: implement + return -1; + } +} diff --git a/chess/src/main/java/de/vivi/chess/game/Game.java b/chess/src/main/java/de/vivi/chess/game/Game.java new file mode 100644 index 0000000..be43c30 --- /dev/null +++ b/chess/src/main/java/de/vivi/chess/game/Game.java @@ -0,0 +1,29 @@ +package de.vivi.chess.game; + +import de.vivi.chess.board.Board; +import de.vivi.chess.pieces.Color; + +public class Game { + + private final Board board; + + private Color player; + + /** + * TODO: implement + */ + public Game() { + board = null; + player = null; + } + + /** + * TODO: implement + *

+ * Starts the game and should process the game like it is + * specified inside example-output.txt. + */ + public void play() { + + } +} diff --git a/chess/src/main/java/de/vivi/chess/pieces/Color.java b/chess/src/main/java/de/vivi/chess/pieces/Color.java new file mode 100644 index 0000000..6ff2949 --- /dev/null +++ b/chess/src/main/java/de/vivi/chess/pieces/Color.java @@ -0,0 +1,7 @@ +package de.vivi.chess.pieces; + +/** + * TODO: add colors (white and black) + */ +public enum Color { +} diff --git a/chess/src/main/java/de/vivi/chess/pieces/Piece.java b/chess/src/main/java/de/vivi/chess/pieces/Piece.java new file mode 100644 index 0000000..a685db8 --- /dev/null +++ b/chess/src/main/java/de/vivi/chess/pieces/Piece.java @@ -0,0 +1,39 @@ +package de.vivi.chess.pieces; + +import de.vivi.chess.board.Board; +import de.vivi.chess.board.Field; + +public abstract class Piece { + + /** + * TODO: implement + *

+ * This method needs to be implemented in each piece by + * using inheritance. It returns true if the move from the + * from field to the to field is considered a valid move + * for the type of piece this method is called on. Otherwise + * it returns false. + */ + public abstract boolean isValidMove(Board board, Field from, Field to); + + public Color getColor() { + // TODO: implement + return null; + } + + public Type getType() { + // TODO: implement + return null; + } + + /** + * TODO: implement + *

+ * Use unicode symbols for the chess pieces. You can find + * them here: + * Unicode chess pieces + */ + public char getSymbol() { + return 0; + } +} diff --git a/chess/src/main/java/de/vivi/chess/pieces/Type.java b/chess/src/main/java/de/vivi/chess/pieces/Type.java new file mode 100644 index 0000000..adeef34 --- /dev/null +++ b/chess/src/main/java/de/vivi/chess/pieces/Type.java @@ -0,0 +1,17 @@ +package de.vivi.chess.pieces; + +/** + * TODO: add types + *

+ * This enum should contain all chess piece types. + * The types are: + * + * - king (König) + * - queen (Dame) + * - bishop (Läufer) + * - knight (Springer/Pferd) + * - rook (Turm) + * - pawn (Bauer) + */ +public enum Type { +} diff --git a/chess/todo.txt b/chess/todo.txt new file mode 100644 index 0000000..b62e0bb --- /dev/null +++ b/chess/todo.txt @@ -0,0 +1,5 @@ +Everything you need to do is marked with a TODO comment + +Additionally, create a chess piece class that extends Piece for every type of chess piece. +For example Pawn.java, King.java, ... +For this you can also look into Type.java \ No newline at end of file