CSE Roadmap

Common tier · about 5 hours · 6 parts

Part 6 of 6 · 3 min read

Exercises

Easy

Easy 1: Draw the line (20 minutes)

Write seven numbered requirements for a core chess game, and list five rules you are leaving out.

Done when: seven rules and five exclusions exist, and each exclusion has a one-line plan.

Hint

Put the exclusions in a table with the reason and the idea.

Easy 2: Run the mate (20 minutes)

Type the code and play the scholar's mate sequence.

Done when: the last move prints CHECKMATE and the next move says "game over".

Hint

Use the play helper that takes "from-to" strings.

Easy 3: Move by hand (20 minutes)

On an empty board with a white rook on d4, list the squares it can reach, and then the squares if a white pawn is on d6 and a black pawn is on f4.

Done when: two lists are written, and the black pawn square is in the second list and the white pawn square is not.

Hint

A rook slides until it meets a piece, and may land on an enemy piece.

Medium

Medium 1: Per-piece tests (45 minutes)

Write tests for each piece's movement on a board that you set up with a method place(String square, Piece p).

Done when: at least three tests per piece pass, including a blocked path for each sliding piece.

Hint

A helper that clears the board lets each test set up its own position.

Medium 2: Text board (45 minutes)

Write BoardView that prints the board with letters, upper case for white and lower case for black.

Done when: the starting position prints eight clear rows, and Board has no print code.

Hint

piece.symbol() and the colour decide the letter case.

Medium 3: Move history and undo (45 minutes)

Record each move with its captured piece, and add undo().

Done when: after three moves and a capture, three undos restore the starting position exactly.

Hint

Save the moved piece and the captured piece for each move.

Hard

Hard 1: Castling (90 minutes)

Add castling on both sides for both colours. Check the three conditions: neither piece has moved, the squares between are empty, and the king does not pass through or into check.

Done when: four tests pass for the allowed cases, and four tests refuse the illegal ones.

Hint

Castling moves two pieces, so it is a special case in Game.

Hard 2: En passant (90 minutes)

Add en passant, with a record of the last move. Test the capture and a refusal one move late.

Done when: the capture removes the passed pawn, and the same capture one move later is refused.

Hint

En passant is only available on the move straight after the double step.

Hard 3: A first bot (90 minutes)

Write a MoveSource that lists every legal move and picks the one that captures the most valuable piece, or the first when none captures.

Done when: the bot plays 50 moves of a game against itself without an illegal move, and a test shows it taking a free queen.

Hint

Piece values of 1, 3, 3, 5 and 9 are a start (made up).