Welcome to my Hong Kong Big Two card game, designed with ChatGPT in a 15-hour coding sprint! This project blends AI coding for beginners with game design, using Python and Pygame to bring a local classic to life. I leaned on ChatGPT to write most of the code, aiming to see if an LLM could build a playable game—and even play it smartly as opponents. Spoiler: it’s a quirky, fun ride with some flaws! Check out the full story in my blog post: AI Coding for Beginners: Designing a Hong Kong Big Two Game with ChatGPT in 15 Hours.
- Classic Big Two Gameplay: Play singles, pairs, triples, or five-card combos (straights, flushes, etc.), following Hong Kong rules like the “3D” start and free-play after three passes.
- AI Opponents: Three LLM-driven opponents (賭神高進, 賭俠, 賭聖) powered by ChatGPT or Ollama—functional but not genius-level smart.
- Advice Feature: Hit '求建議' (Ask for Advice) for Cantonese tips from the LLM on what to play—helpful, though sometimes off the mark.
- Movie Quotes: Random quips from Hong Kong gambling films (God of Gamblers, Gambling Hero) like "五條煙!" (Five aces!) or "又會有條例投降輸一半咁怪都有既!" pop up for nostalgic flair.
- Fallback Function:
ai_fallback_movekicks in when the LLM tries illegal moves (e.g., a pair vs. a triple), keeping the game unstuck with a rule-based backup. - Pygame UI: Clean design with centered card stacks, hidden AI hands, and an advice widget—all tweaked by hand when ChatGPT’s prompts fell short.
- Python 3.x: Ensure it’s installed (This Game is tested in a Python 3.12 Environment. Download here).
- Pygame: For the game interface.
- OpenAI API or Ollama: For LLM-driven AI (opponents and advice). Pick one based on your
config.pysetup. - SimHei Font: For Cantonese text rendering—place
SimHei.ttfin your project folder (download from a free font site if needed).
-
Install Dependencies:
pip install pygame pip install openai
-
Set Up LLM Config:
- Edit
config.py:- For OpenAI: Add your
OPENAI_API_KEYandOPENAI_BASE_URL, either using python-dotenv or hardcoding them,and setLLM_PROVIDER = "OPENAI". - For Ollama: Adjust
OLLAMA_BASE_URL(e.g.,http://localhost:11434/v1) and setLLM_PROVIDER = "OLLAMA".
- For OpenAI: Add your
- Edit
-
Add Font:
- Drop
SimHei.ttfinto the project root or adjust the font path in the code.
- Drop
python main.py- Click cards to select, then use “出牌” (Play), “Pass,” or “求建議” (Advice).
- Scroll the advice widget with your mouse wheel or drag the scrollbar.
- Enjoy the gambling movie quotes popping up every few minutes!
This game was my experiment in ChatGPT game development—could an LLM design a full card game with minimal coding from me? I prompted ChatGPT for rules, UI, and AI logic, but it wasn’t perfect. I had to:
- Add rules step-by-step (it started with singles only!).
- Fix the table layout myself in
draw_screenafter prompt fails. - Solve game stalls with
ai_fallback_movewhen ChatGPT suggested it.
The AI opponents and advice aren’t brilliant (despite my hard prompting!), but the fallback keeps it playable. For the full scoop—quirks, fixes, and all—read my blog post: AI Coding for Beginners: Designing a Hong Kong Big Two Game with ChatGPT in 15 Hours.
- Dumb AI: Opponents and advice can miss winning moves—LLM smarts hit a ceiling.
- Sloppy Code:
current_moveinai_make_moveis unused (oops!). - Visual Tweaks: Table layout needed manual coding—ChatGPT struggled with prompts.
Got ideas to make the AI smarter or the design slicker? Fork this repo, tweak away, and send a pull request! I’d love to see your AI+Design twists.
This project is open-source under the MIT License—feel free to use, modify, or share it.
- ChatGPT for coding most of this (with my nudges).
- Hong Kong gambling movies for the fun quotes.
- You, for checking it out!