Ejemplo n.º 1
0
    def make_move(self, board, phase):
        old_board = self.translator.getOldBoard(board.board)
        player_char = self.translator.getCurrentPlayerChar(self.player)

        if phase == 1:
            ai_move = self.bot.getPlaceMove(old_board, player_char)
            selected_postion = self.translator.getNewPos(ai_move)
            move = Move(self.player, board.get_slot(selected_postion), None)

        if phase == 2:
            can_fly = len(board.get_all_player_slots(self.player)) == 3
            if (can_fly):
                init_place, next_place = self.bot.getFlyingMove(
                    old_board, player_char)
            else:
                init_place, next_place = self.bot.getRotateMove(
                    old_board, player_char)

            selected_init_postion = self.translator.getNewPos(init_place)
            selected_next_postion = self.translator.getNewPos(next_place)
            move = Move(self.player, board.get_slot(selected_next_postion),
                        board.get_slot(selected_init_postion))

        if move is not None:
            self.perform_move(board, move)

        return move
Ejemplo n.º 2
0
    def remove_stone(self, board):
        move = None
        is_valid_input = False
        while not is_valid_input:
            selected_slot = self.get_input_slot(
                board, "You got a mill! Select a stone to remove")
            if (selected_slot == 0):
                return selected_slot
            slot_owner = selected_slot.owner

            slots_outside_mills = board.get_player_slots_outside_mills(
                slot_owner)

            if slot_owner is None or slot_owner is self.player:
                print(
                    "\033[31mYou have to select one of your opponents stones\u001b[0m"
                )
            elif len(slots_outside_mills
                     ) > 0 and selected_slot not in slots_outside_mills:
                print("\033[31mYou have to remove stones not in a mill "
                      "before you remove stones inside a mill\u001b[0m")
            else:
                move = Move(self.player, None, selected_slot)
                is_valid_input = True

        self.perform_move(board, move)
        return move
Ejemplo n.º 3
0
    def remove_stone(self, board):
        move = None

        old_board = self.translator.getOldBoard(board.board)
        player_char = self.translator.getCurrentPlayerChar(self.player)
        ai_move = self.bot.getRemoveStone(old_board, player_char)
        selected_postion = self.translator.getNewPos(ai_move)

        move = Move(self.player, None, board.get_slot(selected_postion))
        self.perform_move(board, move)
        return move
Ejemplo n.º 4
0
 def get_player_slots_outside_mills(self, player):
     slots_outside_mills = []
     for pos in self.board:
         slot = self.board[pos]
         if slot.owner == player:
             # Detect mill requires a 'move' class
             move = Move(player, slot, None)
             # If we detected 0 mills,
             # then this slot is outside an mill
             if detect_mill(self, move) == 0:
                 slots_outside_mills.append(slot)
     return slots_outside_mills
Ejemplo n.º 5
0
 def get_input_phase1(self, board):
     move = None
     is_valid_input = False
     while not is_valid_input:
         selected_slot = self.get_input_slot(
             board, "Select a slot where you want to put your stone")
         if (selected_slot == 0):
             return selected_slot
         if selected_slot.owner is not None:
             print("\033[31mSlot is already occupied, try again\u001b[0m")
         else:
             move = Move(self.player, selected_slot, None)
             is_valid_input = True
     return move
Ejemplo n.º 6
0
    def get_input_phase2(self, board):

        can_fly = len(board.get_all_player_slots(self.player)) == 3
        is_valid_input = False

        # Checks if the inputs are of the right formats
        while not is_valid_input:

            current_position_slot = self.get_input_slot(
                board, "Pick a stone to move")
            if (current_position_slot == 0):
                return current_position_slot
            is_owner = current_position_slot.owner == self.player
            neighbouring_slots = current_position_slot.get_neighbours()
            can_move = any(slot.owner is None for slot in neighbouring_slots)

            if not is_owner:
                print("This stone is not yours. Select another.")
            elif not can_move and not can_fly:
                print("This stone can't move anywhere, pick another one")
            else:
                is_valid_input = True

        new_position_slot = None
        while new_position_slot is None:
            # Where we want to go
            if can_fly:
                chosen_slot = self.get_input_slot(
                    board, "Your stones can now fly: where do you want to go?")
                if (chosen_slot == 0):
                    return selected_slot
                if chosen_slot.owner is None:
                    new_position_slot = chosen_slot
                    break
                else:
                    print(
                        "\033[31mSlot is already occupied, try again\u001b[0m")
                    continue

            new_position = input("Choose direction to move: ")

            while new_position not in ("up", "right", "left", "down"):
                new_position = input(
                    "You can only move up, right, left, or down")

            # Get a direction attribute, i.e. top/left/right/bottom
            direction = new_position
            if (direction == "up"):
                direction = "top"
            elif (direction == "down"):
                direction = "bottom"

            new_position_slot = getattr(current_position_slot, direction)

            if new_position_slot is None:
                print("There is no board slot in this direction. Try again!")
            elif new_position_slot.owner is not None:
                print("This slot is occupied by another stone. Try again!")
                new_position_slot = None

        return Move(self.player, new_position_slot, current_position_slot)