# L-39 MCS 275 Mon 21 Apr 2008 : gametree.py

# Allows to generate all possible moves in the
# game of tic tac toe.

from classboard import *
from classboardtree import *

def ReadBoard():
   """
   Prompts the user for a board
   and returns it.
   """
   print 'give three characters per row'
   print '-> either X, O, or a space'
   s = ''
   for i in range(1,4):
      r = raw_input("give row %d : " % i) 
      if s != '': s = s + '\n'
      s = s + r
   b = Board()
   print s
   b.parse(s)
   return b

def main():
   """
   Reads an initial board and then shows
   all possible moves originating from it.
   """
   b = ReadBoard()
   print b.m
   t = BoardTree(b)
   k = input('player ? (1 or 2) ')
   t.moves(k,2)
   t.values(k)
   print t
   print 'recommended move :'
   print t.c[t.best].b

if __name__=="__main__": main()
