Ejemplo n.º 1
0
    def get_possible_moves(self, game):
        moves = []

        for (dx, dy) in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            if game.is_free(self.x + dx, self.y + dy) and game.is_free(
                    self.x + 2 * dx, self.y + 2 * dy):
                moves.append(
                    moveObj.Move(self, self.x, self.y, self.x + 2 * dx,
                                 self.y + 2 * dy))

        for (dx, dy) in ((1, 1), (1, -1), (-1, 1), (-1, -1)):
            if game.is_free(self.x + dx, self.y + dy) and (game.is_free(
                    self.x + dx, self.y) or game.is_free(self.x, self.y + dy)):
                moves.append(
                    moveObj.Move(self, self.x, self.y, self.x + dx,
                                 self.y + dy))

        # KILL MOVES

        for (dx, dy) in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            if game.is_free(self.x + dx, self.y + dy)\
                    and game.is_enemy(self.x + 2 * dx, self.y + 2 * dy, self.color)\
                    and game.board[self.y + 2 * dy][self.x + 2 * dx].is_killable(game):

                if game.is_free(self.x + 2 * dx + dy, self.y + 2 * dy + dx):
                    killed = game.board[self.y + 2 * dy][self.x + 2 * dx]
                    if type(killed).__name__ == "Mine":
                        killed = (killed, self)
                    else:
                        killed = (killed, )

                    moves.append(
                        moveObj.Move(self,
                                     self.x,
                                     self.y,
                                     self.x + 2 * dx + dy,
                                     self.y + 2 * dy + dx,
                                     removed=killed))

                if game.is_free(self.x + 2 * dx - dy, self.y + 2 * dy - dx):
                    killed = game.board[self.y + 2 * dy][self.x + 2 * dx]
                    if type(killed).__name__ == "Mine":
                        killed = (killed, self)
                    else:
                        killed = (killed, )

                    moves.append(
                        moveObj.Move(self,
                                     self.x,
                                     self.y,
                                     self.x + 2 * dx - dy,
                                     self.y + 2 * dy - dx,
                                     removed=killed))

        return moves
Ejemplo n.º 2
0
    def get_possible_moves(self, game):
        moves = []

        for dx, dy in [(x, y) for x in (-1, 0, 1) for y in (-1, 0, 1)
                       if not (x == y == 0)]:
            if game.is_free(self.x + dx, self.y + dy):
                killed = ()

                for i in range(1, game.width + game.height):
                    if game.is_free(self.x - i * dx, self.y - i * dy):
                        continue

                    if game.is_enemy(self.x - i*dx, self.y - i*dy, self.color)\
                            and game.board[self.y - i*dy][self.x - i*dx].is_killable(game):
                        killed = (game.board[self.y - i * dy][self.x -
                                                              i * dx], )
                        break
                    elif game.is_enemy(self.x - i * dx, self.y - i * dy,
                                       self.color) or game.is_ally(
                                           self.x - i * dx, self.y - i * dy,
                                           self.color):
                        break

                moves.append(
                    moveObj.Move(self,
                                 self.x,
                                 self.y,
                                 self.x + dx,
                                 self.y + dy,
                                 removed=killed))

        return moves
Ejemplo n.º 3
0
    def get_possible_moves(self, game):
        moves = []

        for (dx, dy) in [(x, y) for x in range(-5, 6) for y in range(-5, 6) if abs(x) + abs(y) <= 3 and not (x == y == 0)]:
            if not game.is_in_bounds(self.x + dx, self.y + dy):
                continue

            movedR = () if game.is_free(self.x + dx, self.y + dy) else\
                (moveObj.Move(game.board[self.y + dy][self.x + dx], self.x + dx, self.y + dy, self.x, self.y),)

            moves.append(
                moveObj.Move(
                    self,
                    self.x,
                    self.y,
                    self.x + dx,
                    self.y + dy,
                    moved=movedR
                )
            )

        return moves
Ejemplo n.º 4
0
    def get_possible_moves(self, game):
        moves = []

        for dx, dy in [(x, y) for x in (-1, 0, 1) for y in (-1, 0, 1)
                       if not (x == y == 0)]:
            if game.is_free(self.x + dx, self.y + dy):
                if self.color == 1:
                    revived = None if len(game.p1graveyard) == 0 else type(
                        game.p1graveyard[0])(self.x, self.y, self.color,
                                             game.p1graveyard[0].id)
                else:
                    revived = None if len(game.p2graveyard) == 0 else type(
                        game.p2graveyard[0])(self.x, self.y, self.color,
                                             game.p2graveyard[0].id)

                moves.append(
                    moveObj.Move(self,
                                 self.x,
                                 self.y,
                                 self.x + dx,
                                 self.y + dy,
                                 added=() if revived is None else (revived, )))

        return moves
Ejemplo n.º 5
0
    def get_possible_moves(self, game):
        moves = []

        for (dx, dy) in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            if not game.is_free(self.x + dx, self.y + dy):
                continue

            if game.is_free(self.x + 2 * dx, self.y + 2 * dy):
                moves.append(
                    moveObj.Move(self, self.x, self.y, self.x + 2 * dx,
                                 self.y + 2 * dy))

            if game.is_ally(self.x + 2 * dx, self.y + 2 * dy,
                            self.color) or game.is_enemy(
                                self.x + 2 * dx, self.y + 2 * dy, self.color):
                first = game.board[self.y + 2 * dy][self.x + 2 * dx]

                if type(first).__name__ == "Mine":
                    killed = (first, self)
                else:
                    killed = (first, )

                moves.append(
                    moveObj.Move(self,
                                 self.x,
                                 self.y,
                                 self.x + 2 * dx,
                                 self.y + 2 * dy,
                                 removed=killed))

                if type(first).__name__ == "Mine":
                    continue

                if game.is_in_bounds(self.x + 3 * dx, self.y + 3 * dy):
                    second = () if game.is_free(
                        self.x + 3 * dx, self.y +
                        3 * dy) else (game.board[self.y + 3 * dy][self.x +
                                                                  3 * dx], )

                    if len(second) > 0 and type(second[0]).__name__ == "Mine":
                        killed = (first, second[0], self)
                    else:
                        killed = (first, ) + second

                    moves.append(
                        moveObj.Move(self,
                                     self.x,
                                     self.y,
                                     self.x + 3 * dx,
                                     self.y + 3 * dy,
                                     removed=killed))

                for lr in (1, -1):  # left right
                    if game.is_in_bounds(self.x + 3 * dx + lr * dy,
                                         self.y + 3 * dy + lr * dx):
                        second = () if game.is_free(self.x + 3*dx + lr*dy, self.y + 3*dy + lr*dx)\
                            else (game.board[self.y + 3*dy + lr*dx][self.x + 3*dx + lr*dy],)

                        if len(second) > 0 and type(
                                second[0]).__name__ == "Mine":
                            killed = (first, second[0], self)
                        else:
                            killed = (first, ) + second

                        moves.append(
                            moveObj.Move(self,
                                         self.x,
                                         self.y,
                                         self.x + 3 * dx + lr * dy,
                                         self.y + 3 * dy + lr * dx,
                                         removed=killed))

                    if game.is_in_bounds(self.x + 2 * dx + lr * dy,
                                         self.y + 2 * dy + lr * dx):
                        second = () if game.is_free(self.x + 2 * dx + lr * dy, self.y + 2 * dy + lr * dx) \
                            else (game.board[self.y + 2 * dy + lr * dx][self.x + 2 * dx + lr * dy],)

                        if len(second) > 0 and type(
                                second[0]).__name__ == "Mine":
                            killed = (first, second[0], self)
                        else:
                            killed = (first, ) + second

                        moves.append(
                            moveObj.Move(self,
                                         self.x,
                                         self.y,
                                         self.x + 2 * dx + lr * dy,
                                         self.y + 2 * dy + lr * dx,
                                         removed=killed))

        return moves
Ejemplo n.º 6
0
    def get_possible_moves(self, game):
        moves = []

        for (dx, dy) in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            for i in range(1, game.height + game.width):
                if game.is_free(self.x + i * dx, self.y + i * dy):
                    moves.append(
                        moveObj.Move(self, self.x, self.y, self.x + i * dx,
                                     self.y + i * dy))
                else:
                    break

        for (dx, dy) in ((1, 1), (-1, 1), (1, -1), (-1, -1)):
            if game.is_enemy(
                    self.x + dx, self.y + dy,
                    self.color) and game.board[self.y +
                                               dy][self.x +
                                                   dx].is_killable(game):
                killed = game.board[self.y + dy][self.x + dx]
                if type(killed).__name__ == "Mine":
                    killed = (killed, self)
                else:
                    killed = (killed, )

                moves.append(
                    moveObj.Move(self,
                                 self.x,
                                 self.y,
                                 self.x + dx,
                                 self.y + dy,
                                 removed=killed))

            if game.is_enemy(self.x + dx, self.y + dy, self.color)\
                    and game.is_free(self.x + 2*dx, self.y + 2*dy)\
                    and game.board[self.y + dy][self.x + dx].is_killable(game):

                killed = game.board[self.y + dy][self.x + dx]
                if type(killed).__name__ == "Mine":
                    killed = (killed, self)
                else:
                    killed = (killed, )

                moves.append(
                    moveObj.Move(self,
                                 self.x,
                                 self.y,
                                 self.x + 2 * dx,
                                 self.y + 2 * dy,
                                 removed=killed))

            if game.is_enemy(self.x + 2*dx, self.y + 2*dy, self.color)\
                    and game.is_free(self.x + dx, self.y + dy) \
                    and game.board[self.y + 2*dy][self.x + 2*dx].is_killable(game):

                killed = game.board[self.y + 2 * dy][self.x + 2 * dx]
                if type(killed).__name__ == "Mine":
                    killed = (killed, self)
                else:
                    killed = (killed, )

                moves.append(
                    moveObj.Move(self,
                                 self.x,
                                 self.y,
                                 self.x + 2 * dx,
                                 self.y + 2 * dy,
                                 removed=killed))

        return moves