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
3
votes
4 answers

Creating a non-perfect game algorithm

I know how algorithms like minimax can be used in order to play perfect games (In this case, I'm looking a game similar to Tic-Tac-Toe) However, I'm wondering how one would go about creating a non-perfect algorithm, or an AI at different 'skill…
Radical
  • 1,003
  • 1
  • 9
  • 25
3
votes
1 answer

Game tree for tic tac toe

Firstly, I am a beginner in java and I'm trying to simulate a TicTacToe game. I wanted to use a game tree to create a possible tree for all the states. Each node in the tree will represent the state and use this tree to decide the next move to make.…
SinisterX
  • 31
  • 2
3
votes
3 answers

Negamax implementation doesn't appear to work with tic-tac-toe

I've implemented Negamax as it can be found on wikipedia, which includes alpha/beta pruning. However, it seems to favor a losing move, which is an invalid result to my knowledge. The game is Tic-Tac-Toe, I've abstracted most of the game play so it…
3
votes
1 answer

Setting up an ANN to classify Tic-Tac-Toe End-Games

I'm having an hard time setting up a neural network to classify Tic-Tac-Toe board states (final or intermediate) as "X wins", "O wins" or "Tie". I will describe my current solution and results. Any advice is appreciated. * DATA SET * Dataset = 958…
user1528976
  • 191
  • 6
3
votes
1 answer

Which algorithms are available to solve Tic Tac Toe?

What algorithms are available to solve Tic Tac Toe? Especially with board size 4 * 4 or bigger instead of 3 * 3? I tried 4 * 4 with Minimax & alpha-beta pruning but the pc seems to hang and throws exceptions on stack overflow. I saw these source…
Duc Tran
  • 6,016
  • 4
  • 34
  • 42
3
votes
4 answers

Tic Tac Toe Neural Network as Evaluation Function

I've been trying to program an AI for tic tac toe using a multilayer perceptron and backpropagation. My idea was to train the neural network to be an accurate evaluation function for board states, but the problem is even after analyzing thousands…
2
votes
2 answers

How can i extract my best move from Min Max in TicTacToe?

int minmax(Board game, int depth) { if (game.IsFinished() || depth < 0) return game.Score(game.Turn); int alpha = int.MinValue + 1; foreach (Point move in game.Generate_Moves()) …
Dementor
  • 241
  • 1
  • 6
  • 12
2
votes
1 answer

Implement Minimax without recursion

I am buiding a Tic Tac Toe solving robot. For practise, I wrote a Tic Tac Toe game using the minimax algorithm which worked very well. When I wanted to port my code to the controller, I found out that none of C/C++ compilers for this controller…
lyxicon
  • 163
  • 3
  • 6
2
votes
0 answers

Python minimax for tictactoe

After completely failing the minimax implementation for tic tac toe, I fail to see what's wrong. Right now, my AI just goes around in a circle... import collections class InvalidLocationError(Exception): pass import copy class Board(object): …
Pwnna
  • 9,178
  • 21
  • 65
  • 91
2
votes
0 answers

Why is my Tic-Tac-Toe game not starting even though my server and client are connecting and communicating properly?

The tic-tac-toe game is built using socket programming in Python. It consists of a server and a client, where the players can choose their symbols and start playing the game. The server is responsible for creating the board and handling the game's…
Rai
  • 63
  • 4
2
votes
1 answer

Incorrect output from Tic Tac Toe minimax algorithm - Python

When working on a python Tic Tac Toe algorithm to power a discord bot, I encountered an error. By the way, the algorithm is built to find the best move for X, and the top-left (first) square is 0. When using the board configuration: [1, 0, 0, 0,…
hyperrr
  • 97
  • 1
  • 9
2
votes
2 answers

Basic tic tac toe game in HTML isn't working for all winning moves

So I wanted to just make a quick tic tac toe in HTML. I threw this together and now it only works when the first row wins. It doesn't like my tie check, or any other possible winning positions. It is fine with either X or O. I tried changing the…
calebhk98
  • 157
  • 1
  • 4
  • 15
2
votes
2 answers

React child not updating a variable of parent through function

So I'm learning react at the moment and I've been struggling with this issue.. I'm trying to do tic-tac-toe so I've got this code: import './App.css'; import { useState } from "react" const X = 1; const O = -1; const EMPTY = 0; var Square = ({idx,…
yoyobara
  • 101
  • 1
  • 5
2
votes
2 answers

Infinite recursive call minimax algorithm

I have recently implemented the code for a 4X4 tic tac toe game which is using minimax algorithm. However, my minimax function is calling itself recursively infinite no. of times. Initial Board (4X4) tic tac toe -> board = np.array([['_','_','_',…
2
votes
2 answers

User defined function call on useEffect not rerturing correct output

I'm building an tic-tac-toe app in React JS, but useEffect in react behaving pretty weired for me. this is full project url: https://github.com/vyshnav4u/react-tic-tac-toe Snippet Having problem You can see that i'm calling isWinner function inside…
Vyshnav MK
  • 131
  • 1
  • 5