tic-tac-toe

loop to repeat a game of tic tac toe

强颜欢笑 提交于 2019-12-12 02:24:47
问题 i wrote a code that plays tic tac toe from start to end. After the game, i need to ask the user if they want to repeat the game (yes/no), and repeat until the user enter no. I'm not sure where to implement the loop or how, so help would be appreciated. the code is as follows: import java.util.Scanner; public class bb2 { static char place1 = ' '; static char place2 = ' '; static char place3 = ' '; static char place4 = ' '; static char place5 = ' '; static char place6 = ' '; static char place7

Where's error in implementation of minimax algorithm?

让人想犯罪 __ 提交于 2019-12-12 02:19:21
问题 There is one little problem with it's implementation for a Tic-Tac-Toe game. For the following combination: ['x', 'o', 'e', 'o', ' e', 'e', 'e', ' e', 'e'] the best choice would be ['x', 'o', 'e', 'o', ' x', 'e', 'e', ' e', 'e'] but it returns as I suppose the nearest suitable one: ['x', 'o', 'x', 'o', ' e', 'e', 'e', ' e', 'e'] And in this case AI loses. Here is the code: var board = ['x', 'o', 'e', 'o', 'e', 'e', 'e', 'e', 'e']; var signPlayer = 'o'; var signAI = (signPlayer === 'x') ? 'o'

How do I take in “A1”-style row+column specifications as input?

Deadly 提交于 2019-12-12 02:14:39
问题 I am writing a TicTacToe game in C++. I am using a 2D character array to input each player's piece into a square. However, for input I am asking the user to type in A1, which will be board[0][0] and the top left corner of the game board. How do I allow the user to type in A1 but still allow that to be board[0][0] without hard coding? Also, the user can determine the board size. Min: 3x3, max: 13x16. 回答1: (Assuming the board is 3x3, or at most 9x9) Get two characters from the user, ensure the

Accepting Numbers from 1-9 TIC TAC TOE

旧巷老猫 提交于 2019-12-11 20:02:44
问题 Here's a TIC TAC TOE game i have created using Python.. import os os.system('cls') i = 0 #Exiter def exithoja(): import sys raw_input sys.exit() #Displays Win or Draw def diswin(name,grid): i = checkwin(grid) os.system('cls') viewgrid(grid) if i ==1: print name, " has won the game !!" elif i == -1: print "This Match is a draw !!" exithoja() #Checking for Win or Draw Function def checkwin(grid): i = 0 result = 0 extra=0 for i in range (1,9): #This part checks for full grid. if (grid[i] == 'X'

Javascript code to recognize all possible combinations of winning

喜欢而已 提交于 2019-12-11 05:46:48
问题 I am working on making a tic-tac-toe game for the science fair and I need help for recognizing all possible ways of finding a win rather than writing all of them down with brute force. The game mechanics were just started today and I just started learning javascript (about 5 days ago) so I might not be the best looking code and the most efficent one. Also take notice i'm not done yet as this code is not 100% finished but i'm just putting my code for anyone who would like to look as I only

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

大兔子大兔子 提交于 2019-12-11 02:01:40
问题 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 there is something wrong with if statements: The source code of Main.java: package mytictactoegame; public class Main { public static boolean playerTurn = true; public static boolean playerWon = false; public static boolean compWon = false; public

Detect winning game in nought and crosses

 ̄綄美尐妖づ 提交于 2019-12-10 04:04:58
问题 I need to know the best way to detect a winning move in a game of noughts and crosses. Source code doesn't matter, I just need a example or something I can start with. The only thing I can come up with is to use loops and test every direction for every move a player makes, to search for e.g five in a row. Is there a faster and more efficient way? 回答1: The real easy solution is to just check from the last move made...obviously, no prior move could have won the game, or you wouldn't be here..

What algorithm would you use to solve a very large tic-tac-toe game?

早过忘川 提交于 2019-12-09 07:03:25
问题 A small (3x3, 4x4) tic-tac-toe can be easily solved by considering all the cases. But for example, you have a 30x30 tic-tac-toe. What algorithm would you use to decide the next best move in that case? Minimax + alpha-beta pruning is one way that I know. Is there some other way that is more efficient/not more efficient but cooler? I know it would not be a very interesting game to play. I said 30x30 just to ask what I wanted to i.e. which algorithms work best at these sort of games where the

TicTacToe minimax algorithm returns unexpected results in 4x4 games

a 夏天 提交于 2019-12-08 21:17:30
问题 In my method newminimax499 I have a minimax algorithm that utilizes memoization and alpha beta pruning. The method works normally for 3x3 games, however when I play 4x4 games I get strange, unexpected position choices for the computer. He still never loses, but he doesn't seem to be playing to win. To illustrate the problem here is a scenario from 2 games in 3x3 and 4x4. First here is a scenario from a 3x3 game where the player is X and makes the first move: This isn't bad, in fact it's what

Render Images in tic tac toe app using reactjs

前提是你 提交于 2019-12-08 10:17:27
问题 I am trying to create a simple tic tac toe app using reactjs, with two modes in it: Classic and Image , in the classic mode I have the options to display X and O , while in the Image mode, I have the options two display two images which are mentioned below. My file structure is: src components ChooseGameMode.js choosePlayer.js GameStatus.js Status.js images connery.svg square.svg App.css App.js index.css index.js ... Following is the code that I developed: App.js import React, { Component }