示例#1
0
def player_from_number(count):
    modifier = signum(count)

    if modifier == 0:
        return None

    return 'w' if modifier == 1 else 'b'
示例#2
0
def verify_move(board, position, distance, player):
    distance = distance * player_modifier(player)
    new_position = position + distance

    if position not in board_range() \
            and position != jail_field(player):
        return False

    if distance not in valid_distance(player):
        return False

    if position in board_range() \
            and signum(board[position]) != player_modifier(player):
        return False

    if position == jail_field(player) \
            and board[jail_field(player)] == 0:
        return False

    if board[jail_field(player)] and position != jail_field(player):
        return False

    if goes_offboard(player, new_position):
        for field in board[non_home_fields(player)]:
            if player_from_number(field) == player:
                return False

    if not goes_offboard(player, new_position) \
            and board[new_position] * player_modifier(enemy(player)) > 1:
        return False

    return True
示例#3
0
def make_move(board, position, distance, player):
    if not verify_move(board, position, distance, player):
        return None

    new_position = position + distance * player_modifier(player)
    board = board.copy()
    checker = player_modifier(player)

    board[position] -= checker
    if new_position in board_range():
        if signum(board[new_position] == player_modifier(enemy(player))):
            board[jail_field(enemy(player))] += board[new_position]
            board[new_position] = 0
        board[new_position] += checker

    return board