Share your repls and programming experiences

← Back to all posts
Tic-Tac-Toe
CyanCoding (1415)

https://repl.it/@CyanCoding/Tic-Tac-Toe

As a fun side project, I built this awesome Tic-Tac-Toe game (with three AI levels) in May 2017.

Commentshotnewtop
Mello742 (2)

i beat impossible mode in 4 moves hahaha!!

maxballard (2)

It works and all, but no tic tac toe program like this should be 2000 lines long. You can put a lot of the stuff you have into specific functions. You repeat yourself many times, and basically just hardcoded the game. This will work for a simple game like tic tac toe, but if you wanna progress farther as a programmer you need to actually learn how to program.

CyanCoding (1415)

@maxballard Haha, thanks for the tip. Do note though that I made this over a year and a half ago, and it's not even in the same language I use now. But yes, I have gotten over that bad habit.

ebest (590)

code warningserrors sure can kill!

and HOW did this get the 5th most votes in ALL the posts!?!?!?

-Ebest

Emrah2005BiH (0)

Nice job! Enjoyed playing.

Nanowrimoijk (36)

beat impossible, thats what comes when you play against yourself =(

m_23s (0)

SHUT UP MAN WHAT U GONNA DO BRUV/ I FIND YOU

honchkrowabcd (11)

impossible isin't impossible

Spyder101 (4)

Holy cow great job! The code works smooth and he difficulties hold up their reputation...

zacdisbury (0)

well well well that's cool

FiveCubed (12)

Why do you have it look at every spot on the board to test for a win?

CyanCoding (1415)

@fivecubed: This way it can make sure you won, regardless of the win spots.

Jeremiah32556 (0)

This is REALLY cool. I think it would be better if it was more obvious where the player "0" plays because I sometimes can't tell if the bot played in a spot or if it's just the number zero.

glendog (0)

2600+ lines of code :o

RyanBridgforth (0)

@glendog: Just wait until his next project...

AntonAlley (0)

I'm building a tic tac toe AI in PYTHON only 300 lines for the whole game and AI

CyanCoding (1415)

@antonalley: Awesome! Yes, after writing this in C++ I realized my mistake 😀. Can you send me a link please?

s622420 (0)

it would be nice if there was a play again button

CyanCoding (1415)

@s622420: I think that's just the run button 😀

BobJoeIII (19)

I beat impossible mode!!!!!!! (my life is complete)

beginneer (0)

yo code is just insane! KEEP IT UP

J7Luke (0)

Nice simulator! I can always win against impossible if I go first, and I can always tie if I go second.

CyanCoding (1415)

@j7luke: That's a sign of a real pro! As far as I've seen from other users, there's only one-two ways to beat impossible!

TuffeMann (0)

Hi Cyan. That computer is quite polite. It won, with three o-s in a row, but let me place anothr x after winning. So I also got 3 in a row. The computer then told me that I had won the game. REALLY! There must be a bug in this game somewhere...

CyanCoding (1415)

@tuffemann: Yes, I don't know where that bug is, but I've seen it happen before. I just thought it too funny to remove 😄

Govind05 (0)

Why it is tag impossible,I had beat it in my first attempt

CyanCoding (1415)

@govind05: I tagged it as impossible because until I had published it on the I built this challenge, nobody had ever beaten it before. I didn't even know it was possible! Now, I just leave it in there so that people think there's no way and keep trying until they figure it out.

Jeremiah32556 (0)

@govind05: I won too. Lol, I think the bot is not good with that spot

CyanCoding (1415)

@jeremiah32556: Sadly, it isn't that. It doesn't really have a choice since when it goes in the middle, it'd need to play twice to stop you (if you played on the end).

J7Luke (0)

@microwither The strategy used to beat the impossible computer is to choose a corner, then the opposite corner, then a third corner (or the middle if the computer has left it open). The way for a computer to tie a game that opens this way is to choose the corner opposite the one the player chose on the first move. From there, all the computer has to do is block any potential 3-in-a-row moves.

CyanCoding (1415)

@j7luke: Interesting! I'll fix this soon.

SomeRandomGuy (0)

I beat the impossible mode first try. I loved the way you made the game. Great job!

linaalomari (0)

OMG, this is crazy!
Great job, I'm trying to beat the impossible level too!

josh_improgo (0)

Simple game and fun to play :)

CyanCoding (1415)

AGH RED ALERT RED ALERT THE SECRET TO BEATING IMPOSSIBLE WAS LEAKED ON THIS POST. DO NOT READ I REPORT DO NOT (what am I even doing) READ!

CyanCoding (1415)

@barti10110 Thanks for being the 100th voter!

barti10110 (0)

Not so difficult to beat impossible, but well programmed, and I really appreciate the graphical side of it!

Case_Buttitta (39)

I beta impossible mode on my first try...

Case_Buttitta (39)

I meant beat instead of beta

CyanCoding (1415)

@casebuttitta: Good job! Yes, this has happened to several people.