PSEUDOCODEpy
PSEUDOCODEpy
argv[1:]
import math, re
gameBoardStr = '.'*27+'ox......xo'+'.'*27
moves = []
snapshot = False
# TOKEN
TOKEN = ['x', 'o']
token_lookup = {'x':0, 'o':1}
tok_indx = len([t for t in gameBoardStr if t=='.'])%2
def a1toind(a1):
if a1 == '-S':
return(a1)
return (int(a1[1])-1)*8 + (ord(a1[0].lower())-97)
# MOVES
if args:
moves = [arg for arg in args if not re.findall(r"^-\d+$", arg) ]
moves = [int(arg) if arg.isdigit() else a1toind(arg) for arg in moves if arg ]
# CONSTRUCT NEIGHBORS
res = traceOut(
direction,
neighbors[location][direction],
gameBoardStr,
test_piece
);
if res:
return [location] + res // (i.e. append the result upwards to produce a
list of all results)
return []
return flip_map
flip_map = boardToMoves(gameBoardStr,TOKEN)
printMoves(gameBoardStr, flip_map, TOKEN)
for m in moves:
# IF THE MOVE IS NOT ACTUALLY PLAYABLE, TRY IT FOR THE OTHER COLOR
if m not in flip_map:
CHANGE THE TOKEN FROM x to o (OR VICE VERSA), then
flip_map = boardToMoves(gameBoardStr,TOKEN)
print('')
print(f"{TOKEN} plays to {m}")
# -------------------------------
# FILL THE BOARD W/ NEW PIECE !!!
# ---
for s in flip_map[m]:
gameBoardStr[s] = TOKEN
if flip_map:
# IF THERE ARE ACTUALLY PLAYABLE MOVES FOR THIS LOCATION, PRINT THEM
printMoves(gameBoardStr, flip_map, TOKEN)
else:
# ELSE, THERE AREN'T MOVES - SO TRY THE OTHER PIECE
CHANGE THE TOKEN FROM x to o (OR VICE VERSA), then
flip_map = boardToMoves(gameBoardStr,TOKEN)
printMoves(gameBoardStr, flip_map, TOKEN)