Exemplo n.º 1
0
def GameStartS0():

    # Start Game with S0 1 3 5 7
    board_array = np.array([" "] * 10)
    board_array[2] = "O"
    board_array[3] = "X"
    board_array[7] = "X"
    board_array[5] = "O"

    myBoard = Board(board=board_array)

    current_node = Node(
        GameState2(moves=[3, 2, 7, 5], board=myBoard, turn=4, next_turn="a"))
    uctClass = UCTSEARCH(100, current_node)
    current_node = uctClass.getCurrent_Node()

    #logger = get_module_logger(__name__)

    mylogger.debug("Num Children: %d", len(current_node.children))
    for i, c in enumerate(current_node.children):
        mylogger.debug("%d, %s", i, c)
    mylogger.debug("Best Child: %s", current_node.state)
    mylogger.debug("--------------------------------")

    G = current_node.getGraph()
    nx.draw_networkx(G)
    plt.show()
Exemplo n.º 2
0
def GameStartS0():

    # Start Game with S0 1 3 5 7
    board_array = np.array([" "] * 10)
    board_array[2] = "O"
    board_array[3] = "X"
    board_array[7] = "X"
    board_array[5] = "O"

    myBoard = Board(board=board_array)

    current_node = Node(
        GameState2(moves=[3, 2, 7, 5],
                   board=myBoard,
                   turn=4,
                   next_turn=0,
                   test=True))
    uctClass = UCTSEARCH(10, current_node)
    current_node = uctClass.getCurrent_Node()

    print("Num Children: %d" % len(current_node.children))
    for i, c in enumerate(current_node.children):
        print(i, c)
    print("Best Child: %s" % current_node.state)
    print("--------------------------------")
Exemplo n.º 3
0
    def aiPlayerAction(self):

        board_array = self.board
        myBoard = Board(board=board_array)

        current_node = Node(GameState2(moves=self.moves, board=myBoard,turn=self.turn, next_turn="a"))

        for l in range(9 - self.turn):
            uctClass = UCTSEARCH(500/(l+1),current_node)
            current_node = uctClass.getCurrent_Node()

            #print("Num Children: %d"%len(current_node.children))
            #for i,c in enumerate(current_node.children):
            #	print(i,c)
            #print("Best Child: %s"%current_node.state)
            #print("--------------------------------")

            best_state = current_node.state
            move = best_state.moves[ self.turn ]

        self.turn += 1
        self.moves.append(move)
        piece = self.aiPlayer.piece
        self.makeMove(move,piece)

        # show board....
        #print(self)

        if isWin(self.board,piece):
            print("AI WIN....")
            return 1

        return 0
Exemplo n.º 4
0
def GameStart():

    current_node = Node(
        GameState2(moves=[], board=Board(), turn=0, next_turn=0, test=True))
    uctClass = UCTSEARCH(10, current_node)
    current_node = uctClass.getCurrent_Node()

    print("Num Children: %d" % len(current_node.children))
    for i, c in enumerate(current_node.children):
        print(i, c)
    print("Best Child: %s" % current_node.state)
    print("--------------------------------")
Exemplo n.º 5
0
def GameStart():

    current_node = Node(
        GameState2(moves=[], board=Board(), turn=0, next_turn="a"))
    uctClass = UCTSEARCH(5, current_node)
    current_node = uctClass.getCurrent_Node()

    mylogger.debug("Num Children: %d", len(current_node.children))
    for i, c in enumerate(current_node.children):
        mylogger.debug(i, c)
    mylogger.debug("Best Child: %s", current_node.state)
    mylogger.debug("--------------------------------")

    G = current_node.getGraph()
    nx.draw_networkx(G)
    plt.show()
Exemplo n.º 6
0
def ssmain():

    current_node = Node(GameState2(moves=[], board=Board(),turn=0, next_turn=0,test=True))

    num_sims = 10
    for l in range(10):

        print("###  level %d  ###", l)

        uctClass = UCTSEARCH(num_sims/(l+1),current_node)
        current_node=uctClass.getCurrent_Node()
        print("Num Children: %d"%len(current_node.children))
        for i,c in enumerate(current_node.children):
        	print(i,c)
        print("Best Child: %s"%current_node.state)
        print("--------------------------------")
Exemplo n.º 7
0
def main():

    current_node = Node(GameState2(moves=[], board=Board(),turn=0, next_turn=0,test=True))
    uctClass = UCTSEARCH(2,current_node)
    current_node = uctClass.getCurrent_Node()