def way_costs(op, state):
    step = abs(state[op[0]][0] - op[1][0])
    if is_white(op[0]) and op[1][0] < state[op[0]][0]:
        step *= 2
    elif not is_white(op[0]) and op[1][0] > state[op[0]][0]:
        step *= 2

    return step
Exemple #2
0
def heuristic_knocked(state):
    h = 0
    for i in range(8):
        for j in range(1, 4 + 1):
            if is_white(i) and is_knock((5, j), state[i]):
                h += 1
            if not is_white(i) and is_knock((1, j), state[i]):
                h += 1

    return h
Exemple #3
0
    def get_state(self):
        '''Print Transferred status in "chess board".'''
        chess_board = [["  "] * 4 for i in range(5)]
        chess_board_str = []

        for i in range(8):
            if is_white(i):
                chess_board[self.state[i][0] - 1][self.state[i][1] -
                                                  1] = "♗{id}".format(id=i)
            else:
                chess_board[self.state[i][0] - 1][self.state[i][1] -
                                                  1] = "♝{id}".format(id=i)

        chess_board_str.append('\n{space}{list}'.format(
            space=' ' * 5,
            list='   '.join([' ' + str(i) for i in range(1, 4 + 1)])))
        chess_board_str.append(' ' * 3 + '-' * 21)

        for i in range(5):
            chess_board_str.append(' {row} | {list} |'.format(
                row=i + 1, list=' | '.join(chess_board[i])))
            chess_board_str.append(' ' * 3 + '-' * 21)
        chess_board_str.append('')

        return '\n'.join(chess_board_str)
Exemple #4
0
def heuristic_distance(state):
    h = 0
    for i in range(8):
        if is_white(i):
            h += 5 - state[i][0]
        else:
            h += state[i][0] - 1

    return h
Exemple #5
0
def heuristic_wrong(state):
    h = 0
    for i in range(8):
        if is_white(i):
            if state[i][0] == 1:
                h += 2
            if state[i][0] != 5:
                h += 1
        else:
            if state[i][0] == 5:
                h += 2
            if state[i][0] != 1:
                h += 1

    return h
Exemple #6
0
def print_state(state):
    '''Print Transferred status in "chess board".'''
    chess_board = [["  "] * 4 for i in range(5)]

    for i in range(8):
        if is_white(i):
            chess_board[state[i][0] - 1][state[i][1] -
                                         1] = "♗{id}".format(id=i)
        else:
            chess_board[state[i][0] - 1][state[i][1] -
                                         1] = "♝{id}".format(id=i)

    print('\n{space}{list}'.format(
        space=' ' * 5,
        list='   '.join([' ' + str(i) for i in range(1, 4 + 1)])))
    print(' ' * 3 + '-' * 21)

    for i in range(5):
        print(' {row} | {list} |'.format(row=i + 1,
                                         list=' | '.join(chess_board[i])))
        print(' ' * 3 + '-' * 21)
    print('')