Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: Xeda112358 on January 16, 2012, 12:54:52 pm

Title: Tic-Tac-Toe (Grammer)
Post by: Xeda112358 on January 16, 2012, 12:54:52 pm
A new game to add to your Grammer collection is here! I still need to better the animation, optimise some code out, and make a menu so users can select options (such as who is the AI). Anyways, for now, there is an AI that you can play against, so have fun :)

When you finish the game, press clear to exit, press Enter to play again.
Title: Re: Tic-Tac-Toe (Grammer)
Post by: jsj795 on January 16, 2012, 12:59:47 pm
how hard is the AI? does it make randomized mistakes except obvious wins?
Title: Re: Tic-Tac-Toe (Grammer)
Post by: Xeda112358 on January 16, 2012, 01:24:20 pm
It is *supposed* to make like this:
Winning moves are always taken
Blocking an opponents winning move is taken if a winning move is not found
Random move if neither player can win next turn

So the AI is not amazing, but it works :)
Title: Re: Tic-Tac-Toe (Grammer)
Post by: jsj795 on January 16, 2012, 01:30:49 pm
ahhh I see. yeah it's good enough AI for its purpose
Title: Re: Tic-Tac-Toe (Grammer)
Post by: Sorunome on January 16, 2012, 01:50:59 pm
You could create a AI that can't lose! :D/me knows how not to lose in tic tac toe
Title: Re: Tic-Tac-Toe (Grammer)
Post by: annoyingcalc on January 16, 2012, 01:52:25 pm
really? id like to know how
Title: Re: Tic-Tac-Toe (Grammer)
Post by: Xeda112358 on January 16, 2012, 01:52:38 pm
For X, it is possible to never lose and for O, the same is true. However, there is a way to tie in either case. I am currently trying to make the algorithm in Grammer code >.>
Title: Re: Tic-Tac-Toe (Grammer)
Post by: hellninjas on January 16, 2012, 01:54:29 pm
I haven't seen a tic tac toe game in a while!
This brings back some memories :D
Title: Re: Tic-Tac-Toe (Grammer)
Post by: Xeda112358 on January 16, 2012, 01:57:43 pm
Okay, so the way I am going to do it, I will have 9, 8-byte lists for each of the 9 positions. there are 8 ways to win, so I will keep a running list of the current stats. I assign player X a value of 1 and player O a value of -1. The lists contain the win that get affected. When a potential win reaches -2, X will find a move that brings that to -1 (-3 is an O win, 3 is an X win), or if there is a 2, X will choose a move to bring that to 3 (if it exists).
Title: Re: Tic-Tac-Toe (Grammer)
Post by: Spyro543 on January 16, 2012, 02:00:58 pm
Wow, awesome game! Perhaps you could make a bigger board, like 4*4 or 5*5?
Title: Re: Tic-Tac-Toe (Grammer)
Post by: Sorunome on January 16, 2012, 02:01:48 pm
really? id like to know how
if X starts in a corner...

X - -
- - -
 - -

then you do

X O -
- - -
- - -

If he does now

X O -
- - -
- - X
It's pretty easy and if oyu continue blocking wins there is a tie.

If he does
X O X
- - -
- - -

you do
X O X
- - O
- - -
and then again just block that he doesn't win ->tie

if he does:
X O -
- X -
- - -

OR

X O -
X - -
- - -
You just keep blocking his wins -> tie

if he does:
X O -
- - X
- - -

you do
X O -
O - X
- - -
and then just block his wins -> tie


Ok, if he now starts on the edge:
- X -
- - -
- - -

You do
- X -
- - -
O - -
and you can just block his winning moves -> tie

if he starts in the center he's really stupit as then you don't have to think and just have to block his winning moves -> tie.