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

TicTacToe AI Making Incorrect Decisions

A little background: as a way to learn multinode trees in C++, I decided to generate all possible TicTacToe boards and store them in a tree such that the branch beginning at a node are all boards that can follow from that node, and the children of a…
9
votes
3 answers

Compiling Issue?

I am currently working on a tic tac toe program for an assignment. The issue I am having is when I count my player (either the 'X' player or the 'Y' player), it seems to be counting both players as the same. For instance, after the third play, it…
Rich Hall
  • 225
  • 1
  • 6
9
votes
2 answers

Q Learning Algorithm for Tic Tac Toe

I could not understand how to update Q values for tic tac toe game. I read all about that but I could not imagine how to do this. I read that Q value is updated end of the game, but I haven't understand that if there is Q value for each action ?
8
votes
1 answer

Pygame Tic Tak Toe Logic? How Would I Do It

I am trying to make a tic tak toe game with pygame and I was wondering how would I do the logic here is what I have so far. VIDEO < I only have it when I click on the middle button it will display the player 2 x on the screen and then the image that…
Habib Ismail
  • 69
  • 5
  • 16
8
votes
2 answers

Q Learning Applied To a Two Player Game

I am trying to implement a Q Learning agent to learn an optimal policy for playing against a random agent in a game of Tic Tac Toe. I have created a plan that I believe will work. There is just one part that I cannot get my head around. And this…
Frederick
  • 115
  • 1
  • 10
8
votes
8 answers

Implementation of two for loops in React Js to create a 3X3 square marix box for tic-tac-toe

I'm following the React Js tutorial from the official site which helps us build a tic-tac-toe game. The square boxes are created by hardcoding all the squares as follows: render(){ return (
Aanchal Adhikari
  • 303
  • 4
  • 12
8
votes
4 answers

How to efficiently detect a tie early in m,n,k-game (generalized tic-tac-toe)?

I'm implementing an m,n,k-game, a generalized version of tic-tac-toe, where m is the number of rows, n is the number of columns and k is the number of pieces that a player needs to put in a row to win. I have implemented a check for a win, but I…
user2373682
8
votes
2 answers

Simple tic-tac-toe AI

I know this has been asked a lot and I've searched other code but most of what I've seen doesn't seem flawless (never loses) and simple, elegant and efficient. And I'm unable to decide which type of solution would fit that description. The solutions…
user1136342
  • 4,731
  • 10
  • 30
  • 40
7
votes
1 answer

Tic Tac Toe recursive algorithm

I can see this question (or a similar one) has been asked a few times and I've searched google a lot so that I can try to understand it however I am most definitely stuck. My task is to use a recursive function that uses a "goodness" variable to…
Steffan Caine
  • 165
  • 2
  • 2
  • 7
7
votes
8 answers

All Possible Tic Tac Toe Winning Combinations

I had an interview were I was asked a seemingly simple algorithm question: "Write an algorithm to return me all possible winning combinations for tic tac toe." I still can't figure out an efficient way to handle this. Is there a standard…
DroidT
  • 3,168
  • 3
  • 31
  • 29
7
votes
6 answers

Detect winning game in nought and crosses

I need to know the best way to detect a winning move in a game of noughts and crosses. Source code doesn't matter, I just need a example or something I can start with. The only thing I can come up with is to use loops and test every direction for…
Dennis
  • 79
  • 1
  • 1
  • 2
6
votes
6 answers

How to pause / resume Java Threads

I am making a Tic Tac Toe Program in java because i am learning java and i thought a simple project would be a great place to start. This is my code so far: public class Start { public static void main(String[] args) { GameTicTacToe…
Joe C
  • 1,788
  • 2
  • 17
  • 27
6
votes
2 answers

Quantum tic-tac-toe with alpha-beta pruning - best representation of states?

For my AI class, I have to make a quantum tic-tac-toe game using alpha-beta pruning. I'm thinking about the best way to represent a state of the board - my first intuition is to use a sort of neighborhood matrix, that is, a 9x9 matrix, and on M[i,j]…
6
votes
1 answer

How can I create an AI for tic tac toe in Python using ANN and genetic algorithm?

I'm very interested in the field of machine learning and recently I got the idea for a project for the next few weeks. Basically I want to create an AI that can beat every human at Tic Tac Toe. The algorithm must be scalable for every n*n board…
6
votes
2 answers

TicTacToe minimax algorithm returns unexpected results in 4x4 games

In my method newminimax499 I have a minimax algorithm that utilizes memoization and alpha beta pruning. The method works normally for 3x3 games, however when I play 4x4 games I get strange, unexpected position choices for the computer. He still…