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
1 answer

Tic Tac Toe turn issues C#

I'm in a basic programming class and right now we're suppose to code in a program that simulates playing tic tac toe. In my code I plan to let the person choose if they want to watch the simulated game or if they want to play, in which it'll then be…
Lyght
  • 49
  • 8
2
votes
1 answer

While loop is going one too far

So the problem I'm having is this: When a win condition is met the program should stop the while loop and just display the win/lose/draw message, but instead it allows the X and O of the game to take one more turn and I'm rather at a loss as to why.…
llyando
  • 35
  • 4
2
votes
2 answers

jQuery Tic Tac Toe program chooses both combinations when it should only choose one

I built a little tic-tac-toe program with jQuery. The purpose of the game is to give CPU the first go, and to make it impossible to win. It works to an extent, but there may be bugs I don't know about. The main problem is that, when the CPU can…
alanbuchanan
  • 3,993
  • 7
  • 41
  • 64
2
votes
2 answers

Tic Tac Toe Alpha Beta Minimax

I have been working on a tic tac toe program in order to better understand how the minimax algorithm works. The following implementation is not working correctly, as the computer can loose the game. If the program is working correctly, than in…
user1334130
  • 1,131
  • 3
  • 18
  • 25
2
votes
3 answers

My tic-tac-toe Python game doesn't end when a player wins

Good day. I'm currently reading Michael Dawson's book Python for the Absolute Beginner. I have this code for Chapter 6 and when I ran the code and got the straight "X" in the board, it won't return the winner. The program continues until all the…
John Cruz
  • 127
  • 8
2
votes
0 answers

How to get the AI best move using minimax with alpha beta pruning

I am implementing a simple TicTacToe game just to try out the Minimax with Alpha Beta pruning algorithm and I got stucked... The problem I'm facing is: The AI is not responding correctly to the player last move and I can't figure out where is my…
2
votes
1 answer

Tic-tac-toe A.I. in Java using minimax doesn't work

I'm trying to build A.I. for Tic-tac-toe using minimax algorithm but it returns weird moves - sometimes it just returns what I think is first available move (top left, top mid, top right...), but other times it just returns what seems like "random"…
David Mašek
  • 913
  • 8
  • 23
2
votes
2 answers

Optimize tic tac toe checks

For a project of mine, I have to do a tic-tac-toe solver, and I would like to just ask for some help optimizing some code. Task: Depending on the winner( x or o) , return the appropriate result How I did It: I checked Horizontal, vertical, and…
Martin
  • 231
  • 2
  • 11
2
votes
1 answer

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException if-statement

I'm developing a tic tac toe game and have one problem - Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException, it occurs when i try to press the button. The buttonText is changed to X, but after that i get the problem. I believe…
2
votes
7 answers

Python: does it make sense to refactor this check into its own method?

I'm still learning python. I just wrote this method to determine if a player has won a game of tic-tac-toe yet, given a board state like: '[['o','x','x'],['x','o','-'],['x','o','o']]' def hasWon(board): players = ['x', 'o'] for player in…
Jeff Fry
  • 410
  • 1
  • 4
  • 9
2
votes
1 answer

Trouble with 'Tic Tac Toe' Classes

I am relatively new to JS and have been working on a Tic Tac Toe game as an exercise. I think I am 90% of the way there, but I am having an annoying bug that comes up after the first play through (ie. when a new game is rendered). In this game, each…
Nicholas Haley
  • 3,558
  • 3
  • 29
  • 50
2
votes
1 answer

Is there a mathematical formula to determine how many diagonal sequences are there in a Tic-Tac-Toe game? C#

I'm building a Tic-Tac-Toe game project with C#. My teacher asked me to create an array while its size is the max number of diagonal sequences that are possible in the specific board size (Not only 3x3). Problem now, is that my teacher gave me a…
Arad55
  • 25
  • 1
  • 4
2
votes
1 answer

JavaScript Tic tac toe, how do I check for the position of the image?

I was able to create a simple html5 tic tac toe game. I'm just having trouble on how to go about checking if three X or O's are on the same line to end the game. I though maybe I should compare the image source so I saved it to a multidimensional…
2
votes
1 answer

Pretty good heuristic evaluation rules for big TicTacToe 5x5 board

I have created TicTacToe game. I use minmax algorithm. When the board is 3x3 I just calculate every possible move for a game till the end and -1 for loss, 0 for tie, 1 for win. When it comes to 5x5 it can't be done(to many options(like 24^24) so I…
Yoda
  • 17,363
  • 67
  • 204
  • 344
2
votes
4 answers

random number picker between 2 numbers

I am working on a Tic-Tac-Toe game using C++ and I was wondering if it is possible to randomize a number but it could only choose either 2 or 5. I made random start between user and the computer in order to make a fair start with these blocks of…
tuygun
  • 79
  • 3
  • 12