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 to simulate turns between players using while loops in Python

So I am making a simple tic tac toe game and I am having difficulty trying to figure out how to make sure that each player's moves alternate. I tried using two while loops with a boolean value which is supposed to change once each loop is executed.…
Tom_G_99
  • 461
  • 1
  • 5
  • 13
2
votes
1 answer

Undo Button in Tic tac toe app Using ReactJS

I am trying to build an undo button in tic tac toe app built using reactJS for which I followed a tutorial in Youtube: Following is my file: App.js import React, { Component } from 'react'; import PropTypes from 'prop-types'; import…
2
votes
1 answer

Need help to draw a X for Tic Tac Toe in p5.js

I was following a tutorial on Youtube (The Coding Train) which was making a minesweeper game. I followed the video until I had make a X. I want to make to lines that cross each other and form a big x like this: The board with a X The problem I have…
Lambda
  • 23
  • 3
2
votes
1 answer

Tic tac toe in JavaScript with minimax algorithm giving error maximum call stack size exceed

I am doing an assignment tic tac toe game. My minimax algorithm works fine on its own with an array and two players provided but when working with html collections of divs it gives an error of maximum call stack size exceed. I don't understand why…
J Akhtar
  • 669
  • 1
  • 7
  • 25
2
votes
1 answer

Checking the if current player has won the game of Tic Tac Toe in JavaScript

I am making a simple Tic Tac Toe with html CSS and JavaScript. No computer AL player implemented. Just two players taking turns. My checkWinner function is not working and I have no clue how to determine a winner. Somebody suggested that I create…
J Akhtar
  • 669
  • 1
  • 7
  • 25
2
votes
1 answer

Monte Carlo Tree Search - "most promising" move function

I tried to implement tic-tac-toe hello-world MCTS game player but I encountered a problem. While simulating the game and choosing "the most promising" (exploit/explore) node I only take total wins number into account ("exploit" part) - this causes…
2
votes
1 answer

My Tic Tac Toe App has a bugg

public class MainActivity extends AppCompatActivity { // 0=yellow and 1= red int activePlayer =0; boolean gameIsActive=true; // 2 means unplayed int[] gameState ={2, 2, 2, 2, 2, 2, 2, 2, 2}; int [][] winningPositions = {{0,1,2}, {3,4,5},…
2
votes
2 answers

Borders on some sides

I am coding a client for a tic-tac-toe variant. The game logic changes are not relevant to this question I am trying to show a 'hash-tag' tic-tac-toe grid like the one below. I initially thought of using borders on the buttons, or the frames…
speedstyle
  • 142
  • 4
  • 11
2
votes
1 answer

Print 2d array as a literal "array of arrays" (read description)

This is a pretty niche problem, so please hear me out. The Situation I'm coding an Ultimate Tic Tac Toe game for the command line. I have a 2d char[9][9] array called currentState where each sub-array, which holds 'X', 'O', or ' ', represents a…
Jackson H
  • 171
  • 10
2
votes
2 answers

How to code win/tie conditions in TicTacToe game in python

I have made the main-game mechanics for the TicTacToe game; however, I don't know a way to code the end-game win conditions, i.e. How to find when someone wins/ties. I tried using the all() function, but either this did not work, or I used it…
AJ123
  • 194
  • 2
  • 14
2
votes
1 answer

How to add content inside div with angular without using jquery

I'm trying to build a basic tic tac toe game in angular 1. When I click on a square I want to either add X or O depending on the turn. I cannot figure out how to do that. I can do it in jquery but I want to do it in angular.
2
votes
1 answer

Will alpha-beta pruning remove randomness in my solution with minimax?

Existing implementation: In my implementation of Tic-Tac-Toe with minimax, I look for all boxes where I can get best result and chose 1 of them randomly, so that the same solution isn't displayed each time. For ex. if the returned list is [1, 0 , 1,…
The_Coder
  • 321
  • 5
  • 18
2
votes
1 answer

C++ console TicTacToe: Checking Win Conditions

The game board is stored as a 2D char array. The Player moves his cursor around the board using the numpad, and chooses with the enter key- current position of the cursor is stored in two ints. After each move, the board is evaluated for a win using…
Luke
  • 86
  • 4
2
votes
0 answers

Alpha Beta Pruning Root Method

I am writing a simple game engine that can play games like Chess and Checkers and I'm not sure if I'm implementing the root method of alpha beta function correctly. This is the regular function: double AlphaBeta(GameState gameState, int depth,…
Terry Anderson
  • 117
  • 1
  • 1
  • 8
2
votes
6 answers

Tic-Tac-Toe: How to populate decision tree?

I'm making a Tic-Tac-Toe program. I plan to use minimax with it. I made a tree with space for all possible game sequences and I'm looking for a way to populate it. I currently have this type: typedef struct name { char grid [3] [3]; struct…
AndrejaKo
  • 1,721
  • 5
  • 25
  • 41