Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerate list of possible moves Python Tic-Tac-Toe
    primarykey
    data
    text
    <p>I am currently working on a project for one of my classes where I have to implement an AI opponent to play tic-tac-toe using minmax and Alpha-Beta minmax algorithms to determine the moves. </p> <p>The problem I am having however is attempting to generate a list of possible moves for a board.</p> <p>My problem code is as follows</p> <pre><code>def genMoves(genBoard, turnNumber): moveList = [] print "inMovesList" #Figure out if X or O go now if turnNumber % 2 == 0: moveChar = "O" else: moveChar = "X" i = 0; while i &lt; 9: tempBoard = genBoard if tempBoard[i] == "*": #set tempBoard[i] to X or O tempBoard[i] = moveChar #append move, new board moveList.append((i, tempBoard)) i+=1 print "MovesList: " print moveList return moveList </code></pre> <p>My board is represented as a list of 9 strings initialized to <code>["*", "*", "*", "*", "*", "*", "*", "*", "*"]</code>.</p> <p>My goal is to have move list return a list of tuples with the first element of the tuple being i (Where the X or O was inserted) and the second element being the resulting board.</p> <p>The problem I have is that I will recieve a list with the correct number of possible moves (Eg: If I manually play the first 4 moves for both sides it will only give me 5 possible moves) however it will place the same move in each location that contains a *. (So it ends up generating something like X,O,O,O,O,O,O,O,O for possible second moves)</p> <p>This is not the first time I have had to use minmax but it is the first time I've had to do it in python.</p> <p>Any suggestions for how to get around this issue would be helpful!</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload