How to modify TOJ AIs
Posted: Fri Jul 15, 2011 11:16 am
Did you nkow you can modify TOJ AIs ?
You can use SJEHHTool to decode the sje.hh file in the ai folder.
You will obtain Lua scripts.
Lua scripting language is very easy to understand. I think how the AIs work is that
1) when the game starts the Start function of the Lua script is called.
2) After every new dropped piece, the function PrepareThink of the Lua script is called.
3) TOJ then tries every possible move to a "virtual fields" and evaluate each field by calling the EvalField function of the Lua script passing as parameter the depth in the search tree of the best move (it seems the depth is set to 0 on every script)
4) when the game ends the End function is called.
By neutralizing the EvalField function I found out that :
- test_tetris.lua is the AI used when playing vs a bot in multiplayer.
- test_dropchecker.lua is used when using the anti missdrop item. (it probably compares the result of the EvalField function upon executing the move the user ordered, with some threshold and prevents the move is under this threshold.
The other scripts are probably for the training mode with each script corresponding to different levels.
There doesn't seem to be any instruction limiting the speed so I think the fact that test_tetris.lua is so slow may be due to performance issue? Unless the speed is controlled outside of LUA script.
You can use SJEHHTool to decode the sje.hh file in the ai folder.
You will obtain Lua scripts.
Lua scripting language is very easy to understand. I think how the AIs work is that
1) when the game starts the Start function of the Lua script is called.
2) After every new dropped piece, the function PrepareThink of the Lua script is called.
3) TOJ then tries every possible move to a "virtual fields" and evaluate each field by calling the EvalField function of the Lua script passing as parameter the depth in the search tree of the best move (it seems the depth is set to 0 on every script)
4) when the game ends the End function is called.
By neutralizing the EvalField function I found out that :
- test_tetris.lua is the AI used when playing vs a bot in multiplayer.
- test_dropchecker.lua is used when using the anti missdrop item. (it probably compares the result of the EvalField function upon executing the move the user ordered, with some threshold and prevents the move is under this threshold.
The other scripts are probably for the training mode with each script corresponding to different levels.
There doesn't seem to be any instruction limiting the speed so I think the fact that test_tetris.lua is so slow may be due to performance issue? Unless the speed is controlled outside of LUA script.