HALtris - A.I. Tetris Offshoot

Show off your games, demos and other (playable) creations.
numandina
Prole
Posts: 5
Joined: Tue Dec 31, 2013 10:37 am

HALtris - A.I. Tetris Offshoot

Post by numandina »

Hello.

I had to learn löve in the space of a weekend for a job application, and I ended up programming this tetris game where you are pitted against an AI who "chooses" which pieces are being handed to you in each turn. I liked the end result so much I've decided to post it here.

Turning the AI off will choose pieces randomly (regular tetris), while setting it to "1" (evil) will give you the worst possible piece for the current board configuration, and setting it to "-1" will give you the best possible piece.

The code is fully commented and although it can be made better, consider this just an alpha build (if I get feedback I may update it) and the code can be tidied up plenty. Included are playing music and having a rudimentary menu, and I've also displayed an "AI thinking process" board on the right that gives insight on how each piece was chosen. You can turn this off if you want to play without waiting.

The algorithm takes in several factors which are weighted and added up. You can easily edit these in the code. So far, there is only ONE case which enables you to "beat" the evil AI (try to figure it out). After fixing that I think it would really be impossible to get but one single line off of it. I've seen some similar games online but they aren't very robust and their AI can be easily beaten.

To make things entertaining, there is the option of switching difficulty in real time, which means you can pit the good AI versus the evil AI (by alternating between the two), or use the good AI to help you when you're in a tight spot.

Please check it out and give me feedback. Thanks! :)

Google Drive Link: https://docs.google.com/file/d/0B0etIhI ... R3Mkk/edit

EDIT:
Link for löve 0.9.0: https://docs.google.com/file/d/0B0etIhI ... =drive_web
Last edited by numandina on Thu Jan 09, 2014 10:14 am, edited 1 time in total.
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: HALtris - A.I. Tetris Offshoot

Post by davisdude »

Sounds like it's fun! I can't play it, though. Here's the error:
HALtris wrote:Error

maingame.lua: 78: attempt to call method 'setLifeTime' (a nil value)

Traceback

maingame.lua 78: in function 'load'
main.lua 20: in function 'load'
[C]: in function 'xpcall'
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
User avatar
shatterblast
Party member
Posts: 136
Joined: Tue Dec 11, 2012 9:47 pm
Location: Dallas, Texas, USA

Re: HALtris - A.I. Tetris Offshoot

Post by shatterblast »

I get the same error.
User avatar
XCaptain
Prole
Posts: 23
Joined: Tue Apr 09, 2013 11:18 am

Re: HALtris - A.I. Tetris Offshoot

Post by XCaptain »

This works fine in love 0.8.0.

This AI is very impressive :awesome:! It will never let you finish a line in mode one. never, not one, not even one line :|.
This AI is pure evil.
User avatar
riidom
Citizen
Posts: 74
Joined: Wed Jun 19, 2013 4:28 pm
Location: irgendwo an der Elbe
Contact:

Re: HALtris - A.I. Tetris Offshoot

Post by riidom »

Hi, I would like to try this too.
However, you could improve a few things maybe:
a) Don't go fullscreen right from start.
b) Take care for other people computers resolutions. It is sadly impossible for me to play, since I see the screen just partially.
c) It uses >600MB of RAM after 10 seconds of calculations. I know it is HAL, but still! :)
numandina
Prole
Posts: 5
Joined: Tue Dec 31, 2013 10:37 am

Re: HALtris - A.I. Tetris Offshoot

Post by numandina »

Here is a version that works in löve 0.9. I removed the particle system.

Please note that the game starts paused for some reason in 0.9, so press the pause button twice to unpause.

Looking forward to more feedback!
Attachments
HALtris.love
(646.53 KiB) Downloaded 256 times
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: HALtris - A.I. Tetris Offshoot

Post by Germanunkol »

This is really great.

Maybe you should make an AI-mode that's somewhere between 0 and 1, though, because, as XCaptain said, it won't ever let you finish a line in mode 1... so the game's impossible to win.

Great idea, though... and it works really well.

Also liked playing in mode -1 :D ... probably my best game score ever :)
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
numandina
Prole
Posts: 5
Joined: Tue Dec 31, 2013 10:37 am

Re: HALtris - A.I. Tetris Offshoot

Post by numandina »

That's a good idea. Added to the list.

P.S. It is not impossible to win a line in difficulty 1. There is one case, try to find out what it is.

Also if you find the game boring, try switching between difficulties in real time while playing. For example choose difficulty 1 at start, then after half the board is filled choose difficulty -1 to see what happens next.
User avatar
YellowAfterlife
Prole
Posts: 29
Joined: Mon Jan 23, 2012 4:05 pm
Contact:

Re: HALtris - A.I. Tetris Offshoot

Post by YellowAfterlife »

Interesting idea. I did experiment with Tetris "doing player a favour" some time ago, but never thought of turning that around to increase difficulty.

If I'm not mistaken, this is the case when AI gives in - it does not counter "manoeuvring" around blocks:
Image

Also there's a bug being that if you flip a tetriminoe next to a wall, it can get stuck in that in a variety of ways, erasing a piece of wall in process. This can be exploited to score a decade of lines or two, provided that game does not just drop you 20 square blocks in a row. That said, block variety is a problem of both modes -1 and +1. Game will often drop the same block over and over because factors are not changing. Could have a bit of randomness to that.

Without much exploitation, here's the farthest I got at mode+1
Image
yal.cc
Contains things I work on. Also gets Love2d examples time to time.
numandina
Prole
Posts: 5
Joined: Tue Dec 31, 2013 10:37 am

Re: HALtris - A.I. Tetris Offshoot

Post by numandina »

Thanks for the bug report. I could've sworn I tested that intensively. Added to the list.

I (and the AI) did not take into account maneuvering around blocks, which would really complicate the engine. Maybe I should take into account...

The one case I was talking about was a mathematical case, namely this:

Image

Reaching this particular block structure means that any of the blocks will enable you to finish a line, a result of the AI only looking forward one step.
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot] and 2 guests