Work in pairs to extend a Python chess game. Have your coding agents implement features and
tests on separate branches, then integrate other contributions into main. You decide the
expected behavior and check that the combined game works.
What you produce: the extended chess game, its tests, and an agent’s review of them, uploaded to Moodle. Most of the session is one continuous work block. Work through the activities in order; you are not expected to finish every extension.
Your partner must be new. Pair up with someone you did not work with in any earlier lab (Labs 1 to 4). The lab instructor checks every pair at the start, and a repeat partner costs each of you 1 point.
Never sit idle while an agent works. Open another window and work with another agent: start the next feature on its own branch, or review and test a branch that is done.
The game is incomplete. Check, checkmate, and stalemate are implemented. Stalemate already ends the game in a tie; other conditions for a tie are still missing. Castling and en passant are also missing. Later you add promotion: when a pawn reaches the last row, its player can change it into a queen or another piece. If you’re unfamiliar with chess, ask your agent to explain the rules or open the short guide below.
Chess rules: a quick guide
- Playing: White moves first, then players take turns. Select a piece in the game to see its legal destinations. Usually, landing on an opponent’s piece captures it.
- Check: your king is under attack; your next move must remove that threat.
- Checkmate: your king is in check and no legal move can remove the threat. You lose.
- Stalemate (already implemented): you have no legal move, but your king is not in check. The game ends in a tie.
- Promotion: a pawn reaching the last row becomes a queen, rook, bishop, or knight, chosen by its player.
- Castling: a special move involving the king and a rook, allowed only under certain conditions. It is not implemented here.
- En passant: a pawn can capture an adjacent enemy pawn that just advanced two squares, as if it had moved only one square. This is allowed only on the immediately following move. It is not implemented here.
For piece movement and illustrated examples, see Chess.com’s beginner rules guide.
Before the lab
Each of you, on your own laptop: clone the
chess starter repository, set it up, and run
the game and its tests once. Arrive with both working, so the session starts with the code.
Keep the repository’s feature/captured-pieces and feature/promotion branches. Your lab
instructor checks your setup at the start of the lab; it is worth 1 point.
How to set up and run
Clone the repository and open its folder:
git clone https://github.com/avivz/aicode-lab05-chess.git
cd aicode-lab05-chess
Ask your agent to create a virtual environment named .venv and install
requirements-dev.txt in it. Activate it in each terminal you use for the game or tests:
source .venv/bin/activate
Start the server:
python3 server.py
Open http://127.0.0.1:8000. Have your agent run the tests in another terminal:
python -m pytest
Phase 1 — Get started
Share a repository. Your clone’s origin is the course repository, which you cannot push
to. One of you creates a private GitHub repository for the pair and adds the other as a
collaborator. Both of you add it to your clones as a second remote, team, and exchange your
branches through it. Keep origin: the supplied feature/ branches stay under origin/.
Check that each of you can push a branch and fetch the other’s.
How to share the repository
One of you (replace YOU and PARTNER with your GitHub user names):
gh repo create aicode-lab05-chess --private
git remote add team https://github.com/YOU/aicode-lab05-chess.git
git push -u team main
gh api -X PUT repos/YOU/aicode-lab05-chess/collaborators/PARTNER
The other accepts the invitation at https://github.com/YOU/aicode-lab05-chess/invitations, then:
git remote add team https://github.com/YOU/aicode-lab05-chess.git
git fetch team
From then on, git push -u team <branch> shares a branch and git fetch team gets your
partner’s.
Locate the board, turn, and move history. Decide what undo should do against the computer, and note your decision.
Look at how the project is checked, too: what does it run, and what is missing? Decide which of this week’s checks you want in place before you build the features.
Phase 2 — Build and test
Use this as one large work block, at your own pace:
Implement and merge features
- Implement these two features separately, on branches from the same starter commit: one partner adds save and load, with controls to save a game to a file and resume it later; the other adds undo, with a control that lets the player reverse the last move. Agree on shared game information. Each branch must include its own tests for the feature it adds. Have your agent write and run those tests before merging, then review the changes and results.
- Merge both features into
mainand try them together. Run your tests and play the game. Have your agents add checks for combined behavior that your separate tests do not cover. - Integrate the supplied branches into
main, one at a time: firstfeature/captured-pieces, which displays captured pieces, thenfeature/promotion, which lets the player choose a new piece when a pawn reaches the far rank. After each merge, run the existing tests and try the combined game before asking your agent to repair anything. Investigate anything unexpected, have your agent add a test that reproduces it, and fix it together. Alternate who operates the agent. After each merge, ask yourself: do the tests cover the features working together? Check the results before fixing failures. Read the relevant assertions and changes. Keep the tests and rerun them as you continue. If everything works immediately, show which check establishes that.
Save/load and undo requirements
- Save/load: add controls to save to a file and load in a fresh instance. Preserve the board, turn, move notation, opponent mode, and history needed to undo earlier moves.
- Undo: add a control that reverses a move, restores any captured piece, and updates the turn and notation. Repeated undo reaches the start; undo there does nothing. Against the computer, it follows your agreed behavior.
Supplied features: behavior and branch names
Merge feature/captured-pieces, then feature/promotion (possibly under origin/ in a clone).
- Captured pieces: the display lists pieces actually captured in the current game.
- Promotion: a pawn reaching the last row on the opposite side becomes a queen, rook, bishop, or knight, chosen by its player.
To try promotion, start a new two-player game and follow the moves below. Each square has a letter for its column and a number for its row, shown along the board’s edges: a2 means column a, row 2. Click the piece, then its destination square.
Take turns moving the same white and black pawns:
| Turn | White’s move | Black’s move |
|---|---|---|
| 1 | Move the pawn from a2 to a4. | Move the pawn from h7 to h5. |
| 2 | Move it from a4 to a5. | Move it from h5 to h4. |
| 3 | Move it from a5 to a6. | Move it from h4 to h3. |
| 4 | Move it diagonally from a6 to b7, capturing a black pawn. | Move it diagonally from h3 to g2, capturing a white pawn. |
| 5 | Move it diagonally from b7 to a8, capturing the black rook. | Stop here. |
The white pawn has reached the opposite end of the board. Choose which piece it becomes when the game asks—for example, a queen. This is promotion.
Checking tools
Have your agent run ruff check, ruff format --check, and mypy --strict, then run the
tests and produce a test coverage report. Read the commands, results, and useful findings
before making changes.
The coverage report shows which parts of the code ran during the tests. Does it cover everything? Discuss the gaps with your agent, including behavior the tests might not check even when the code runs.
For a repaired failure, run the tools at its first failing revision in a scratch worktree. Does a finding explain its cause?
Add redo together
Add redo together: a control that restores the move the player just undid. Decide the expected outcomes before implementing redo with your undo mechanism:
- Undo → redo restores a capture or promotion, including the chosen piece and display.
- Undo → save → load → redo works: preserve the redo continuation in the save file.
- Undo → play a different move discards the old redo continuation.
- Against the computer, agree on which moves redo restores and whether its reply may change.
- A new game clears both undo and redo history.
Implement additional features if you have time. Each partner adds a feature on a separate branch, with its own tests, then merge and test them together.
Feature ideas
Try adding an automatic tie when only the two kings remain, since neither can checkmate the other. This condition is not yet detected; stalemate is already handled. Other ideas: a new piece pawns can promote to, a randomly arranged starting row of pieces, or a limit of three undos per player. You can invent another rule.
Identify affected features and what must be saved or restored. Have your agents add checks for your expected outcomes and test both rules after merging.
Phase 3 — Review, discuss, submit (last 20 minutes)
- Start the review. Commit your work on
main. Download the review skill,SKILL.md, into.claude/skills/lab05-review/in your repository, without committing it. Start a fresh agent session and run/lab05-review. In Codex, ask the agent to read the file and follow it. In a few minutes it runs your checks, skims your code, tests and history, and writeslab05-review.md. It changes nothing else. - Discuss while it runs. Your lab instructor leads the discussion:
- Which of the week’s practices did you use: tests for each feature and for features together, linting, formatting, type checking, check commands in an instruction file? Which did your agent do without being asked?
- What did you skip, and why?
- Where should you do better next time?
- Compare and submit. Read the review. Does it agree with what you said? It is a model’s
judgment, so check one of its claims against the code. Each of you uploads
lab05-review.mdto Lab 5 report on Moodle before the session ends, even though the file is the same.
How you’re graded
Setup prepared at home, working when the lab starts: 1 point. Game and tests: 2 points. Review uploaded before the session ends: 1 point. A late upload loses it. Max grade: 4 of 4 points.
Late for the lab (over 10 minutes): -1 point Partner from an earlier lab: -1 point
Not graded: the review’s verdicts, appearance, number of tests, how many extensions you reach, or whether the agent made a mistake on its first attempt.