An AI that plays NES Tetris at a high level. Primarily based on search & heuristic, with high-quality board eval through value iteration.
Due to the logistics of playing NES Tetris, there are two different clients for interacting with the main AI backend:
fceuxcontains a Lua client for playing in the FCEUX emulator (primary client)console_clientcontains a python client that runs on Raspberry Pi to play on a real console.- TetrisTrainer is a public web client (try it live!) that lets users draw a board and ask AI about the best placements.
Then there are two components of the backend:
servercontains the primary server, written in Node.js. It handles the request parsing, and the delegation to worker threads.cpp_modulescontains modules that perform the core AI computation at literally 100x the speed of the original JS implementation. The main flow involves a Node server thread sending a game state to the C++ module, which returns the value of each possible move as an encoded JSON map.
- Node.js: Download here
- FCEUX: Download here
- Python3: Download here
- Visual Studio Build Tools
-
Clone or Extract:
- Clone this repository or extract the zip file from the releases page.
-
Obtain NES Tetris ROM:
- Legally acquire the ROM for NES Tetris. You can use TetrisGYM.
-
Open Command Line:
- Press
Win + R, typecmd, and press Enter. - Navigate to the folder for Stackrabbit using
cd path/to/stackrabbit.
- Press
-
Install Dependencies:
- Run
node install.jsin the command line.
- Run
-
Start the Application:
- If the previous command runs without errors, execute
npm start.
- If the previous command runs without errors, execute
-
Setup FCEUX:
- Open the FCEUX folder.]
- Add all
.luafiles (excludingitn12.lua,mime.lua, andsocket.lua, put them inC:/path/to/fceux/lua) from the Luasocket repository toC:/path/to/fceux/lua/socket/. (if there is noluafolder, create it and the socket folder inside)
-
Load Tetris ROM:
- In FCEUX, click
File > Openand select the Tetris ROM.
- In FCEUX, click
-
Run Stackrabbit Script:
- In the FCEUX window, go to
File > Lua > New Lua Script Window. - In the new window, browse and run
path/to/stackrabbit/src/fceux/stackrabbit.lua. - Open level 19 and let it start!
- In the FCEUX window, go to
- We may have made some errors, so if you tell us those errors, We will make corrections as soon as possible, Thank You!
- Making the AI: @GregoryCannon
- Making the Tutorial on setting up: @BenP1236691
- Bug fixing the TypeScript: @NguyenQuangMinh0504
- Compiling StackRabbit into web assembly: @timotheeg
- Adding column 9 vits: @fractal161