Why?
Recently while doing some Xmas shopping i game across the board game Catan it fitted into an idea i have had for a while about a game along these lines.
I Also wanted to see if i could build a game with the help of AI without coding a single thing myself.
After 26 Iterations i present you with
https://github.com/herepete/games/blob/main/catan.py
You will only need to install 1 package
pip3.11 install PrettyTable
It might not be fully finished but it was a fun experiment playing with AI.
I found the default chatgbt model of GPT-4o pretty good for the initial setup but when the script got more complicated to 200 ish lines plus it started struggling in the terms of removing core features without being asked.
It did get quite frustrating and then i tried chatgbt o1 model and it has worked really well. It made the occasional error between iterations but it was helpfull.
AI Guard Rails
I found giving these instructions helped giving the AI some guard rails…
Version Incrementing:
Each new full version of the code should have its version number incremented on the second line. For example, after # Version 1.13
, the next full version you provide should be # Version 1.14
, then # Version 1.15
, and so forth.
Full Code with Each Update:
Whenever you request changes, I should provide the complete updated script—not just a snippet—so you have a full, up-to-date version of the code at each iteration.
Preserve Existing Code Unless Necessary:
Do not remove or rewrite large sections of code unless it’s required to implement the requested changes. Keep as much of the original logic and structure as possible, only adjusting or adding code where needed.
Implement Requested Features/Modifications Incrementally:
Each time you requested changes—like adding a 4th AI player, explaining aspects of the game, improving the trading logic, or allowing the human player to accept/reject/counter AI-offered trades—I incorporated those changes step-by-step, ensuring stability and that previous features remained intact.
Clarification and Reasoning:
Before implementing changes, I asked clarifying questions when needed to ensure I understood your requirements correctly. Where possible, I explained what was done and why, so you understood the reasoning behind each update.
No Removal Without Reason:
Unless you explicitly allowed or it was necessary for the change, I avoided removing or altering code unrelated to the requested features to maintain code integrity and continuity.
End Result
Enter your name: asdas
Welcome to Catan!
--- Purpose of the Game ---
Earn 10 Victory Points (VP) by building settlements, roads, and cities.
--- How the Game Works ---
1. The board is composed of hexes, each producing a specific resource (brick, lumber, ore, grain, wool) or desert.
Each hex has a number (2-12). At the start of a turn, you roll two dice. The sum determines which hexes produce resources.
2. Settlements adjacent to a producing hex earn 1 resource; cities earn 2 of that resource. Desert hexes never produce.
3. If a 7 is rolled, no one collects resources and the robber would be activated (not fully implemented here).
4. Your goal is to reach 10 VP. Settlements grant 1 VP, cities grant an additional VP over a settlement, reaching 2 total.
5. On your turn, you can:
- Build: Use resources to construct a settlement, road, or upgrade a settlement to a city.
- Trade: Offer your resources and request others. AI players consider fairness, scarcity, and personal benefit. You can accept, reject, or counter trades offered to you.
- Pass: If you pass without having built or traded, you gain 1 random resource as a bonus.
6. The game features AI players with different personalities (generous, fair, greedy) who evaluate trades differently.
7. Once you or another player reaches 10 VP, the game ends immediately and that player wins.
8. After the last player in a round finishes their turn, press Enter to continue and start the next round.
Starting the game!
asdas's turn!
--- Board ---
[1] wool (3) [2] grain (11) [3] wool (10) [4] desert (2)
[5] lumber (7) [6] ore (3) [7] grain (5) [8] lumber (7)
[9] brick (12) [10] brick (8) [11] brick (7) [12] ore (8)
[13] wool (11) [14] desert (6) [15] ore (8) [16] grain (2)
[17] lumber (12) [18] desert (12)
--- Dice Roll Explanation ---
You rolled a 7. The robber would be activated (not yet implemented):
- No hexes produce resources this turn.
- The robber would move to a chosen hex, blocking it.
- Players with >7 cards would discard half of them.
+-------------+-------+--------+-----+-------+------+-------------+--------+-------+----------------+
| Player | Brick | Lumber | Ore | Grain | Wool | Settlements | Cities | Roads | Victory Points |
+-------------+-------+--------+-----+-------+------+-------------+--------+-------+----------------+
| asdas | 2 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| AI Player 1 | 2 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| AI Player 2 | 0 | 0 | 3 | 1 | 1 | 0 | 0 | 0 | 0 |
| AI Player 3 | 2 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 |
+-------------+-------+--------+-----+-------+------+-------------+--------+-------+----------------+
Actions: 1. Build 2. Pass 3. Trade
Choose an action:
....