I made this back in October, but I think posting about it now can't hurt.
There was a 48 hour game jam that I participated in, but I couldn't think of anything that I wanted to make with the theme, so I just decided to make and submit Tetris for a laugh.
After I had a working game of Tetris, I thought it might be fun to expand on it with an AI.
Video of the AI --
https://www.youtube.com/watch?v=vkUx0RRj4YcBrief explanation of the AI -- It analyzes every possible location you can put the current shape and assigns each possible location a score based on aspects like height, how many lines you clear, etc. The highest score is the location chosen. There's also a bit of AI learning in that the value of each aspect of score is determined by a process similar to natural selection. Run a few games with different values, pick the best performing values and change them slightly and repeat the process and it should improve. For example, if the game started off with assigning height a positive score, then after a few generations it should see a downward trend since placing blocks high up is generally not a good strategy to get a good score.
This article explains the whole thing --
http://www.danieljosephpetersen.com/posts/how-my-tetris-ai-works.htmlIn this version, the AI learning is turned off. It's always going to be using the same values, which actually weren't the best that I found (it's not as good as the video), but I unfortunately have a bunch of values saved and am not sure which ones were the best, I'd probably be better off just rerunning the thing again overnight. There's a ton of room for improvement, but I did it over the course of a week and I'm happy enough with it.
Controls:
Enter turns AI on/off
Period (.) key increases time between ai moves
Comma (,) key decreases time between ai moves