Share your repls and programming experiences

← Back to all posts
Tic Tac Toe AI
richtan (116)

https://repl.it/@richtan/Tic-Tac-Toe-Python-3
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.

Commentshotnewtop
richtan (116)

I feel so autistic talking to myself like this.

richtan (116)

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

richtan (116)

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 (116)

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

richtan (116)

@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 (116)

and also, just asking, whats slack?

rorymills1 (0)

on impossible, it missed ago and i won

richtan (116)

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

richtan (116)

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

katiewinton (43)

@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 (116)

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

[deleted]

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 (116)

@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 (116)

@xabras: what do you mean by glitchy?

richtan (116)

i am debugging right now pls give some time

richtan (116)

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

richtan (116)

Please upvote if you like it.

Itai52 (2)

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

richtan (116)

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 (116)

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

richtan (116)

I also added jokes if you do the quit command.

Calamari1 (87)

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 (116)

@calamari1: oh ok I fixed it now thanks!

richtan (116)

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

fbasso (0)

Best game ever bro!!!

richtan (116)

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

LightninMcQuade (241)

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 (116)

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

richtan (116)

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

richtan (116)

admins hate me project lol

NotVexed (6)

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.

richtan (116)

just saying, the code will catch all input and will not end without you telling it to or manually doing ctrl-enter or something

richtan (116)

unlike some other programs made by others