Share your repls and programming experiences

← Back to all posts
Tic Tac Toe AI
richtan (123)
I made this a few months ago during my free time. Not sure if this counts as a bot, but you can also play with another human.

richtan (123)

I feel so autistic talking to myself like this.

studentAlfredAl (446)

2 years later and I find this. Wonderful game! :)

richtan (123)

if there are any bugs, please tell me and i will do my best to fix them.

richtan (123)

I'm 90% sure there is a bug SOMEWHERE because the last time I tested it, it had a major one.
Edit: Found it

mariogreco (0)

Found a bug. On impossible mode, if computer goes first, it tends to place its marker on the same location as its previous turn, at least once per game.

richtan (123)

@mariogreco: oh ok I will go check that out. sorry about that!

richtan (123)

@mariogreco: could you send me a screenshot? that would be helpful when debugging

forfree (0)

very nice AI, fun to play, too! i like it. :)

richtan (123)

and also, just asking, whats slack?

rorymills1 (0)

on impossible, it missed ago and i won

richtan (123)

@rorymills1: can you do it again and send me a screenshot? i will try to fix it!

richtan (123)

If you want to use any of the code, you may use it, but please give credit.

katiewinton (45)

@richtan: um just saying it's a little confusing because when the computer goes first on medium it chooses the center piece and it looks like a zero not an o

richtan (123)

@katiewinton: well there is no zero on the board, so...


I got an error ;(. I'll write it over here:
Traceback (most recent call last):
File "python", line 456
elif int(self.ct1) - 1 in [0, 2, 6, 8] and not self.board[{0:8,8:0,2:6,6:2,1:"X",3:"X",4:"X",5:"X",7:"X"}[int(self.ct1) - 1]] in self.xos:
SyntaxError: invalid syntax"

richtan (123)

@matti12: sorry i was adding something at that time. it should work now

XaBras (0)

It is extremely glitchy! I mean, against the bot

richtan (123)

@xabras: what do you mean by glitchy?

richtan (123)

i am debugging right now pls give some time

richtan (123)

I think i fixed one of the bugs, you can try if you want.

richtan (123)

Please upvote if you like it.

Itai52 (2)

I won against it in "Impossible" mode, you should upgrade it.

richtan (123)

I will be adding back the impossible mode as soon as I get it to work properly.

AlexanderPaige_ (0)

This is a lot cooler than I expected. Nice job!

richtan (123)

Added what seems to be working Impossible mode. Report bugs if you find them :)

richtan (123)

I also added jokes if you do the quit command.

Calamari1 (95)

This has kind of a retro touch doing it like this. It's just like the good ol' days when we played stuff via telnet :D

btw: small bug in the end: the quit command asks for (Y/n) but it does not accept uppercase Y.

richtan (123)

@calamari1: oh ok I fixed it now thanks!

richtan (123)

@calamari1: also noting, the uppercase also means default yes is no answer, in case anyone asks

fbasso (0)

Best game ever bro!!!

richtan (123)

Added even more color to make it easier to know who is who.

LightninMcQuade (41)

Works Great! you should make it where when you are done with a game and type y to play agai it throws you into another game with the same settings and add a function with all of the menus in it so if they type settings you just call that function if they type n sys.quit and if they type y just clear the board and start another game

richtan (123)

@quadeg1: yeah i was thinking about that too, i will add soon

richtan (123)

@quadeg1: aaand I'm done, I added it

richtan (123)

admins hate me project lol

NotVexed (9)

Hi richtan,

I love your game and was testing it for bugs when i found this. It says, 'Please enter a valid input. That spot is may have been taken. If so, please choose another spot.

I am not sure if you wanted the "is may" part, or the "If so" part because it is obviously taken.