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

TicTacToe AI Java

So this is a college assignment and everything is pretty much done except the AI doesn't know how to "take the win" and its moves at the start aren't as random as I'd like to be as they always go top corner and work their way down. The assignment…
andrew-caulfield
  • 2,060
  • 2
  • 23
  • 24
3
votes
7 answers

Optimal algorithm for seeing who won a tick tac toe game

I have a completed tic tac toe game board. It is 3 x 3. Im not really asking for code (although that would help), but what algorithms would be best for seeing who won? Another way to phrase it would be, what algorithms should I research that would…
user489041
  • 27,916
  • 55
  • 135
  • 204
3
votes
5 answers

Choose X or O for move tic tac toe

I am making a Tic Tac Toe game and i created a function that inserts X or O into my array. I have run into one problem with my design. I call the function to make a move for X, but when it is the next players turn how do i make it call for O? Is…
soniccool
  • 5,790
  • 22
  • 60
  • 98
3
votes
1 answer

Have 2 array with 5 number between 0-8,go through array if any possible combo match the numbers in array. if yes say winner. Combos = given in my ans

Ans : var p1arr = []; var p2arr = []; const GameBoard = (() => { const PlayerFactory = (name, mark, turn) => { return { name, mark, turn } }; const player1 = PlayerFactory("Player 1", "X", true); const player2 =…
Ujjawal
  • 51
  • 4
3
votes
1 answer

My minimax algorithm loses to me, but seems flawless

I'm trying to code a tic-tac-toe bot using the minimax algorithm in python. My code seems like it should work to me, but misevaluates positions, searches too many or too few nodes and loses to me every game. mainboard = ["-", "-", "-", "-", "-",…
Alexand
  • 31
  • 2
3
votes
1 answer

Checking for a match in each element of a 2d vector

I'm creating text based TicTacToe in C++ and need to create a function that checks for a win. Right now, I have a vector of all the moves player X has made: std::vector x_vector = {1, 2, 3, 5, 7}; I also have a 2d vector of win…
Max Waters
  • 33
  • 2
3
votes
1 answer

How can I return the next move in the alpha-beta algorithm?

I'm implementing an AI to play Tic Tac Toe and I'm using the alpha-beta algorithm to search for the best move. Below is the code I have so far. I managed to make the algorithm work -- the value of the states seems to be correct, but I'm not being…
lleao
  • 65
  • 1
  • 1
  • 6
3
votes
3 answers

C++ : Help understanding what this line of code is trying to do

I am new to coding and I started with C++ in Codeacademy. This is a very basic doubt, so TIA for helping me out. The point of the program is to build a TIC TAC TOC game. I was looking to understand the solution that is available. That's where I came…
3
votes
0 answers

React useEffect dependency array: what to include

I am developing a small Tic-Tac-Toe game in react and it's working as I want it to do. Everything's fine except the es-linter and I don't want to just disable a rule as that's probably a bug. So here is one of two hooks I have, where the problem…
Oldie55
  • 31
  • 3
3
votes
0 answers

Processing: Tic Tac Toe minimax algorithm

I am currently working on a schoolproject. I am developing a classic Tic-Tac-Toe Player vs. Computer in Processing. My issue: I have tried to declare the minimax algorithm, however the Computer still follows a loop when making the next move instead…
ana
  • 97
  • 7
3
votes
1 answer

TicTacToe with MiniMax algorithm 4x4

Can anyone please tell me why the TicTacToe program gets stuck when it comes to CPU's turn in 4x4 table? When I play 3x3 version it works correctly, I play, then CPU plays, even tries its best to win. But when it is 4x4 table, I can play, but when…
3
votes
0 answers

Trying implement min max algorithm to tic tac toe. How should I implement the recursive function?

I am trying to implement a minmax algorithm that I found in javascript to my c# tic Tac toe game. I have done my best, but in my opinion the problem seems to be in the recursive function that I have been debugging for ages. This is my first time…
3
votes
1 answer

Identifying state of tic-tac-toe board from image

I'm working on a project where I have to use openCV in java to identify the state of a tic tac toe board. Please see the sample program execution below. input Output X,-,- -,O,- X,-,- I'm trying to solve this by finding contours in the image,…
Badar Khan
  • 60
  • 1
  • 7
3
votes
1 answer

How to solve Tic Tac Toe 4x4 game using Minimax Algorithem.and Alpha Beta Pruning

I made a Tic Tac Toe game, using Minimax and Alpha Beta Pruning. I wanted to make a computer AI for Tic Tac Toe (10x10) game, but Its game tree size was ridiculously large. My code is such that, I just need to change two variables to change board…
3
votes
2 answers

Minimax in Javascript not working properly

As a practice project I made a Tic-Tac-Toe game on JSFiddle (because there aren't enough already, right?) and I progressed into adding an unbeatable AI. For the most part it works, but there are some combinations (e.g. setting X into fields 5, 9, 3…
c-shark
  • 89
  • 10