Esempio n. 1
0
    def next_action(self):
        """Return the next action this agent wants to perform.

        :return: (row, column, orientation)
        """
        start_time = time.time()
        free_lines = self.board.get_potential_moves()
        if len(free_lines) == 0:
            # Board full
            return None
        signal.alarm(self.timelimit)
        try:
            (s, value) = self.tree.get_best_move_for_set(self.moves.copy())
            if not isinstance(s, str) or self.mcts == False or s in self.moves:
                (a, b) = heuristics.find_good_move(self.board)
                signal.alarm(0)
                self.mcts = False
                if a % 2 == 0:
                    o = "h"
                    c = b
                    r = int(a / 2)
                else:

                    o = "v"
                    c = b
                    r = self.odds.index(a)
                self.heuristicmoves += 1
                elapsed_time = time.time() - start_time
                self.times_for_move.append(elapsed_time)
                return r, c, o
            else:
                signal.alarm(0)
                self.mctsmoves += 1
                r, c, o = s.split(",")
                elapsed_time = time.time() - start_time
                self.times_for_move.append(elapsed_time)
                return r, c, o
        except TimeoutException:
            (a, b) = heuristics.find_good_move(self.board)
            signal.alarm(0)
            self.mcts = False
            if a % 2 == 0:
                o = "h"
                c = b
                r = int(a / 2)
            else:

                o = "v"
                c = b
                r = self.odds.index(a)
            self.heuristicmoves += 1
            elapsed_time = time.time() - start_time
            self.times_for_move.append(elapsed_time)
            return r, c, o
Esempio n. 2
0
    def next_action(self):
        """Return the next action this agent wants to perform.

        :return: (row, column, orientation)
        """
        free_lines = self.board.get_potential_moves()
        if len(free_lines) == 0:
            # Board full
            return None
        (s, value) = self.tree.get_best_move_for_set(self.moves.copy())
        if not isinstance(s, str) or self.mcts == False or s in self.moves:
            (a, b) = heuristics.find_good_move(self.board)
            self.mcts = False
            if a % 2 == 0:
                o = "h"
                c = b
                r = int(a / 2)
            else:

                o = "v"
                c = b
                r = self.odds.index(a)
            self.heuristicmoves += 1
            return r, c, o
        else:
            self.mctsmoves += 1
            r, c, o = s.split(",")
            return r, c, o
Esempio n. 3
0
    def next_action(self):
        """Return the next action this agent wants to perform.

        :return: (row, column, orientation)
        """
        free_lines = self.board.get_potential_moves()
        if len(free_lines) == 0:
            # Board full
            return None
        move = False
        if self.mcts:
            value = 0
            for l in it.permutations(self.moves, len(self.moves)):
                go = True
                for seq in self.shouldnotstartwith:
                    li = list(l)
                    if li[:len(seq)] == seq:
                        go = False
                        break
                if go:
                    (newmove,rate) =  self.tree.get_best_move_for_set(list(l).copy())
                    if rate > value and newmove not in self.moves:
                        value = rate
                        move = newmove
                        self.mctsmoves += 1
                        r,c,o = move.split(",")
                        return r,c,o
                    else:
                        self.shouldnotstartwith.append(list(l))
                print("SHOULDNTO",self.shouldnotstartwith)
                print("MCTS POWER")
        if not isinstance(move, str) or self.mcts == False:
            (a,b) = heuristics.find_good_move(self.board)
            self.mcts = False
            if a%2==0:
                o = "h"
                c = b
                r = int(a/2)
            else:

                o = "v"
                c = b
                r = self.odds.index(a)
            self.heuristicmoves += 1
            return r, c, o
    def next_action(self):
        """Return the next action this agent wants to perform.

        :return: (row, column, orientation)
        """
        start_time = time.time()
        free_lines = self.board.get_potential_moves()
        if len(free_lines) == 0:
            # Board full
            return None
        (a, b) = heuristics.find_good_move(self.board)
        if a % 2 == 0:
            o = "h"
            c = b
            r = int(a / 2)
        else:
            o = "v"
            c = b
            r = self.odds.index(a)
        elapsed_time = time.time() - start_time
        self.times_for_move.append(elapsed_time)
        return r, c, o