Пример #1
0
def cpu_move():
    global board, decision, last, first, current, moving, cpucaptured
    if moving: return
    if first:
        first = False
        decision = ai.decide(board, cpu)
        cpucaptured = logic.captured(board, decision[1], decision[2][0])
        board.remove(cpucaptured)
        board.move(decision[1], decision[2][0][0])
        last = decision[2][0][0]
        grid.move(decision[1], decision[2][0][0])
        moving = True
    else:
        grid.remove(cpucaptured)
        chain = decision[2]
        del chain[0]
        if chain:
            cpucaptured = logic.captured(board, last, chain[0])
            board.remove(cpucaptured)
            board.move(last, chain[0][0])
            grid.move(last, chain[0][0])
            last = chain[0][0]
            moving = True
        else:
            first = True
            current = player
            board.children = ai.successors(board, player)
Пример #2
0
                else:
                    print '  ',
            print '\n'
    
    def colored(self, color):
        """ Return a list of positions for the stones with given color. """
        colored = []
        for i in range(5):
            for j in range(9):
                if self[i][j] == color:
                    colored.append((i,j))
        return colored
    
    def terminal(self):
        if not self.colored(BLACK) or not self.colored(WHITE):
            return True
        return False
    
    def copy(self):
        """ Returns a deep copy of self. """
        b = Board()
        b.stones = [sub[:] for sub in self.stones]
        b.moves = copy.deepcopy(self.moves)
        return b
             
if __name__ == '__main__':
    b = Board()
    b.calcmoves()
    b.display()
    ai.decide(b, BLACK)
Пример #3
0
                        turn_id = take_turn(turn_id)

            if pos_ != 0:

                if turn(pos_, turn_id, matrix):
                    Bhev.moved(players[turn_id])

                turn_id = take_turn(turn_id)

        else:
            # AI

            obs = ai.observe(players[turn_id], matrix, players)
            ai.orient(players[turn_id], matrix, obs)
            ai.decide(players[turn_id], matrix, obs)
            ai.act(players[turn_id], matrix, obs)

            turn_id = take_turn(turn_id)

        # Groom world Draw
        for i in grid.keys():
            for k, v in grid[i].items():

                pygame.draw.rect(screen, v["color"], v["coord"], v["filled"])

        pygame.draw.rect(screen, en.black,
                         [0, screen_size[1], display_size[0], display_size[1]])

        turn_display(
            f"{players[turn_id]['name']}    Moves:  {total_moves}/{MAX_MOVES}")