Keys:
← : move piece left
→ : move piece right
↓ : drop piece
Z : rotate piece counter-clockwise
↑ or X : rotate piece clockwise
⌘R : reset game
KRIEG {video|source code & compiled:Mac OS X} is probably my oldest project which will run on a machine not only found on eBay, being the first prototype I coded when I was teaching myself SDL* in 2003; KRIEG is a quick-and-dirty clone of Puyo Puyo with an AI bolted on top; whilst playable, the purpose of KRIEG was to be a test-bed for several ideas for AIs I was entertaining at the time…
With regards to the AI…
- For every possible different combination of piece X-coordinate and rotation, a prediction is made, resulting in a score for attaching the piece under the AI player’s control at that X-coordinate and with that rotation.
- When predictions for every possible different combination of piece X-coordinate and rotation have been made, the AI player will simply take the X-coordinate and rotation with the best score as its targets, and attempt to move/rotate the piece under its control to that coordinate and that rotation.
With regards to the predictions made by the AI…
- A prediction is made by creating a duplicate of the the AI player’s playfield and attaching the piece under the AI player’s control to the duplicate playfield at the proper X-coordinate and with the proper rotation for the prediction.
- The duplicate playfield is then updated as the original playfield would be, dropping and eliminating blocks until no more changes will occur within the duplicate playfield without the attachment of another piece.
- When no more changes will occur within the duplicate playfield without the attachment of another piece, several values are passed back to the AI: the height of the highest column in the duplicate playfield; the total number of blocks eliminated from the duplicate playfield; and the number of blocks of the same colour in the groups formed by the attachment of the piece under the AI player’s control to the duplicate playfield.
- The score for the prediction is then determined by multiplying those values passed back to the AI by the importance of those various values to the AI’s decision making process, and summing the multiplied values.
(I’ll note that there is at least one bad bug in KRIEG, a potentially long-to-infinite loop in kriegPlayfield::Spawn() – that bug has never triggered on any of the occasions I’ve used KRIEG, but it is there…)
KRIEG was developed on an Apple iMac DV (Summer 2000) in C++ using SDL*, OpenGL, and sealfin*, compiled with Apple Xcode 1.1.