tic-tac-toe

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

这一生的挚爱 提交于 2019-12-06 16:44:43
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"] + "|" + board["top-m"] + "|" + board["top-r"]) print("--------") print( board["mid-l"] + "|" + board["mid

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

本小妞迷上赌 提交于 2019-12-06 08:20:00
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 decide what steps to take in order to win (I still need to figure out the decision part, but I'm holding

Detect winning game in nought and crosses

南楼画角 提交于 2019-12-05 04:53:06
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? 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...so you just need to check to see if there are 5 (or however many) in a row/column/diagonal around the move

TicTacToe strategic reduction

拥有回忆 提交于 2019-12-04 18:17:41
问题 I decided to write a small program that solves TicTacToe in order to try out the effect of some pruning techniques on a trivial game. The full game tree using minimax to solve it only ends up with 549,946 possible games. With alpha-beta pruning, the number of states required to evaluate was reduced to 18,297. Then I applied a transposition table that brings the number down to 2,592. Now I want to see how low that number can go. The next enhancement I want to apply is a strategic reduction.

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

好久不见. 提交于 2019-12-03 16:42:22
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 ); // add a 'PLAYER' mark to an arbitrary location Minimax.minimax( board, Mark2.COMPUTER ); // will always

Suggestion on Tic Tac Toe

假装没事ソ 提交于 2019-12-03 13:42:51
问题 I am designing my implementation strategy for Tic-Tac-Toe game. Since this is my 1st game implementation, I am a bit confused and need some general pointers. Now, the total number of winning combinations in a Tic-Tac-Toe are 8. Currently, I plan to store these winning combinations in an array. Once the end user has made at least 3 moves, I would start checking if the Player has won the game by comparing the current positions used by a Player against this array. However, I am sure this is not

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

…衆ロ難τιáo~ 提交于 2019-12-03 11:56:08
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 scores for all game positions so that I can also sometimes pick the second best score instead of the

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

陌路散爱 提交于 2019-12-03 09:39:27
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 number of cases to consider for a perfect solution is very very high and thus not feasible. I don't think

Tic Tac Toe recursive algorithm

六眼飞鱼酱① 提交于 2019-12-03 07:08:56
I can see this question (or a similar one) has been asked a few times and I've searched google a lot so that I can try to understand it however I am most definitely stuck. My task is to use a recursive function that uses a "goodness" variable to determine which is the best move a computer can make, I even have a document that is meant to help with this but for the life of me, I just don't understand it. If anyone could take some time to help me or break down what I actually need to do i'd be much appreciating, I'll link the code I have so far below but this is an assignment so guidance is

TicTacToe AI Making Incorrect Decisions

烈酒焚心 提交于 2019-12-03 06:14:49
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 for my first time trying an AI. Now when I first implemented the AI, I went back and added two fields to