ECE243 Computer Organization (W26)
- Emma Le
- Peng Yang (Jonathan) Deng
This project brings Doudizhu (斗地主), a three-player Chinese card game, onto the DE1-SoC FPGA board. The final board-facing build supports the full main gameplay loop: startup screen, bidding, turn-based play, round resolution, audio feedback, and a persistent scoreboard across rounds.
The repository is split into two major parts:
libdoudizhu/: a portable C11 game engine that handles rules, move classification, bidding, scoring, and bot playsrc/: the DE1-SoC integration layer, including VGA rendering, PS/2 keyboard input, audio, timers, and the board entry point
- portable Doudizhu rules engine packaged as a reusable library
- bot opponents supplied by the
libdoudizhusubmodule - board-side VGA UI for the full gameplay loop
- PS/2 keyboard-driven interaction model
- audio feedback tied to major game events
- isolated unit / demo targets for individual hardware subsystems
The board executable in src/main.c follows this loop:
- Show the help screen and wait for
Enter - Deal a new round and sort the human player's hand
- Run bidding until a landlord is chosen
- Run the main play phase with one human player and two bots
- Apply round scoring and show the round-finish screen
- Wait for
Enter, then start the next round while keeping cumulative scores
The keyboard driver currently supports:
Left/A: move leftRight/D: move rightUp/Down/W/S: toggle card selectionEnter: confirm bid, play selected cards, pass, or continue from splash / results screens
During bidding, left and right cycle through available bid options and Enter confirms the current selection.
During play, selecting no cards and pressing Enter submits a pass.
Startup screen shown before gameplay begins. This is the first screen players see on the DE1-SoC display.
Bidding screen shown before gameplay beings. This is where the player and bots bid for control of the landlord.
Main in-game board state showing the player's hand, opponent HUD, centre play area, and current round status.
End-of-round results screen showing the winner and updated running scores before the next round starts.
| Path | Purpose |
|---|---|
README.md |
Top-level project overview |
CMakeLists.txt |
Root build configuration |
riscv32-toolchain.cmake |
DE1-SoC RISC-V cross-compilation setup |
rvgcc-toolchain.cmake |
Alternate RISC-V cross-compilation setup |
libdoudizhu/ |
Portable Doudizhu rules engine and bot library |
src/io/ |
DE1-SoC hardware interface modules |
src/units/ |
Board-side and host-side unit / demo targets |
src/other/ |
Shared addresses and helper utilities |
src/main.c |
Main board-side gameplay loop |
To build this project, you need:
- CMake 3.3 or newer
- Ninja or Unix Makefiles
- a C11-compatible compiler
For DE1-SoC builds, you also need the RISC-V toolchain referenced by riscv32-toolchain.cmake.
Before building, initialize the game-engine submodule if needed:
git submodule update --init --recursivemkdir cmake-build-debug-linux
cd cmake-build-debug-linux
cmake -DCMAKE_BUILD_TYPE=Debug -G Ninja ..
cmake --build .mkdir cmake-build-release-linux
cd cmake-build-release-linux
cmake -DCMAKE_BUILD_TYPE=Release -G Ninja ..
cmake --build .mkdir cmake-build-riscv
cd cmake-build-riscv
# Ninja
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../riscv32-toolchain.cmake -G Ninja ..
cmake --build .
# Or Unix Makefiles
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../riscv32-toolchain.cmake -G "Unix Makefiles" ..
cmake --build .When cross-compiling, the board-facing targets are emitted as .elf files.
The main game target is FinalProject.elf.
To actually run the game, you must use the DE1-SoC RISC-V build, specifically with the riscv32-toolchain.cmake setup.
# After building, the target FinalProject.elf should be in your directory
# Rename the binary to output.elf - the Makefile looks for this.
mv FinalProject.elf output.elf
# In one powershell terminal, run the following:
./gmake DE1-SOC
./gmake gdb_server
# Afterwards, run the following in a second terminal:
./gmake gdb_client
# Use the continue command to start execution
cThe core rules and bot tests live in libdoudizhu and can be run from a Linux build directory:
cd cmake-build-debug-linux
cmake --build . --target all
ctestRelevant test binaries include:
test_movestest_gametest_bottest_eval
If bot tuning is enabled with -DDOUDIZHU_TUNING=ON, the project also builds test_selfplay.
The board-facing hardware tests live in src/units and should be built with the RISC-V toolchain, then run on the
DE1-SoC or in Cpulator.
cd cmake-build-riscv
cmake --build . --target allRelevant targets include:
AudioTest.elfDisplayTest.elfKeyboardTest.elfTimerTest.elfMainTest.elf
These host-side targets are useful for validating non-board-specific behavior:
FontTestDisplayLogicTestHexDispTest



