Exemple #1
0
    def noBad5Filter(self, player, board, action):
        if (player == self.player):
            percept_board = avalam.Board(board.get_percepts())
        else:
            percept_board = avalam.Board(board.get_percepts(True))

        x1 = action[0]
        x2 = action[2]
        y1 = action[1]
        y2 = action[3]
        n1 = percept_board.m[x1][y1]
        n2 = percept_board.m[x2][y2]

        s = n1 / abs(n1)
        number = s * (abs(n1) + abs(n2))
        if (number == 5):
            return True
        else:
            for i in range(x2 - 1, x2 + 2):
                for j in range(y2 - 1, y2 + 2):
                    if (i >= 0 and i <= board.rows - 1 and j >= 0
                            and j <= board.columns - 1
                            and not (i == x1 and j == y1)
                            and not (i == x2 and j == y2)):
                        n3 = percept_board.m[i][j]
                        if (n3 != 0):
                            s2 = n3 / abs(n3)
                            number2 = s2 * (abs(n3) + abs(number))
                            if (number2 == -5):
                                return False
        #else:
        return True
Exemple #2
0
    def play(self, board, player, step, time_left):
        """This function is used to play a move according
        to the board, player and time left provided as input.
        It must return an action representing the move the player
        will perform.
        """
        """if step == 1 :
            self.passed=True
            return (3,3,4,3)
        if self.passed==False and step==2:
            return (4,3,3,3)"""
        start_time = time.time()
        self.player = player
        self.time_left = time_left
        newBoard = avalam.Board(board.get_percepts(player == avalam.PLAYER2))
        state = (newBoard, player, step)
        result = minimax.search(state, self)
        #print('towerDifferentColourFilter =', self.towerDifferentColourFilter(player,board,action))

        interval = time.time() - start_time
        self.totalTime += interval

        print('Decision Time:', interval)
        print('Total time:', self.totalTime)
        return result
Exemple #3
0
    def towerDifferentColourFilter(self, player, board, action):
        if (player == self.player):
            percept_board = avalam.Board(board.get_percepts())
        else:
            percept_board = avalam.Board(board.get_percepts(True))

        x1 = action[0]
        x2 = action[2]
        y1 = action[1]
        y2 = action[3]
        n1 = percept_board.m[x1][y1]
        n2 = percept_board.m[x2][y2]
        if (n1 > 0 and n2 < 0):
            return True
        else:
            return False
Exemple #4
0
 def play(self, board, player, step, time_left):
     """This function is used to play a move according
     to the board, player and time left provided as input.
     It must return an action representing the move the player
     will perform.
     """
     #Launch
     if (step == 1 or step == 2):
         self.gametime = time_left
     if (step == 1):
         # Hard codage de la 1�re action pour �viter une perte de temps
         return (3, 8, 4, 7)
     #Init minmax
     newBoard = avalam.Board(board.get_percepts(player == avalam.PLAYER2))
     state = (newBoard, player, step)
     self.maxMinMaxDepth = calculate_maxMinMaxDepth(
         step, time_left, self.gametime, newBoard.estimate_depth_safety())
     self.maxTimeForMinMax = datetime.datetime.now() + datetime.timedelta(
         0, getTimeSituation(step, time_left, self.gametime))
     #Debug
     print("Depth :", self.maxMinMaxDepth)
     print("Time :", getTimeSituation(step, time_left, self.gametime))
     print("Time left : ", time_left)
     #Minmax
     minmaxRes = minimax.search(state, self, time_left)
     print(minmaxRes)
     if minmaxRes == None:
         self.maxMinMaxDepth = 2
         minmaxRes = minimax.search(state, self, time_left)
     return minmaxRes
Exemple #5
0
 def play(self, board, player, step, time_left):
     """This function is used to play a move according
     to the board, player and time left provided as input.
     It must return an action representing the move the player
     will perform.
     """
     self.time_left = time_left
     newBoard = avalam.Board(board.get_percepts(player == avalam.PLAYER2))
     state = (newBoard, player, step)
     return minimax.search(state, self)
Exemple #6
0
    def BackUpFilter(self, player, board, action):
        if (player == self.player):
            percept_board = avalam.Board(board.get_percepts())
        else:
            percept_board = avalam.Board(board.get_percepts(True))

        x1 = action[0]
        x2 = action[2]
        y1 = action[1]
        y2 = action[3]
        n1 = percept_board.m[x1][y1]
        n2 = percept_board.m[x2][y2]
        isolTower = False
        s = n1 / abs(n1)
        number = s * (abs(n1) + abs(n2))
        if (number == 5):
            return True
        for i in range(x2 - 1, x2 + 2):
            for j in range(y2 - 1, y2 + 2):
                if (i >= 0 and i <= board.rows - 1 and j >= 0
                        and j <= board.columns - 1
                        and not (i == x1 and j == y1)
                        and not (i == x2 and j == y2)):
                    n3 = percept_board.m[i][j]
                    if (n3 != 0):
                        s2 = n3 / abs(n3)
                        if n3 > 0:
                            return True
                        else:
                            percept_board.m[i][j] = 0
                            percept_board.m[x1][y1] = 0
                            percept_board.m[x2][y2] = s2 * (abs(number) +
                                                            abs(n3))
                            if (not percept_board.is_tower_movable(x2, y2)):
                                isolTower = True
                            percept_board.m[x1][y1] = n1
                            percept_board.m[x2][y2] = n2
                            percept_board.m[i][j] = n3
        if (isolTower):
            return False
        else:
            return True
Exemple #7
0
    def play(self, board, player, step, time_left):
        """This function is used to play a move according
        to the board, player and time left provided as input.
        It must return an action representing the move the player
        will perform.
        """
        """if step == 1 :
            self.passed=True
            return (3,3,4,3)
        if self.passed==False and step==2:
            return (4,3,3,3)"""
        start_time = time.time() 
        self.player=player
        self.time_left = time_left
        newBoard = avalam.Board(board.get_percepts(player==avalam.PLAYER2))
        state = (newBoard, player, step)
        result=minimax.search(state,self)

        return result