I'm trapped in Tic-Tac-Toe

I'm trapped in Tic-Tac-Toe
0

#1

I have copied my scores array and called it NotTaken. When I place a marker, I want to splice the placement from the NotTaken array. The problem I am having is that my Player is not splicing although the computer is splicing.

My code is heavy on console.log so that I can track these. The function I think I’m problems with is the updNotTaken().

Any help is appreciated. My pen is at https://codepen.io/KoniKodes/pen/KqyLML


#2

I have read through your code a couple of times. You do not have many comments, so it is difficult to figure out what some of the functions are supposed to be doing. If you can answer a few questions, I will try to figure out what is going on in your code.

  1. Can you explain in detail what the function comp is supposed to do?

  2. What is the status array supposed to be tracking?

  3. What is the scores array supposed to be tracking?


#3

Thank you for responding.
comp() is supposed to have the computer choose a place (that hopefully has not been taken)
status tracks -1 for player or 1 for computer in the placement of the board. It is used for assigning the winner.
scores array is the board spaces id #, and is replaced with “X” or “O” when a move is placed. It is used to track the winCheck function.

The notTaken is spliced per score when a space is placed so that when we come down the final two moves before the full board is a tie, and the computer doesn’t have a block or win, it will look at the random spaces available in the notTaken array and then place on the random choice.

The updNotTaken function is supposed to define what the indexOf the notTaken array is with the place value. That is what I think is not working…

Thank you again.


#4

I don’t know if this is the problem but in updNotTaken you have

while (notTaken.indexOf(place) > -1) {
    notTaken.splice(notTaken.indexOf(place), 1);

It is generally a bad idea to change the array while iterating inside it. Maybe changing the while statement to an if will solve your problem.


#5

Thank you. But now it’s back to stealing a space that’s already been taken when it’s has to choose between the last two moves without a block or win.

In looking at the console.log, it seems that it although it sees the place that my player chose, it does not attach it to the notTaken splice. On the other hand, it does see the computer placement and splices that. Yet, it looks to me as though both segments are the same.


#6

You were correct!

I went back to keeping it simple and took out the Not Take array.

Here’s my new page: https://konikodes.github.io/TicTacToe/

Thank you for your help.


#7

I have finally gotten out the Tic-Tac-Toe Trap! I did not think I was going to survive it.
Thanks to all of you for your support and suggestions.

Please take a look and let me know what you think.
https://konikodes.github.io/TicTacToe/


#8

You have a slight bug. When I lose, it tells me Congratulations! If I win, it tells me Congratulations and then the computer makes one more move for some reason.

You also need to prevent the player from being able to make a move before the computer has played. I can make 3 moves and win before the computer plays first move.


#9

Thank you for your feedback. I do not understand why it is happening to you.
When I win I get congratulations and one song. When the computer wins I get The Computer has won, and a different song.
On the tie, I get We have a tie! and a different song.

I do have the computer set with a 2 second time out. I have problems with an immediate placement after a player moves, it hurts my eyes. How do I prevent others from cheating?


#10

I was the Bird of Paradise in this game. The computer won, but look at the message on the screen.

When we get a tie, the game just sits there with no message or music.


#11

Thank you. What device are you using? What browser? I need to fix this.


#12

I think I fixed it. Can you check again please?
I should not matter which marker you choose. You should be recognized now.


#13

I tested several games with different icons and different starting positions. Everything seemed fine, but then I had this game which ended in a tie, but no music or tie message. The game just stayed liked this until I refreshed the browser.

Also, there was a game where I won, because the computer did not make a winning move. I got my congratulations message and music and then computer played one more turn (after I won) to get three in a row and then the computer’s winning music played at the same time. I was not fast enough to get a screen shot of both of us winning. I will try to get it to do it again and post the screenshot here.


#14

Thank you for bringing these to my attention. I thought I had solved all of these. They are why I’ve been trapped here for so long.

Did these happen after the game refreshed? Or was it as a new game? I remember one tester did it like 8 times and then mad about a memory error.

So I’m wondering what my refresh threshold is and if it is affecting the logic.

I don’t think the user story tells us how many times to refresh.