Questions tagged [tic-tac-toe]

Tic Tac Toe is a popular exercise for beginning coders, as the finite resources and game mechanics can be easily grasped and represented in many ways. As it is a short game, it is possible to create an algorithm that never loses.

The X player usually goes first. The player who succeeds in placing three respective marks in a horizontal, vertical, or diagonal row wins the game. The following example game is won by the first player, X.

screenshot

1551 questions
2
votes
3 answers

How to clone a 2D Array properly?

I am new to python and my first project is to hand-code a tictactoe game. So as I'm trying to write a "toString" method, I came across a problem with 2 Dimensional arrays, as follows board = [[0, 0, 0], [0, 0, 0], [0, 0, 0]] binit = board[:] for x…
FunnyO
  • 383
  • 2
  • 20
2
votes
3 answers

Tkinter Tic Tac Toe Drawing a shape in a certain box

I'm a newbie in programming, trying to learn python and I decided to make Tic Tac Toe for my first project. I've made functions for drawing X and O, but I have trouble drawing them in the box I'm clicking. Here's the code so far: ttt =…
Alecs21
  • 25
  • 3
2
votes
1 answer

Why does my the recursion never end in my tic tac toe minimax algorithm( In Python3 )?

First of all, I just want to say thank you so much for taking the time to read this. I made a tic tac toe game using graphics in python 3. In order to activate the ai you must click on settings, and then click on the players button. Then once I…
Epik_Guy
  • 21
  • 1
2
votes
2 answers

Tic Tac Toe React Js : Not able to print location

I am following Tic tac toe tutorial from https://reactjs.org/tutorial/tutorial.html I want to print location of cell being clicked My Code : function Square(props) { return (
Kushal
  • 8,100
  • 9
  • 63
  • 82
2
votes
1 answer

How to know who is winner in Tic Tac Toe in python using guizero

I have created a game called Tic Tac Toe. There are 2 players one of them are Xs one of them are Os all you have to do is get your symbol 3 in a row without the other person blocking you. The Gui for the game looks like this: Code: from guizero…
2
votes
1 answer

Textbox not showing up in my game Tic Tac Toe python

I have made a game called Tic Tac Toe it is a 2 player game and it is when you have etheir get 3 Xs or 3 Os in a row or diagonally. Code: from guizero import * empty = ' ' player = "X" def clicked(z): button = buttonlist[int(z)] # Finds out…
2
votes
1 answer

How to use std::multimap to map integer key to two integer values that serve as multidimensional array coordinates (for Tic Tac Toe)?

As an exercise, I am trying to create a TicTacToe game in Visual Studio as a console application. First, I created the 3x3 grid with a multidimensional array. I thought an intuitive way to "write" an 'X' or an 'O' in a particular square of the grid…
2
votes
1 answer

Make function return boolean and implement AI in tic/tac/toe game

I have made a tic/tac/toe game but I want to create a computer player that controls "O" while the user controls "X". For the clicked function in my code, I am trying to return a boolean but I am not sure if I am doing it right. The function returns…
Angel Baby
  • 137
  • 1
  • 9
2
votes
0 answers

Do I need another layer in my neural network?

I'm trying to program a neural network to play noughts and crosses (also known as tic tac toe). It works well enough to play against and decreases the loss function when I train it, but only up to a point, after which it plateaus. I have tried…
Arkleseisure
  • 416
  • 5
  • 19
2
votes
3 answers

Why does state not update as expected?

I am currently building a TicTacToe game and would like to store my current player in state as currentPlayer. After one player moves, I update currentPlayer to the opposite player. However, when I try to log the new state to the console, it's not…
Jacob Crocker
  • 75
  • 1
  • 7
2
votes
2 answers

Javascript - How to have the name of the players with queryselector?

I create a system to have the names of the players how get the 2 values of the names I create 2 input text and I want take the 2 values to show the name's players but I can not: HTML:
Xehanorth
  • 99
  • 9
2
votes
3 answers

Something wrong with this function?

I'm new to python. Started making a tic tac toe game. I've printed a board, so that's not the concern. My function play_sequence has something weird happening. from IPython.display import clear_output def display_board(board): print(board[7]+ …
Airmastix
  • 21
  • 1
2
votes
1 answer

Tkinter - making specific ranges of the window into variables

I am making tic tac toe game in Tkinter and it currently works, but I want the code to recognize when a range in the window (ex. 0, 0, 200, 200) is clicked so that I can change the variable. The goal with this is to make the game know when there is…
B S
  • 100
  • 1
  • 2
  • 7
2
votes
1 answer

Minimax algorithm Ruby Tic Tac Toe

I am writing unbeatable tic tac toe game using minimax algorithm. For some reason my scores hash lose its value as it comes out for the loop. If it is happening then I must be doing something wrong that I am unable to catch. I am new to coding. Need…
gkaur
  • 21
  • 2
2
votes
1 answer

My unbeatable Tic Tac Toe program is failing

I have tried to use the minimax algorithm to make a program that cannot lose in tic tac toe. But, in a few cases, it is failing. For example, when there are two spots left on the tic tac toe board (in a few cases), the program stops playing and asks…