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

Something going wrong with 3d array

I have an 2d array that represent a tic tac toe board. And empty box is just "" ; My current game board is saved in ar1 which is 2d string array. I want to make an array of game boards which is array of 2d array = 3d array. So I guess it would be…
Imri Persiado
  • 1,857
  • 8
  • 29
  • 45
2
votes
0 answers

Tic Tac Toe in Python(Graphic window)

My program i have to write isnt a generic tic tac toe instead the user gets to decide the window size and how many squares per side. Im having trouble getting the X and O to display in the center of each square. I can get the correct amount of X…
user1786698
  • 61
  • 1
  • 3
2
votes
3 answers

Array's value is changed for no ostensible reason

I'm trying to embed a very basic AI in a game of Tic Tac Toe and I'm running into a problem with the arrays that I use to discern the most suitable square to claim. I have one array that represents the game grid in its current state and another…
Dinguz
  • 23
  • 2
2
votes
3 answers

How I do check_game_state method in tictactoe game?

I want to understand whether the game is finished or drawn or still playable. But I want to do it with dynamic code. For example I do it static for 3*3 tictactoe game like this : private static boolean check_game_state(char[] board) { if ( …
CompEng
  • 7,161
  • 16
  • 68
  • 122
2
votes
1 answer

Reset Application with Swing button

Trying to reset the buttons with a "Play again" JButton. import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.awt.Toolkit; import java.awt.Image; public class HW4_TicTacToePanel extends JFrame implements ActionListener…
Daishi100
  • 43
  • 1
  • 6
1
vote
5 answers

tic-tac-toe while and ||

hi im 17 and trying to teach myself c++. For one of my first projects I am trying to write a tic-tac-toe game and play vs an AI. So the code im having trouble with is this main() { char player, computer; while (player != 'x' || player !=…
Patrick Kennedy
  • 177
  • 2
  • 2
  • 11
1
vote
3 answers

Checking for Win in Tic-Tac-Toe

Hello I'm 17 and trying to learn how to code. I am having trouble debugging this section of code and would appreciate some help. bool checkifwin(char grid[3][3], char player) { if (checkverticle(char grid[3][3], char player) ||…
Patrick Kennedy
  • 177
  • 2
  • 2
  • 11
1
vote
5 answers

How to set the score for a table in Tic Tac Toe?

I have table and some functions like Generate_moves() etc. but for the minmax algorithm to work I need to set a score for tables to make the computer choose the best table. public int Score() { if (Turn == "X") …
Dementor
  • 241
  • 1
  • 6
  • 12
1
vote
4 answers

How to draw a line programmatically?

The game tic tac toe seems to be a nice exercise for me. I want to draw the tic tac toe grid first. Interface Builder does not have a built in class for drawing lines. Therefore my question is: Which class can I use to draw the lines of the grid…
Studie
  • 799
  • 2
  • 12
  • 20
1
vote
1 answer

How can I disable clicks after winning status

I have tried so many concepts but finally not able to conclude the answer. I have made a tic-tac-toe game, which is fully functioning but I have a problem where, when I my winning status is displayed on windisplay column, after that also I am able…
Ujjawal
  • 51
  • 4
1
vote
2 answers

How do I pick position of tictactoe field by number input (0-8)?

So I'm trying to refine my high school project by trying to restart at making a Tic-Tac-Toe Neural Network. However I can't wrap my head around how to set a cross or a circle at a position in the tic-tac-toe field by inputting 0-8: class main(): …
tryg
  • 13
  • 4
1
vote
1 answer

I'm struggling with minimax algorithm in tic-tac-toe game

I'm currently trying to make a tic-tac-toe game using minimax algorithm. I'm using JavaScript with p5js framework for this project. Here is the sketch.js code: var rows = 3; var cols = 3; var scl = 1; var board_width = cols * 100 * scl; var…
Thinh Pham
  • 23
  • 3
1
vote
1 answer

Issues with JSX syntax during React's TicTacToe tutorial

While attempting React's TicTacToe tutorial (https://react.dev/learn/tutorial-tic-tac-toe) on my local development environment, I ran into this error message after copy-pasting the following from the tutorial's spec. export default function Square()…
1
vote
1 answer

Dumb TicTacToe AI (Godot 4.0)

I'd appreciate some help please folks with a (what should be) simple game in GDScript 2.0. I am making a tic-tac-toe game and Player 2 is an AI using the minimax algorith. However the AI is really dumb sometimes and just lets me win when it would…
1
vote
1 answer

Why does my tic tac toe minimax algorithm utilizing a 1d representation of a tic tac toe board and allowing for play of both sides not work?

I wrote a python program utilizing the minimax algorithm to play tic tac toe. The board is represented by a 1d array. The player is able to play as either side. The program recursively generates all of the legal boards and checks for a winner…