예제 #1
0
 def getMove(self, game_state, depth, DEBUG=False):
     initial_node = Clone(game_state)
     moves = initial_node.find_moves()
     branches = [0] * len(moves)
     best_score = -9e99
     best_move = moves[0]
     # FIRST MOVE IS EVALUATED HERE FOR RANDOMNESS
     if depth > 0:
         for i, move in enumerate(moves):
             clone = copy.deepcopy(initial_node)
             old_usedBoxes = clone.usedBoxes
             clone.move(move)
             clone.depth += 1
             if old_usedBoxes < clone.usedBoxes:
                 branches[i] += (clone.usedBoxes - old_usedBoxes)
                 score = self.max_play(clone, depth)
             else:
                 score = self.min_play(clone, depth)
             branches[i] += score
     if DEBUG:
         initial_node.display_game()
         print branches
         print moves
     if self.random:  # RANDOM BAD AI
         rand_move = random.randint(0, num_best_moves(branches) - 1)
     else:  # TRAIN AI MAKE FIRST GOOD MOVE
         rand_move = 0
     return formatMoves(orderMoves(branches), moves)[rand_move]
예제 #2
0
 def rankMoves(self, game_state, depth, DEBUG=False):
     initial_node = Clone(game_state)
     all_moves = makeCommands(self.dim)
     legal_moves = initial_node.find_moves()
     ranks = [0] * len(all_moves)
     if depth > 0:
         for move in legal_moves:
             i = all_moves.index(move)
             clone = copy.deepcopy(initial_node)
             old_usedBoxes = clone.usedBoxes
             clone.move(move)
             clone.depth += 1
             if old_usedBoxes < clone.usedBoxes:
                 ranks[i] += (clone.usedBoxes - old_usedBoxes)
                 score = self.max_play(clone, depth)
             else:
                 score = self.min_play(clone, depth)
             ranks[i] += score
     if DEBUG:
         initial_node.display_game()
         print ranks
         print all_moves
     return ranks
예제 #3
0
    def create(self, platforms, buttons, spikes, goals, clones):
        # Adds clones that aren't part of the spawn point as platforms
        clone_list = pygame.sprite.Group()
        for platform in clones:
            block = Clone.Clone(platform[4], platform[5])
            block.rect.x = platform[2]
            block.rect.y = platform[3]
            clone_list.add(block)
        pygame.sprite.spritecollide(self.player, clone_list, True)
        for clone in clone_list:
            self.platform_list.add(clone)

        # Go through the array above and add platforms
        for platform in platforms:
            block = plat.Platform(platform[0], platform[1])
            block.rect.x = platform[2]
            block.rect.y = platform[3]
            self.platform_list.add(block)
            for button in buttons:
                if platform == button[1]:
                    but = bt.Button(self.player, clone_list, block, self)
                    but.rect.x = button[0][0]
                    but.rect.y = button[0][1]
                    self.button_list.add(but)

        for spike in spikes:
            block = sp.Spike(spike[2])
            block.rect.x = spike[0]
            block.rect.y = spike[1]
            self.spike_list.add(block)

        for goal in goals:
            block = gl.Goal(goal[0], goal[1])
            block.rect.x = goal[2]
            block.rect.y = goal[3]
            self.goal_list.add(block)
예제 #4
0
 def check_ending_chain(self, game_state, current_score, DEBUG=False):
     initial_state = Clone(game_state)
     initial_state.plus(current_score)
     self.ENDING_SEQUENCE = self.continue_chain(initial_state)
     if DEBUG:
         G.display_game()