Esempio n. 1
0
    def get_action(self, state):
        """ Employ an adversarial search technique to choose an action
        available in the current state calls self.queue.put(ACTION) at least

        This method must call self.queue.put(ACTION) at least once, and may
        call it as many times as you want; the caller will be responsible
        for cutting off the function after the search time limit has expired.

        See RandomPlayer and GreedyPlayer in sample_players for more examples.

        **********************************************************************
        NOTE: 
        - The caller is responsible for cutting off search, so calling
          get_action() from your own code will create an infinite loop!
          Refer to (and use!) the Isolation.play() function to run games.
        **********************************************************************
        """
        # TODO: Replace the example implementation below with your own search
        #       method by combining techniques from lecture
        #
        # EXAMPLE: choose a random move without any search--this function MUST
        #          call self.queue.put(ACTION) at least once before time expires
        #          (the timer is automatically managed for you)
        #print(self.load_q())
        choice = self.decision(state)
        debug_state = DebugState()
        debug_board = debug_state.from_state(state)
        #sys.stdout.write( str(debug_board))
        #sys.stdout.flush()
        #print(debug_board)
        self.queue.put(choice)
Esempio n. 2
0
import pickle
import queue
from isolation import Isolation, DebugState

# Loading the opening book form a pickle file
with open("data.pickle", "rb") as f:
    book = pickle.load(f)

# Creating the initial state (a blank board)
initial_statate = Isolation()

# Displaying the initial move taken by the first player
first_move_state = initial_statate.result(book[initial_statate])
print('OPENING MOVE FOR PLAYER 1')
print(DebugState().from_state(first_move_state))

# Displaying the reply taken by the second player
response_move_state = first_move_state.result(book[first_move_state])
print('BEST REPLY BY PLAYER 2')
print(DebugState().from_state(response_move_state))
Esempio n. 3
0
from isolation import Isolation, DebugState

bd = Isolation()
#board = board.result(67)
db = DebugState(bd)
print(db)
Esempio n. 4
0
    def get_action(self, state):
        """ Employ an adversarial search technique to choose an action
        available in the current state calls self.queue.put(ACTION) at least

        This method must call self.queue.put(ACTION) at least once, and may
        call it as many times as you want; the caller will be responsible
        for cutting off the function after the search time limit has expired.

        See RandomPlayer and GreedyPlayer in sample_players for more examples.

        **********************************************************************
        NOTE:
        - The caller is responsible for cutting off search, so calling
          get_action() from your own code will create an infinite loop!
          Refer to (and use!) the Isolation.play() function to run games.
        **********************************************************************
        """
        # TODO: Replace the example implementation below with your own search
        #       method by combining techniques from lecture
        #
        # EXAMPLE: choose a random move without any search--this function MUST
        #          call self.queue.put(ACTION) at least once before time expires
        #          (the timer is automatically managed for you)
        methods = ["RANDOM", "MINIMAX", "ALPHABETA_Iterative", "MCTS", "NEGASCOUT", "PVS", "PVS_Iterative", "PVS_ZWS"]
        method = "MCTS"

        printDebugMsg(DebugState(state.board))

        ply_count_threshold = 2
        # If fewer than ply_count_threshold applied on board, then choose random move.
        if state.ply_count < ply_count_threshold:
            if state.actions():
                self.queue.put(random.choice(state.actions()))
            else:
                self.queue.put(None)
        else:
            if method == "RANDOM":
                self.queue.put(random.choice(state.actions()))
            elif method == "MINIMAX":
                # Code from sample_players.py file.
                # return the optimal minimax move at a fixed search depth of 3 plies
                self.queue.put(self.minimax(state, depth=3))
            elif method == "ALPHABETA_Iterative":  # Win ~= 62.5%
                # Alpha-Beta with iterative deepening
                depth_limit = 3
                best_move = None
                for depth in range(1, depth_limit + 1):
                    best_move = self.alpha_beta_search(state, depth)
                printDebugMsg("final best_move = {}".format(best_move))
                # print("Alpha Beta Node Count = {}".format(AB_Baseline_NodeCount))
                self.queue.put(best_move)
            elif method == "MCTS":  # Win ~=
                # Use Monte Carlo Tree Search
                mcts = MCTS_Search(computational_budget=100)
                # mcts = MCTS_Search()
                action = mcts.uctSearch(state)
                # Handle case where no action was returned.
                if action:
                    self.queue.put(action)
                elif state.actions():
                    self.queue.put(random.choice(state.actions()))
                else:
                    self.queue.put(None)
            elif method == "NEGASCOUT":  # Win ~= 18%
                # Use NegaScout
                self.queue.put(self.negaScout(state, depth=5))
            elif method == "PVS":  # Win ~= 11.5%
                # Use Principal Variation Search
                self.queue.put(self.principal_variation_search(state, depth=3))
            elif method == "PVS_Iterative":  # Win ~=
                # Use principal variation search with iterative deepening.
                depth_limit = 5
                best_move = None
                for depth in range(1, depth_limit + 1):
                    best_move = self.principal_variation_search(state, depth)
                self.queue.put(best_move)
            elif method == "PVS_ZWS":  # Win ~=
                # Use Principal Variation Search
                self.queue.put(self.principal_variation_search_zws(state, depth=5))
            else:
                import sys
                sys.exit("Unknown method")
        printDebugMsg("self.queue = {}".format(self.queue))
Esempio n. 5
0
from isolation import Isolation, Agent, DebugState
from my_custom_player import CustomPlayer
import train


# main code
if __name__ == '__main__':
    board = DebugState()
    debug_board = board.from_state(board)
    test_agent = TEST_AGENTS['MINIMAX']¬
    custom_agent = Agent(CustomPlayer, "Custom Agent")¬
    wins, num_games = play_matches(custom_agent, test_agent, args)
    print(debug_board)