I am trying to create a class that generates a decision tree for a board from the Game Tic-Tac-Toe. I am using the comment from the user "ssoler" on the post Tic-Tac-Toe: How to populate decision tree? as the basis for the class however I don't think the class is working. For one I cannot see all the outputs as idle abbreviates them by using "...". Also my use of classes and recursion in the past is poor. I am aiming to apply the Minimax algorithm and alpha-beta pruning to the tree outputted by the class.
win_comb=((0,1,2),(3,4,5),(6,7,8),(6,3,0),(7,4,1),(8,5,2),(6,4,2),(8,4,0))
Board = [1, 2, 3, 4, 5, 6, 7, 8, 9]
whose_move = 1
child_nodes = []
class Node():
def __init__(self,Board,win_comb,whose_move, child_nodes):
self.c_g_s = Board
self.node = None
self.new_node = None
self.child_nodes = child_nodes
self.win_comb = win_comb
self.w_m = whose_move
def create_tree(self):
for index,each in enumerate(self.c_g_s):
if each == index + 1:
self.new_node = self.c_g_s
if self.w_m == 1:
self.new_node[index] = "X"
self.w_m = 0
else:
self.new_node[index] = "O"
self.w_m = 1
self.new_node = tuple(self.new_node)
if self.available_moves():
self.new_node = self.c_g_s
self.child_nodes.append(self.create_tree())
else:
child_nodes.append(self.new_node)
if self.child_nodes:
return [self.node,self.child_nodes]
return
def available_moves(self):
for index, each in enumerate(self.c_g_s):
if index + 1 == each:
return False
return True
n = Node(Board,win_comb,whose_move,child_nodes)
print(n.create_tree())