Let's discuss your "Tic Tac Toe Game"

Yes, I like yours.
The minimax fried my brain for weeks. So I finally just hard-coded the ai possibilities.
I think that you are right, I focused on the interface first, as always.
I need to go back and focus on the actual workings…

I think you don’t need minimax if you program the game to do the things you do as a player. Like with a new game, you have to check your opponent isn’t leading you into a trap - I hard coded two of those. Once the game is going, you check first to see if you can win in one move, then to see if you need to defend, then you have to check attack options, so you need to check if you can pull a fork, if none of those applies, check to see if your opponent is about to fork you and defend against it. The problem is getting the AI to “see” the board in the first place. I resorted to arrays for each row and column of the board plus the two diagonals. It got a bit complicated but it taught me to be comfortable with arrays and the computer can make sense of an array, like X becomes [0,2,0], X_X becomes [2,0,2]. [2,0,2] reduced = 4 which makes it an imminent threat for example. Hope this helps.

Yes. I just focused on seeing if the move was available. It seems to hold its own fairly well.

But I can’t get it to stop once there is a winner. It just keeps on playing. I know I’m missing something with this.

I think it keeps looping when checking for winner, and drop if there is one. I need to tear it apart again.

Thanks for your insight.

I don’t know if it’s very professional or not, but what I’ve been doing is using arrays to store true/false states so that I can be sure function scopes won’t mess the values up. If I had the problem you’re mentioning, I’d probably use something like gameOver[0] = false and then test for that state before allowing the program to make a move. I’m pretty new to all this coding stuff though, so, as I say, I don’t know if it’s very professional.

Thank you @CodeNooooob,

I have been using brackets to catch my function scopes of codes. But you may be right about testing the state before allowing the next move. I’ve been passing through to those functions.

I believe that good coding practice allows others to come in and pick up your solutions if you are no longer there.

Comments about logic, arrays when needed, looping through to reach the next iteration and testing our program are all totally professional.

In the workplace we’ll find that each team has their own way of doing things, but the true challenge is about making the project work and keeping it clean enough that whoever works there next can read your handwriting and will be able to fix any bugs or continue building into the new versions.

So, yes. Thank you for your professional solution.

Here’s my tic tac toe project!

Good job! This was fun!

1 Like

Hi!
Here is mine: https://codepen.io/jdomanski/full/RjbMXb/

Mine is here
97% Finished https://codepen.io/Azametzin/full/aLLYaG/

Hello!

I’d love to get some feedback on my Tic Tac Toe app:
codepen link
github link
I’m interested in code review. GUI is secondary.

Tic Tac Toe Game

Any feedback is welcome

Project Link - https://codepen.io/alimur/full/dZWvWg/

Project Link - https://codepen.io/zapbampow/full/NwbOpO/

While it isn’t as pretty as some of the other projects, I’m happy with this. Minimax defeated me and I ended up writing my own logic. The AI isn’t perfectly smart, but it basically leads to ties if you play well. I have to say, this was more challenging than I expected and I spent many more hours on it than I had planned. I ran into problems trying to implement the minimax algorithm. I ran into problems based on holes in my understanding of how to program and how to program in Javascript. I ran into problems with the asynchronous nature of JS. On the whole I would say that I learned quite a bit as I worked through this, which was the whole point.

1 Like

Please evaluate my x o game on code pen (Pharaonic style)

Project Link

Project link - https://github.com/chadpjontek/Tic-Tac-Toe

From what I’ve tested, and I’ve tested a lot, the AI does something unexpected when “it knows it can win no matter what”. What I mean by that is, if it is given the option to win immediately, it won’t if it also knows it can win in its next move without losing this turn. I’m at a loss as to why and I tried to even implement a priority system for deeper levels into the turns (sooner turns giving more score) but it didn’t seem to work. Any thoughts on that or feedback in general would be great!

P.S It is kind of cool though because it’s as if it’s teasing you before it goes ahead and wins even after giving you an extra chance lol!

Hi Guys, after a tremendous amount of time I’ve allotted thinking about this and doing this. I finally done it! (I think…) Please try and review my pen. If there are errors please If you could send the screenshot to me as a reply. Thank you.

Project Link - https://codepen.io/alecaceaes/full/jaQGdM/

Hey Everyone,

Please take a look at my Tic Tac Toe app and let me know what you think :slight_smile:

Link => https://codepen.io/afaisalsahar/full/ZvpWEJ

Thanks so much!

2 Likes

Project Link - https://codepen.io/LetsZiggy/full/Ozbawj/