tic-tac-toe

Finding the winner in Tic-Tac-Toe (Java using 2-D arrays)

情到浓时终转凉″ 提交于 2019-12-24 14:16:58
问题 I'm having trouble figuring out how to display the winner of the game in this tic-tac-toe program. import java.util.*; public class tic { public static void main(String[] args) { Scanner in = new Scanner(System.in); boolean flag=false; char[][] board = { {' ', ' ', ' '}, {' ', ' ', ' '}, {' ', ' ', ' '} }; boolean done = false; int player = 1; int row = 0; int col = 0; while (flag != true) { checkForWinner(board); System.out.println("Enter the row and column for your next move"); row = in

Questions about a tic-tac-toe program I am writing

有些话、适合烂在心里 提交于 2019-12-23 03:17:51
问题 I am making a tic-tac-toe program in python. I have two questions: How to create a trick to terminate the move() when we have created a diagonal or a line(xxx or OOO) in the game. In my program some error is occurring::in line 28::(UnboundLocalError: local variable 'stop' referenced before assignment) My code is:: import random board = {"top-l":" ","top-m":" ","top-r":" ","mid-l":" ","mid-m":" ","mid-r":" ","low-l":" ","low-m":" ","low-r":" "} def print_board(board): print( board["top-l"] + "

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

别说谁变了你拦得住时间么 提交于 2019-12-22 21:45:51
问题 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 name * child [9]; } node; and I'm looking for a way to fill grid just like it's shown here. How would I go filling the grid to make sure that all possible combinations are there? My plan is to have the game recognize every move player can take and then

Pretty good heuristic evaluation rules for big TicTacToe 5x5 board

懵懂的女人 提交于 2019-12-22 17:05:33
问题 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 have created evaluation method which gives: 10^0 for one CIRCLE inline, 10^1 for 2 CIRCLE inline, ..., 10^4 for 5 CIRCLES inline, but it is useless. Does anybody have better idea for assesment? Example: O|X|X| | | ---------- |O| | | | ---------- X|O

Using the value of a computed function for a proof in agda

跟風遠走 提交于 2019-12-22 08:24:44
问题 I'm still trying to wrap my head around agda, so I wrote a little tic-tac-toe game Type data Game : Player -> Vec Square 9 -> Set where start : Game x ( - ∷ - ∷ - ∷ - ∷ - ∷ - ∷ - ∷ - ∷ - ∷ [] ) xturn : {gs : Vec Square 9} -> (n : ℕ) -> Game x gs -> n < (#ofMoves gs) -> Game o (makeMove gs x n ) oturn : {gs : Vec Square 9} -> (n : ℕ) -> Game o gs -> n < (#ofMoves gs) -> Game x (makeMove gs o n ) Which will hold a valid game path. Here #ofMoves gs would return the number of empty Square s, n <

Tic Tac Toe with Minimax: Computer sometimes losing when Player goes first; works otherwise

旧城冷巷雨未停 提交于 2019-12-21 05:25:08
问题 I am working on a Minimax algorithm for unbeatable Tic Tac Toe. I need it to work both for when the Computer goes first as well as when the Player goes first. With the current version, the Computer will never lose when going first. However, it seems that Minimax never finds a best move (always returns -1 as the score) if the Player goes first. What is causing the Minimax score returned to be -1 for the Computer if the Player makes the first move? Example: board.addMark( 1, Mark2.PLAYER ); //

Tic Tac Toe and Minimax - Creating an imperfect AI on a microcontroller

元气小坏坏 提交于 2019-12-21 04:01:50
问题 I have created a Tic-Tac-Toe game on a microcontroller, including a perfect AI (perfect meaning that it doesn't lose). I did not use a minimax algorithm for that, just a little state machine with all possible and optimal moves. My problem now is that I wanted to implement different difficulties (Easy, Medium and Hard). The AI so far would be the hard one. So I've thought about how to do this the best way and ended up wanting to use the minimax algorithm but in a way that it calculates all the

TicTacToe AI Making Incorrect Decisions

喜夏-厌秋 提交于 2019-12-20 19:57:14
问题 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 node are boards that follow in one move. After that, I thought it would be fun to write an AI to play TicTacToe using that tree as a decision tree. TTT is a solvable problem where a perfect player will never lose, so it seemed an easy AI to code

C++ Tic Tac Toe Game

我是研究僧i 提交于 2019-12-20 08:06:17
问题 I am so confused. I am trying to create a tic tac toe game using windows c++ visual. So far I was doing good until I kept getting errors. I tried looking for help but none of the answers seemed right. This is my practice problem. Implement displayBoard to display Tic Tac Toe board. Prompt User for a box on the board to select, i.e. a number between 1 and 9 with 1 being the upper left corner. use cin.get(box) to get the box number and isdigit to verify it is a number; 1 | 2 | 3 4 | 5 | 6 7 | 8

How to determine game end, in tic-tac-toe?

我的未来我决定 提交于 2019-12-17 18:03:15
问题 I'm developing tic-tac-toe game, and I need algorithm to check when game ends(and who win). In 3x3 game I would check each possible win-situation(there is 8 capabilities). But in 7x7(needed 4 signs in a row or collumn, or diagonal)is a lot of possible win patterns. 回答1: While a very basic approach is to look at runs in all the directions from every single cell, here are an approach then only ever checks a cell in a single "line" once. A "line" is a row, column, or diagonal that can possibly