Exemple #1
0
    def _step(self, board: Board) -> Board:
        """
        Performs one hill climb step
        :param board: Current state of the board to step from
        :return: Board after the step
        """
        # select random line from unfilled ones
        unfilled = board.unfilled_by_row()
        row = list(unfilled.keys())[random.randint(0, len(unfilled) - 1)]
        line = board.values()[row]
        # swap 2 characters in it
        self._swap_in_line(line, unfilled[row])
        # update original board
        board.fill_line(row, line)

        return board
Exemple #2
0
    def _beta_operator(self, board: Board):
        """
        ß-operator of the ß-climbing, introduces exploration to the algorithm
        :param board: Neighbouring state of the board
        :return: New state of the board
        """
        # go through modifiable rows
        unfilled = board.unfilled_by_row()
        for row in unfilled:
            # regenerate the row with probability of beta
            if self._with_probability(self._beta_prob):
                line = board.values()[row]
                # clear
                for index in unfilled[row]:
                    line[index] = 0
                # refill
                board.fill_line(row, np.array(self._fill_line_unique(line)))

        return board