Chinese Chess
Play Xiangqi on a 9×10 board with full rules and three AI levels.
FAQ
What are the basic rules?
What is the flying general rule?
What do the three levels change?
How many moves does Undo take back?
How to use
- Pick a level
Easy plays greedily with random noise, normal searches three plies, and hard searches five plies with pruning. Changing the level starts a fresh round at once.
- Select, then move
Tap one of your red pieces to select it, and legal destinations get marked. While the AI is thinking the status line shows a note, and taps are ignored until it answers.
- Mate or stalemate wins
Capture your way to checkmate, or leave the other side with no legal move, and the round ends. A move that gives check is announced in the status line.
- Undo in pairs
One undo removes both the AI reply and your own last move. Undo is locked once the round is decided, so start a new game instead.
- Keyboard play
Use the arrow keys and Enter to select or drop, Esc to cancel, U to undo and N for a new game. The cursor stops at the board edges.
About this tool
Chinese chess, known as Xiangqi, is played on a board of nine files and ten ranks. The pieces stand on the intersections, and a river divides the field in half. Each side starts with sixteen pieces. The general and advisors are confined to the palace, and elephants may not cross the river. Horses move in an L shape unless a leg is blocked, and chariots drive along straight lines with the greatest reach. Cannons capture only over a screen, while pawns gain sideways moves once they cross the river. The opening looks symmetrical, yet the first player holds a slight initiative, and the real contest is coordinating limited forces in a crowded space.
This version puts you on the red side moving first, with the AI on black, and every calculation runs locally in the browser. The engine scores each position with material values plus piece-square tables. A negamax search with alpha-beta pruning then looks ahead, three plies on normal and five on hard. The HUD shows the round count, the captured pieces and the thinking state. Your win and loss record is stored in the browser, no account is needed, and nothing leaves the page.
How it works
Chess engines combine search with evaluation. The board is encoded as an array, and all legal moves are generated for the side to move. A negamax framework walks the tree: after our move the opponent answers, and their best reply is our worst outcome. Alpha-beta pruning uses that structure to skip branches that cannot change the result, and capture-first ordering makes the pruning bite earlier. The evaluation adds material values to piece-square tables, so centralised horses, crossed pawns and active chariots score higher. King safety is handled by the check rules inside the move generator itself.
The flying general rule is special to Xiangqi. The two generals may never face each other on an open file. The engine treats that as a form of check, and the legality filter rejects any move that would create it. Checkmate and stalemate share one test, since a side with no legal move loses either way, and only the message differs. Depth and budget work together on the hard level, where the node count is capped so replies stay quick on modest hardware. The better the move ordering, the further the same budget can see.
When to use it
- A break at noon
One round runs from a few minutes to a quarter of an hour. There is nothing to install and no account to create. Three levels keep the outcome uncertain, and a lost round costs one tap to restart, which suits a short break between tasks.
- Teaching kids the moves
Blocked horse legs and elephant eyes are vivid rules that children pick up within a few games. The easy level misses captures and blocks, so young players taste victory early, and the normal level waits until they ask for a fair fight.
- Replaying your mistakes
Undo makes trial and error free, and the status line announces every check, so each move shows its immediate consequence. Take the losing line twice from the same position and compare the replies. This instant feedback is a light way to study how positions develop.
Tips & tricks
- Develop horses and cannons early and open a file for your chariots.
- Guard the palace before grabbing pawns; a bare general loses quickly.
- Keep horse legs and elephant eyes clear when you plan a jump.
- Watch the file between the two generals; an open file is an instant loss.
Things to watch
- Grabbing material
Snatching a loose pawn while losing the initiative is the classic beginner loss. When the opponent offers a piece, ask what the exchange buys, because a chariot pulled from the palace often starts the mating attack. Count the defenders first and let short-term gain go.
- A bare palace
With advisors and elephants gone, a knight fork or a rook on the back rank ends the game quickly. Keep one guard in reserve through the middlegame, and when checked, look for a reply that also develops a piece. A single tempo often decides the race.
- Wasting your pawns
Pawns look disposable, but a crossed pawn controls a key point and supports horses and cannons. Advancing without purpose concedes ground, and the enemy pieces cross over while your position comes apart. Move a pawn to open a line for a piece, never out of habit.