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

How can I DRY out this Ruby code in my Tic-Tac-Toe game? (Uses a 1.times block!)

I'm wondering if anybody can help me out with this...I'm sure it's one of those forehead-slapping things...but I can't figure out how to DRY this bit up. I'm making a Tic-Tac-Toe program as a learning exercise. I'm actually finished, but there's a…
globewalldesk
  • 544
  • 1
  • 3
  • 18
2
votes
1 answer

Java: Tic-Tac-Toe - How To AVOID Repeated Cell From Being Input By User?

How do I prevent the same tic tac toe coordinate from being inputted by the user? The user input is taken at the main method in the Game Class. The tic tac toe cells with [x, y] coordinates ranging from (0-2) can be either: 0(_), 1 (X) or 2 (O) Grid…
Tai
  • 53
  • 1
  • 7
2
votes
1 answer

TicTacToe suggested move

Things which cannot be changed: enum CellLocation{TOP_LEFT,TOP_CENTER,TOP_RIGHT,CENTRE_LEFT, .. and so on} enum CellState{OCCUPIED_BY_X,OCCUPIED_BY_O,EMPTY} A gameboard interface, which only contain one method: CellState getCellState(CellLocation…
user2025303
2
votes
0 answers

Bug in negamax algorithm related to evaluation function? Works some times, not others

I'm trying to develop a Tic-Tac-Toe game with an unbeatable AI and am at a point where my negamax function returns correct output most of the time. At times, though, under certain predictable conditions, the computer chooses a board move that…
Daabd00b
  • 21
  • 2
2
votes
1 answer

Having trouble restarting logic Tic Tac Toe game (JavaScript)

I am having trouble to look where the problem is. I was able to create the game board and I will be implementing AI soon. For now, I need to make it work so that everytime the game is over, it will restart a new one and resume. However when it…
Alejandro
  • 2,266
  • 6
  • 35
  • 63
2
votes
2 answers

Tkinter : Button in frame not visible

I'm trying to implement a TicTacToe program. I am an absolute beginner in python. After viewing many tutorials and reading a few books, I have understood the basics of Python. I'm trying to get the buttons to display in a frame, but all I get is a…
m s
  • 23
  • 5
2
votes
1 answer

Tic Tac Toe in Javascript - winners issue

I'm experimenting with a Javascript Tic-Tac-Toe game. It works fine in all aspects except for one sequence and am not sure why this error happens. The basic structure is that each tile sends an ID number and onclick ,the tile gets the x/o, the…
vaspv
  • 25
  • 6
2
votes
0 answers

Tic Tac Toe region ROI open cv c++

Well this is the problem. I should make graphic display of video where someone is playing tic tac toe. I detected lines on frame using HoughLinesP, but now I should make 9 ROI for nine cells in grid to detect what is where drawn.How should I do ti,…
Kristina Vakarov
  • 181
  • 3
  • 12
2
votes
1 answer

DFA for a Tic Tac Toe Game

I'm suppose to make a c++ program that makes a DFA for Tic Tac Toe, accepting first player wins only. I have working code and it is generating a DFA. I also have a function that is counting the number of states. I'm getting 2,203,642 states, but I'm…
2
votes
3 answers

Test for possible wins in tictactoe game

I'm creating a tictactoe game, and every move I need to test whether a player has won or not, and it's giving me a lot of trouble. I have a 2d vector of all the possible win combinations: vector> possibleWins…
123
  • 8,733
  • 14
  • 57
  • 99
2
votes
0 answers

Minimax Tic Tac Toe Javascript game wont play intelligently

Good Afternoon, can someone please help me figure out why my Tic Tac Toe javascript game wont play intelligently...meaning that it shouldn't let me win. I've spent hours on this and still cant figure it out. Here is the link to my…
2
votes
1 answer

Tic Tac Toe 'X' is not appearing until after 2nd 'O' has been clicked

Hello I have been working on a Tic Tac Toe application in Java and I have it working, but my issue is that when I play against X the X is not visible after I click the spot to place the first O. The X is there but it is not visible until after I…
Plam
  • 381
  • 1
  • 12
2
votes
4 answers

I'm learning C, and have made up a Tic Tac Toe table. Now, how can I reference the individual cells?

I'm learning C, so decided to try and make a Tic Tac Toe game, using ASCII art as the table. I don't have much yet... #include #define WIDTH 2; #define HEIGHT 2; int main (int argc, char *argv[]) { printf("Welcome to Tic Tac…
alex
  • 479,566
  • 201
  • 878
  • 984
2
votes
2 answers

Python code works in 2.7 but not in 3.5

My coursework is to create Tic Tac Toe in Python, my tutor helped me get it working in 2.7 however It needs to be in 3.5. Firstly in 2.7 the code below prints a 3x3 list, however in 3.5 it just prints the list downwards not 3x3. my tutor said maybe…
2
votes
2 answers

Tic-Tac-Toe without AI

I'm doing homework for UNI and I got to do a Tic-Tac-Toe without any decision taken by player, the moves are all chosen randomly. So if the character on matrix is ' ' it means it's free, while if it's 'X' or 'O' it should generate another move. This…
kHz-
  • 29
  • 7