Script + utility for bots to play NES Tetris on the FCEUX emulator.
First of all, I'm afraid this only works in Windows. My apologies.
- Download FCEUX and a copy of the original Tetris (NES) ROM. Make sure the ROM and joypad input works in FCEUX.
- Clone this repository to your computer. Run the script build.bat to generate the bot executable from the C++ files.
- In FCEUX, go to File -> Lua -> New Lua Script Window.
- In the Lua Script window, open classictetrisbot.lua (but don't run it yet).
- In the Arguments field, put "srvive -d". This will run the bot named "srvive." The -d flag will put a green highlight where the bot has chosen to place a piece.
- In FCEUX, open the Tetris ROM file.
- Get to the Type A level select screen and hover over 9 (it might be smart to make a savestate here). Press Run in the Lua Script window to run the bot and start the game.
A "bot" is basically a function that evaluates a decision and outputs a number, a higher number represents a better decision. Writing a simple bot is pretty easy, and you can use this repository as a framework to write your own.
- In the src/bots/ directory, create a new .h file for your bot. Let's call it
newbot.h
. - Copy the following into the file:
#include "../bot.h"
double newbot(decision_t decision) {
// ...
}
- Replace
newbot
with whatever you want to call your function. - Write your function. Good luck, more on this later.
- Navigate to the src/ directory and open
bot_list.h
. #include
your header file.- In the array
bot_list
, make a new entry:
{"newbot", newbot}
- Again, replace
newbot
with your bot name. - Save everything and run build.bat again.
- You're done! Now when you run the script in FCEUX, put your bot name in the arguments.
Short for "Survive" (or Senor Vive). One of the first bots, written to maxout through sheer force of will (a.k.a., getting a lot of lines). Here's a screenshot of SRVIVE making it all the way to the undefined territory from a level 19 start:
In honor of CTWC Tetris legend Jonas Neubauer. My attempt at writing an efficient bot, has maxed out a few times but needs some work.
XOR-stack, a weird bit-manip-abuse bot with a 10-line evaluator function. Performs extremely well for its size.