tic-tac-toe

TicTacToe and Minimax

眉间皱痕 提交于 2020-06-01 06:08:00
问题 I am a young programmer that is learning python and struggling to implement an AI (using minimax) to play TicTacToe. I started watching a tutorial online, but the tutorial was on JavaScript and thus couldn't solve my problem. I also had a look at this question ( Python minimax for tictactoe ), but it did not have any answers and the implementation was considerably different from mine. EDIT: the code you will find below is an edit suggested by one of the answers (@water_ghosts). EDIT #2: I

TicTacToe and Minimax

六眼飞鱼酱① 提交于 2020-06-01 06:04:55
问题 I am a young programmer that is learning python and struggling to implement an AI (using minimax) to play TicTacToe. I started watching a tutorial online, but the tutorial was on JavaScript and thus couldn't solve my problem. I also had a look at this question ( Python minimax for tictactoe ), but it did not have any answers and the implementation was considerably different from mine. EDIT: the code you will find below is an edit suggested by one of the answers (@water_ghosts). EDIT #2: I

Tic Tac Toe diagonal check

天大地大妈咪最大 提交于 2020-05-15 22:44:30
问题 I'm building a game of Tic-Tac-Toe, and I have a vertical and horizontal check that look like this: def check_win_left_vert (board): win = True x = 0 for y in range (2): if board[y][x] != board[y+1][x]: win = False return win It looks through the board by incrementing the y axis; I use the same method for the x axis. How would I do this for a diagonal axis? Would I increment both? 回答1: You would use the same variable for both on one diagonal, and "2 invert" it on the other: for x in range(2):

Tic Tac Toe diagonal check

馋奶兔 提交于 2020-05-15 22:43:44
问题 I'm building a game of Tic-Tac-Toe, and I have a vertical and horizontal check that look like this: def check_win_left_vert (board): win = True x = 0 for y in range (2): if board[y][x] != board[y+1][x]: win = False return win It looks through the board by incrementing the y axis; I use the same method for the x axis. How would I do this for a diagonal axis? Would I increment both? 回答1: You would use the same variable for both on one diagonal, and "2 invert" it on the other: for x in range(2):

For loop question of Tic Tac Toe game in python3

守給你的承諾、 提交于 2020-03-06 11:09:08
问题 It should return True while all squares in Tic Tac Toe are filled. However, the bug of this is, if I fill the row2 column2 square, it will return True immediately. Can someone help me out? Thank you very much! :) def boardFull(self): ''' Checks if the board has any remaining "empty" squares. Inputs: none Returns: True if the board has no "empty" squares (full); False otherwise ''' check = True for row in local_board: for col in row: if col == ' ': check = False elif col != ' ': check = True

For loop question of Tic Tac Toe game in python3

ⅰ亾dé卋堺 提交于 2020-03-06 11:06:56
问题 It should return True while all squares in Tic Tac Toe are filled. However, the bug of this is, if I fill the row2 column2 square, it will return True immediately. Can someone help me out? Thank you very much! :) def boardFull(self): ''' Checks if the board has any remaining "empty" squares. Inputs: none Returns: True if the board has no "empty" squares (full); False otherwise ''' check = True for row in local_board: for col in row: if col == ' ': check = False elif col != ' ': check = True

Java - Tic Tac Toe Swing game - Errors

冷暖自知 提交于 2020-01-26 04:04:32
问题 I am making a tic tac toe game in Java and made the gui and wanted to run it to test it but am getting a few errors. I am not sure why and was hoping that someone could explain why those errors are coming up and what i should do to fix them. The errors that I am getting are as follows: Exception in thread "main" java.lang.NullPointerException at TicTacToeSwing.(TicTacToeSwing.java:84) at TicTacToeSwing.main(TicTacToeSwing.java:180) Here is my code: (please note: I have not done the

Java - Tic Tac Toe Swing game - Errors

℡╲_俬逩灬. 提交于 2020-01-26 04:04:10
问题 I am making a tic tac toe game in Java and made the gui and wanted to run it to test it but am getting a few errors. I am not sure why and was hoping that someone could explain why those errors are coming up and what i should do to fix them. The errors that I am getting are as follows: Exception in thread "main" java.lang.NullPointerException at TicTacToeSwing.(TicTacToeSwing.java:84) at TicTacToeSwing.main(TicTacToeSwing.java:180) Here is my code: (please note: I have not done the

what should i do to run this play again button, app crashes when its pressed(making a tic tac toe game)?

时光怂恿深爱的人放手 提交于 2020-01-22 03:31:25
问题 plz help me out in this problem i tried many changes that were suggested in android studio basically the problem occurs in playAgain function it crashes but it shold clear the images im the imageviews main activity package com.example.xo; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.GridLayout; import android.widget.ImageView; import android.widget.TextView; public class MainActivity

Class draw() method works when called directly, but crashes when called by another object [closed]

我是研究僧i 提交于 2020-01-17 00:34:14
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 8 years ago . I'm making a version of nine-board Tic Tac Toe. (Each move determines the board in which the opposing player must move) My standard Board draws fine with