def shakeit(node): """ shake the tree identified by node. """ data = node.data if len(data.points) > 0: state1 = data.clone() state1.shake(1) state1.switch() node1 = tree.treenode(state1) state2 = data.clone() state2.shake(2) state2.switch() node2 = tree.treenode(state2) node.subnodes.append(node1) node.subnodes.append(node2) else: return for n in node.subnodes: shakeit(n)
node2 = tree.treenode(state2) node.subnodes.append(node1) node.subnodes.append(node2) else: return for n in node.subnodes: shakeit(n) possibility = 0 def printdata(data): global possibility possibility = possibility + 1 print "a_points:", data.a_points print "b_points:", data.b_points winner = "a" if data.a_points[-1] == 10 else "b" print "winner is:", winner if __name__ == "__main__": global possibility initstate = state.state() rootnode = tree.treenode(initstate) shakeit(rootnode) tree.traverse(rootnode, printdata) print "total possibility:", possibility print "total instances:", state.state.instancecounter