commit 26c8e9b7e25c4881e0ccc09e91bff7c464125e7a Author: Paul H
+ * 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