python - Tic Tac Toe - Finding empty grid tiles -
this continuation of previous question regarding tic tac toe game. making function collect empty grid tiles of tic tac toe board, , return them in list. function recursive, in keep looking empty grid tiles adjacent move made. this:
<-------> < x o - > < - - x > < o x - > <------->
so lets user (or in case, code wrote computer playing against computer) wants know grid tiles empty picking tile. above example, tiles numbered
0 1 2 3 4 5 6 7 8
and lets computer chose tile 1 - search adjacent tiles (so in case, top, left, right, , bottom) , see if can make moves there. if finds adjacent tile empty, finds adjacent tiles of tile well, until exhausts possibilities. want able call function current board , playermove, , find adjacent tiles empty, , append them list. tips?
def whatisempty(movelist,move): emptytiles = [] #something allows find adjacent tiles of move #something allows find adjacent tiles of tiles found above, until found
i know need couple loops this, i'm not sure how start. know want have move in middle of imaginary 3x3 grid, , find adjacent tiles see if empty, , on. in 2d list, use this:
movelist[x-1][y] movelist[x][y+1] movelist[x+1][y] movelist[x][y+1]
where each of corresponds top, right, left, , bottom, , used recursively. tips appreciated.
a recursive strategy might not best in scenario. consider example provided:
<-------> < x o - > < - - x > < o x - > <------->
suppose next move made in middle tile. if recursive function checks 4 tiles adjacent it, miss tile "cut off" rest (the bottom right one). , if write function check 8 adjacent tiles (including diagonally adjacent) might write iteratively.
for in range(3): j in range(3): pass # replace code add empty tile list
Comments
Post a Comment