Xiangqi Pack by AI: banqi, xiangqi, xiangqi mahjong and a soldier's story, in your browser
This time the idea was to use the pieces of xiangqi (Chinese chess) as characters for a series of board games, and to put them all in one game file where you pick a game at start, hence the name “pack”. The pieces are round wooden discs with a character on them, and also a face: they say hello when turned up, say a line when they take, and “go back to camp for a rest” when taken.
Xiangqi Pack (象棋大補帖) is a game for a retro TV game console format; the whole game file is 2 MB. Inside:
| Entry | What’s there |
|---|---|
| The hall | Banqi, xiangqi and xiangqi mahjong; the computer at three strengths (easy, normal, hard); banqi and xiangqi also for two players |
| Story | “The Little Soldier Grows Up”, six chapters, each using one of the games as its level |
| Toys | Piece of the day: draw a piece, get a word of encouragement |
| Language | 中文, English, 日本語, 한국어, Tiếng Việt, switched with left / right on the title menu; the characters on the pieces stay the same |
The rules are traditional games; the code, the computer players, the graphics, the characters and four songs were made by an AI. The AI worked about 210 minutes, about US$58 at API prices.
It is also our first game in more than one language: Chinese, English, Japanese, Korean and Vietnamese, switched with left / right on the title menu, and the text and fonts on screen change with it. The translations were done by the AI too.
Play it in your browser: aixsfc.app/player/?load=xiangqi. It is free to play; to share it, send your friends this address.
How to play







- Banqi (dark chess): a 4×8 board with all 32 pieces face down. Each turn, turn one up, move one step or take. The ranks are general, advisor, elephant, chariot, horse, cannon, soldier; the soldier can take the general, the general cannot take the soldier; the cannon takes by jumping exactly one piece. The rules follow the Taiwanese banqi in the Chinese Wikipedia article on banqi.
- Xiangqi: ordinary Chinese chess, nine files by ten ranks with the river. The rules follow the Chinese Wikipedia article on xiangqi: the horse’s leg can be blocked, so can the elephant’s eye, the cannon jumps one piece to take, the soldier moves sideways only after crossing the river, the two generals may not face each other. Pick up a piece and the empty points it can reach show gold rings, the pieces it can take a gold rim; “將軍!” (check!) shows when your general is attacked. If the computer moves first you play black, and the board turns round so that your pieces are at the bottom.
- Xiangqi mahjong: the 32 pieces are the tiles. You and three computers hold 4 each; on your turn draw one and discard one. Five that make “a set plus a pair” win: a set is general-advisor-elephant or chariot-horse-cannon (one colour), or three soldiers; a pair is two alike. A discard that completes your hand wins too. The rules follow the 32-piece game in the Chinese Wikipedia article on xiangqi mahjong (one set plus one pair wins), simplified to be easy to pick up: only drawing and winning, no claiming discards for sets; three soldiers also count as a set; the article’s pair of generals of different colours is not in this version yet. A rules card comes before you start.
- The story, “The Little Soldier Grows Up”: the smallest soldier grows up at the recruits’ camp, climbs the ranks and in the end trains new recruits. The six chapters use banqi, xiangqi mahjong and xiangqi as levels, from easy to normal. A win opens the next chapter and your progress is saved; after two losses in a row you may skip a level, so children never get stuck. Taken pieces “go back to camp”; nobody gets hurt.
- Keys: D-pad to move, A to confirm, B to put back.
How the computer plays
Each game’s computer was first written as a JavaScript reference program, played against itself many times to set the strengths, then written again in the console’s assembly language following it.
Banqi: easy takes something at random seven times in ten when it can; normal scores each move (what it takes, whether it can be taken back); hard picks the best 8 moves and looks one turn deeper. The reference against itself, 300 games (taking turns to start):
| Match | Won | Lost | Drawn |
|---|---|---|---|
| Normal vs easy | 300 | 0 | 0 |
| Hard vs easy | 299 | 0 | 1 |
| Hard vs normal | 99 | 52 | 149 |
The many draws are banqi as it is: both sides play carefully, and 50 turns without a flip or a take is a draw.
Xiangqi: the first move is picked at random from 8 common openings (central cannon, horse, elephant, the pawn opening); after that every move gets a quick look (one move, the captures after it, and whether it threatens a big piece), and the best few lines are read two moves deeper, captures followed to the end. Easy reads 2 lines, normal 5, hard all of them. 20 games each:
| Match | Won | Lost | Drawn |
|---|---|---|---|
| Normal vs easy | 12 | 0 | 8 |
| Hard vs normal | 14 | 6 | 0 |
| Hard vs easy | 17 | 3 | 0 |
On the console, easy and normal take up to about 2 seconds a move, hard usually 2–4 seconds and at most about 7. So by both names the screen shows how many seconds this move has taken, and you can see the other side is thinking.
Xiangqi mahjong: easy discards at random; normal discards the piece that leaves the most kinds of winning pieces; hard also counts how many of each are still unseen. 4000 hands: at a table of three easy players, a normal or hard player wins about 34–36%, each easy one about 5%. Normal and hard come out about the same; luck counts for a lot in this game.
How we checked it
- Move by move. The computer plays against itself in the emulator; after every move the board (or the hands, the discards, the wall) is read from the game’s memory and compared with the reference program after the same move, and must be exactly the same. Banqi: 19 games at the three strengths; xiangqi: the three strengths, up to 200 moves a game; xiangqi mahjong: 42 hands, including self-drawn wins, wins on a discard and draws.
- Counting xiangqi moves. Every legal move from the start, counted down: 44 after one move, 1,920 after two, 79,666 after three, the same as the known figures, before the computer was written.
- Playing like a player. Test programs play whole games with the D-pad and A: pick a piece up, put it back, move to a gold ring, see the result, play again; for xiangqi also with the computer first and the board turned round. The story was played from chapter 1 until all six were open, checking that progress is saved.
How the AI built it
Our first game in several languages. All text is written in Chinese first, and each language has a dictionary looked up by the Chinese sentence. Each language has its own text area and font area, with every sentence at the same place in each, so switching language means copying those two into memory; the game code is the same for all languages. Korean and Vietnamese use another openly licensed pixel font, Galmuri11; English, Vietnamese and Korean wrap at word breaks, and Japanese keeps its full stops and commas off the start of a line.
One reference, two languages. The rules and the computer players were written in JavaScript first, played against each other to set the strengths, then written again in 65C816 assembly, down to the same random number generator, so both choose the same move from the same position and can be compared move by move.
Making xiangqi think fast enough on a slow machine. At first, hard took up to about 15 seconds on a move. The speed-ups:
- The moves in each direction got their own stretch of code.
- The last layer scores moves from tables instead of making them.
- Each line only asks “is this better than the best so far?”, so the search can stop early.
None of these changes which move is chosen.
The thinking time counted by the frame interrupt. While the computer thinks, the main program has no time to draw, so the seconds are updated by the vertical blank interrupt (NMI), which runs every frame.
All graphics drawn by code. The wooden table, the boards, the wooden pieces, and portraits of the 14 pieces with 5 expressions each are all drawn by programs; the font has no 傌 (the red horse), so it is put together from the person radical of 俥 and a narrow 馬.
Four new songs. The title, playing, winning and the piece of the day, written in MML (sheet music as text) as pentatonic tunes.
Cost
| AI working time | about 210 minutes |
| Model | Claude Opus 5.5, about 440 replies |
| AI output tokens | about 550,000 |
| Total tokens processed | about 190 million (mostly cache reads) |
| Estimated cost | about US$58 (at Anthropic API prices of November 2026; subscriptions are billed differently) |
| Other costs | none: the font is openly licensed, everything else was made for this game |
Versions
| Version | What changed |
|---|---|
| 1.261108.7 | The language moves to the last row of the title menu, switched at once with left / right |
| 1.261108.6 | Languages: 中文, English, 日本語, 한국어, Tiếng Việt, saved; the saved game is read back at start |
| 1.261108.5 | The story “The Little Soldier Grows Up”, six chapters |
| 1.261108.4 | Xiangqi mahjong |
| 1.261108.3 | Xiangqi: each side’s seconds on this move by its name |
| 1.261108.2 | Xiangqi’s computer redone: common openings at random, captures followed to the end, strength as “how many lines it reads” |
| 1.261108.1 | Xiangqi: against the computer at three strengths, two players |
| 1.261108.0 | The hall menu; quick presses no longer missed |
| 1.261107.1 | Banqi: a red general that vanished when turned up; a main menu item too wide for its box |
| 1.261107.0 | First version: banqi (against the computer, two players), piece of the day |
Not done yet
- Banqi rule options (the chariot’s long move, chain captures).
- Other games such as xiangqi endgame puzzles and jieqi, added to the hall one at a time.
- The computer strengths come from computer-against-computer games; how they feel to people needs more players.
For parents and teachers
- Good for primary-school children and families: each piece’s move is its personality; in the story the soldier “can move sideways once it crosses the river”, the horse “goes round when the way is blocked”, and playing along teaches how the pieces move.
- The opponents in the story are matches and tasks, taken pieces “go back to camp for a rest”; the piece of the day gives encouragement only, no fortune-telling.
To make your own game with AI, run npx https://aixsfc.app/skill/aixsfc.tgz in an empty folder, then start claude; see the home page.
Sources and licences
- Rules: banqi, xiangqi and xiangqi mahjong are traditional games; the rules follow the Chinese Wikipedia articles on banqi, xiangqi and xiangqi mahjong, with xiangqi mahjong simplified as described above.
- Font: Cubic 11, ACh-K, SIL Open Font License 1.1.
- Korean and Vietnamese font: Galmuri11, Lee Minseo, SIL Open Font License 1.1.
- English, Japanese, Korean and Vietnamese text: translated by the AI, not yet checked by native speakers.
- Characters and story: made up.
- Code, computer players, graphics, characters, music: made from scratch for this game.