Tetris battle
tetris king-of-the-hill javascript
I guess you know what Tetris is, but if you don't I'll try to explain:
So there is a 2 dimensional board, often with size 10x20. On the top of the board, in the middle, there is a random tetrominoe (also rotated randomly), a figure made of 4 squares. There are 7 shapes:
L J S Z T O I
# # ## ## ### ## #
# # ## ## # ## #
## ## #
#
Every second, the tetrominoe (later called "block") will move 1 cell to the bottom until there is no space left. Player can control it - Move it to left, right, rotate it by 90 degrees (left or right) or speed up its fall. When it can't fall down further, a new block is created and you take the control over it, losing possibility to move the previous block.
The target is to get as much points as possible. Player can get them, by filling a line (which is then removed), for example:
!
!
!
****####!$ <- user scores a point, the line is now removed
&&&& $$$
different character is a different block
Player can lose if there is no place for a new block to spawn.
You can play Tetris online here
The battle
In this challenge, you will have to create a bot to play Tetris. Unlike a normal playthrough, there will be two players playing on a single board.
Let's call the bots A and B.
Block spawning
Every block will start on the left, or right side, depending which bot's it is (left - A, right - B). There will be a 2 block margin, so the block will have some space to rotate. Block will always spawn with left/right align, not centered.
If a block can't fit, it will try to rotate, so it can be placed. If all 4 directions fail, you die.
Example for 10 width board:
--A----B--
Random size board
Width: random even number between 8 and 16.
Height: random number between 15 and 25.
It's to make it a bit harder. Try to plan your strategy so it fits all the heights!
Scoring
You gain 1 point per destroyed block. Some bonus rules apply:
Enemy's block isn't my block
You can't use blocks placed by your enemy to gain score. After adding the last block to a line, you gain as much score as much sub-blocks you placed in it. Enemy sub-blocks don't count. Example:
Player A filled the line.
AAAABBBAAB
Player A gets 6 points.
Player B doesn't earn any.
Combos
If you do a move that removes more than just 1 line, you gain x times more score. Of course, x is the amount of lines.
Player A filled the line
--ABBB
AAABBBABBB <
BBBBBBABBB <
BBBBAAABBB <
B AA ABBB
Player A removed 3 lines.
Player A removed 12 (4+5+3) blocks he owns.
Player A scores 36 points.
Death & Game Over
When a new fails to spawn, it tries to rotate 90, 180, 270 or 360 degrees. If it still can't spawn. You lose. Note it won't try to change it's position, so be careful and try to not put any blocks in the spawn area.
When you die, you can't place any more blocks.
- In case your enemy has more points than you, you lose.
- Otherwise, the game doesn't end yet – the enemy will get double points for the next 10 blocks. The game will end when the bonus ends, when he beats your score or when he dies.
When the game is over, the bot with more points win.
The game will also end automatically after 300 actions. See API > Actions section for more information.
Controller
Work in progress. https://github.com/Soaku/Tetris-KOTH
API
Can't really tell you how it's gonna look like without a controller, right?
However, there is a project of how it's gonna look like:
Actions
Every game consists of actions. Your bot function will be executed at the beginning of each action. At the end of each, active tetrominoes will move 1 cell to the bottom.
The controller will wait a configurable amount of time between actions unless the preview is disabled.
Your function should return an integer in at most 0.1 seconds, otherwise your action is terminated and ignored. If it will cross the limit repeatedly, I might remove it.
Rules
- Default loopholes are forbidden.
- Aggressive bots are allowed but discouraged.
- You cannot use any external libraries. The controller uses jQuery, but you aren't allowed to use it.
- Don't try to access the document – Don't write nor read data.
- Don't write your bot to beat specific enemies by countering their strategies.
- Enemy spawn works like an occupied block. You cannot place anything here.
Main scoring
Every bot will play with every other bot.
Scoring works this way:
- Victory: 2 points
- Tie: 1 point
- Lose: 0 points