The T-spin AI bot (MisaMino ver 1.4.5 1111)

Started by misakamm, July 15, 2013, 05:42:05 AM

Previous topic - Next topic

oofw

Quote from: myndzi

Scratch that, how about solo play mode? I find that I really just want to study its play, but that's hard when I have to also stay alive...

i took a video of it... it just seems to use the next pieces very well , nothing too fancy... it's good at making 5 or 6 combos.  it's good at finding tspin triple setups.

XaeL

Quote from: oofw
it just seems to use the next pieces very well , nothing too fancy...


Please code your own tetris ai. Then you can come back to this thread.



QuoteLike many setups here, it is useful if your opponent doesn't move and you get 4 Ts in a row.

oofw

#47
Quote from: XaeL
Please code your own tetris ai. Then you can come back to this thread.

whuh ?

edit: didnt mean to put the ai down or anything... i just expected it to do really  cool stuff to be like so efficient

XaeL

Quote from: oofw
whuh ?

edit: didnt mean to put the ai down or anything... i just expected it to do really  cool stuff to be like so efficient
It's efficiency is much higher than mine unless i think realy hard.



QuoteLike many setups here, it is useful if your opponent doesn't move and you get 4 Ts in a row.

myndzi

#49
Quote from: oofw
i took a video of it... it just seems to use the next pieces very well , nothing too fancy... it's good at making 5 or 6 combos.  it's good at finding tspin triple setups.

The fact that that's what you have to say about it pretty much demonstrates why it's a good AI. You're talking about its play like you would talk about a human's play. Believe it or not, it's not easy to produce that kind of output with a computer program. I don't know what you were expecting, but it turns out that the best strategy for computers to play tetris vs a human is very similar to the best strategy for humans to play tetris vs a human

To elaborate a little, the reason it's so efficient is that it makes the right choices at the right times in the right circumstances. A human might see a T-spin opportunity, see that a T is coming up, and set up a TSD, burn a couple pieces, and take the TSD. A bot can easily calculate exactly how many pieces it would be wasting and if there is a better option, so when it does T-spins they are exactly when they are most convenient, using the T as soon as it is available. And when it skips obvious T-spin setups, it's because it can get better effect out of downstacking instead. Plus it can make T-spins very easily so it doesn't really have to keep an eye out for specific situations that 'show up' so much as it just stacks with a mind to creating T-spins when they're useful.

So in short, it 'makes it look easy'

perfectclear

to make the bot even better one could program in bag-7 knowledge, so that if can guess what its pieces will be that are beyond the previews. perhaps it would help it in setting up combos.

misakamm

Quote from: perfectclear
to make the bot even better one could program in bag-7 knowledge, so that if can guess what its pieces will be that are beyond the previews. perhaps it would help it in setting up combos.
you are right, if next 6 pieces is the beginning of a bag, that we know the 7th preview. the lv7 do exactly the same thing
Try to beat this program with your T-spin
[!--ImageUrlBegin--][a href=\\\"http://i.imgur.com/AzV0vhL.png\\\" target=\\\"_new\\\"][!--ImageUrlEBegin--][img width=\\\"400\\\" class=\\\"attach\\\" src=\\\"http://i.imgur.co

oofw

Quote from: myndzi
To elaborate a little, the reason it's so efficient is that it makes the right choices at the right times in the right circumstances. A human might see a T-spin opportunity, see that a T is coming up, and set up a TSD, burn a couple pieces, and take the TSD. A bot can easily calculate exactly how many pieces it would be wasting and if there is a better option, so when it does T-spins they are exactly when they are most convenient, using the T as soon as it is available. And when it skips obvious T-spin setups, it's because it can get better effect out of downstacking instead. Plus it can make T-spins very easily so it doesn't really have to keep an eye out for specific situations that 'show up' so much as it just stacks with a mind to creating T-spins when they're useful.

So in short, it 'makes it look easy'

yes i noticed this !

through the past few days i've probably been playing with misa's ai and watching it play for at least 12 hours. here are some more observations - it doesnt go for b2b as often as "pro players" ... very often it clears a line to set up a tspin. as for playing against it , i noticed i do a lot better if i build up a tspin (or a tetris) and wait for it to send me lines because if i send it something immediately it sends it irght back so the best way is to spike it... ive only beaten level 6 twice so i dunnooo...

i appreciate the difficulty of making a tetris ai , i really do! i had been thinking o f making one for my programming course way before i joined harddrop buuut then gave up because i realized how much work it is... any negativity in my previous post was because its playing style (which involves using the piece previews really well) is hard to replicate in real games and i , me myself , was interested in tetris AI to find out what the most optimal playing style is.

let me give you an exampe (these are things i thought about like two months ago):

1. you have different variables emphasizing different parts of the game , like combo , downstakcing,  tspinning at any chance vs waiting for garbage firsst, etc. im not sure how you would set this up im just brainstorming here. sooo then through some method (ie. "particle swarm optimization" or genetic programming... im not really sure how these work , i found them while researching ai methods but theres a lot more info on the internet if you're interested) you generate different copies of your ai and simulate matches against each other. you take the winning styles and change them a little to generate children and have them fight each other again. you do this over and over again. all of this is really complicated but eventually you would get (arguably?) the "best" playing style at the end that wins the most against the other styles

2. let's pretend we're playing so that only 2 or 3 previews is shown. the ai wil be significantly weaker , but most players will not be affected at all. how do you make the ai stronger?

i'm guessing in misa's ai , it randomly selects a list of how the previews can be used , so this is like a branch... and like it gets the field at the end of the branch. for this field , you can make it randomly simulate possible placements for each of the 7 pieces. you do this a few times (so you are " simulating" looking 5 or 6 pieces ahead but you are not ACTUALLY using the next pieces past the 2nd/3rd one. does that make sense?) and you get like a massive tree. then you use a fast evaluation method to get a score for each branch. now you have the original branches and the "simulated branches". for the simulated branches you get the average score and relay it back to the original branch. then you select the best original branch.
here you get the element of randomness and you have it sense whether a situation is good in a way similar to ryan's ai... in short , this gives you a more "humanlike" and less "calculating" ai


im still pretty new to programming so i dont know how easy to make or how well these would work and im not saying misa should do them (he can do what he wants)... im just trying to give yyou guys an idea of why i wrote my previous post like that.

myndzi

#53
Quote from: oofw
very often it clears a line to set up a tspin.

I noticed this too, but I don't think it impairs its play. It can do that because it allows it to keep the field flatter and the garbage more accessible, and it can make T-spins that aren't immediately obvious to human players because they're like 3-4 pieces out from a flat field or whatever. It's more to its advantage to stay accessible to the garbage than to maintain b2b.

[!--quoteo--][div class=\\\'quotetop\\\']QUOTE[/div][div class=\\\'quotemain\\\'][!--quotec--]
1. you have different variables emphasizing different parts of the game , like combo , downstakcing,  tspinning at any chance vs waiting for garbage firsst, etc. im not sure how you would set this up im just brainstorming here. sooo then through some method (ie. "particle swarm optimization" or genetic programming... im not really sure how these work , i found them while researching ai methods but theres a lot more info on the internet if you're interested) you generate different copies of your ai and simulate matches against each other. you take the winning styles and change them a little to generate children and have them fight each other again. you do this over and over again. all of this is really complicated but eventually you would get (arguably?) the "best" playing style at the end that wins the most against the other styles
[/quote]

Those variables are strategy-level, you can't do anything with them until you get tactics-level decisions reliable. (Where to put pieces, how to downstack, how to build a T-spin, etc.) Misa's AI is extremely good at tactical play, so if she feels like it she can move on to strategy later. Particle swarm optimization and genetic algorithms are ways of arriving at an optimal value without exhaustively searching all the possibilities, so for example, El-Tetris used particle swarm optimization to choose new constants (as well as choosing one or two different variables) for Pierre Dellacherie's algorithm.

Again, AI-vs-AI parameter optimization needs solid tactics before the strategy can be tunable. If the AI can't stay alive in a solo game, you hardly know if the other one won because the first one sucked or because the second one had better strategy.

(Edit: I'm sure Misa's AI does make some strategic decisions, but I think they are rolled into the tactical ones. For example, I imagine she has variables such as total stack height and maybe messiness of garbage or something like that. The factors that bring out the downstack when it gets high and fall back to T-spins when it stays low. To my knowledge, they aren't a separate decision-making process, though, and I believe they would need to be to perform the kind of optimization you're talking about.)

[!--quoteo--][div class=\\\'quotetop\\\']QUOTE[/div][div class=\\\'quotemain\\\'][!--quotec--]
2. let's pretend we're playing so that only 2 or 3 previews is shown. the ai wil be significantly weaker , but most players will not be affected at all. how do you make the ai stronger?
[/quote]

This isn't necessarily true

[!--quoteo--][div class=\\\'quotetop\\\']QUOTE[/div][div class=\\\'quotemain\\\'][!--quotec--]
i'm guessing in misa's ai , it randomly selects a list of how the previews can be used , so this is like a branch... and like it gets the field at the end of the branch.
[/quote]

More likely it selects highly rated placements to investigate further (misa..?); she mentioned it doesn't exhaustively search the search space, and ~4000 comparisons seems really good to me for 6 previews.

[!--quoteo--][div class=\\\'quotetop\\\']QUOTE[/div][div class=\\\'quotemain\\\'][!--quotec--]
here you get the element of randomness and you have it sense whether a situation is good in a way similar to ryan's ai
[/quote]

Ryan's AI's "sense" of what situations were good was an objective rating of how much utility each surface had. It was not dependent on context or speculation, it was calculated beforehand and used statically.

[!--quoteo--][div class=\\\'quotetop\\\']QUOTE[/div][div class=\\\'quotemain\\\'][!--quotec--]
simulating" looking 5 or 6 pieces ahead but you are not ACTUALLY using the next pieces past the 2nd/3rd one.
does that make sense?
[/quote]

This is kind of contrary. The reason to limit the previews of an AI is to provide it less work so that it can complete it in a reasonable amount of time. If you actually have 6 pieces to look at, there's no reason not to use them if you can search 6 pieces ahead. If you don't have them, then speculative searching has some utility, but mostly in deciding between close winners, since you don't KNOW what's coming up. In general, in Tetris, it's best to stack as flexible as possible -- provide spaces for anything that could show up, not provide a space that will be great if one piece shows up but awful if anything else does. This is something that can be analyzed independent of next pieces, so speculating about them doesn't really help much.

It's this quality that lends itself to the 'human' advantage you mention - through experience, we naturally learn shapes that are useful and shapes that are bad. While we can make specific decisions like "I've probably got a T or an I coming up", that doesn't play a direct role in our "normal" play, it only affects chance-taking: if you know an I is coming up, you might wait for it and built a Tetris instead of downstack. As you can see though, this doesn't seem to be necessary to play well -- downstacking can be as effective as attacking in multiplayer, and perhaps moreso if you're really good at it. It sends messy garbage, blocks and counters incoming attacks, and lowers your field to give you headroom.

In fact, the only real utility I can see to building up attacks or waiting for pieces lies in two places: human thought speed and timing. An AI can explicitly explore options in fractions of a second and find all sorts of oddball T-spins that you might only ever use once if you happened to run into them. But it'll see them before you WOULD run into them by accident. For a human it makes much more sense to save the ones you spot as you run into them (within reason!), rather than try to construct them at the perfect time. For an AI, the opposite makes sense: construct them at the perfect time, otherwise keep your stuff clear.

As for timing, stacking up is a way to wait for your opponent to do something without wasting your time. That's in strategy territory once again, which I think is currently out of scope here

---

Edit: This is getting kinda offtopic, I'm going to report my post and ask for a thread split

oofw

#54
Quote from: myndzi


Edit: This is getting kinda offtopic, I'm going to report my post and ask for a thread split

l m a o

thanks for the detailed reply... i agree with some things you said but my intentions both of the post i just made and of my previous post were quite different ahaha i didnt mean to launch you so offtopic

myndzi

It's a topic of interest, what's wrong with conversation?!

misakamm

here introduce the preview4 version
this version support 180spin (with no kicks) and normal game mode
add an extra level 7. level7 search the same depth as level6, but search more nodes
in the normal game mode, AI speed is 1.8pps by default (80 APM if level is 7)
@oofw @XaeL

thanks for larry's and blitz's stream, and everyone's suggestion.
Try to beat this program with your T-spin
[!--ImageUrlBegin--][a href=\\\"http://i.imgur.com/AzV0vhL.png\\\" target=\\\"_new\\\"][!--ImageUrlEBegin--][img width=\\\"400\\\" class=\\\"attach\\\" src=\\\"http://i.imgur.co

caffeine

#57
Thanks again for this, misakamm! Your program is a great tool for learning to play multiplayer better. I have some options ideas for players who might not play TOJ-style games, but are still interested in learning from the AI. What about on/off switches for combos, t-spins, and single preview? I'm interested in seeing how the AI plays in different scenarios.

Edit: also, sometimes I accidentally hit the wrong F-key because they are so close together! (And have to redo my keys all over again). Maybe it would be better to use something like F1 and F4 instead of F1 and F2.

baseballboy4296

Quote from: caffeine
sometimes I accidentally hit the wrong F-key because they are so close together! (And have to redo my keys all over again). Maybe it would be better to use something like F1 and F4 instead of F1 and F2.
Yeah, I've had this problem many times! It would be nice if they weren't right next to each other.

myndzi

Better: allow the user to abort with the ESC key. Easy to program, intuitive, and anyone who uses Esc to play Tetris needs to examine their key layout anyway