Пример #1
0
def realizar_descarga(estado, a, b, x, y):
    pos = estado.posicion[a]
    for c in estado.carga[b]:
        if c in estado.carga[b] and 'D' in a and 'T' in b and pos == y:
            return [('descargar_camion', a, b, c)]
    return False


def reparto(estado, a, b, x, y):
    if estado.conexion[x][y] == 'carretera':
        return [('conducir_camion', a, b, x, y)]
    else:
        return False


pyhop.declare_methods('gestionar_camion', realizar_carga, realizar_descarga,
                      reparto)


def moverse_a_pie(estado, a, x, y):
    if estado.conexion[x][y] == 'senda' and 'D' in a:
        return [('caminar', a, x, y)]
    return False


def moverse_en_camion(estado, a, x, y):
    pos = estado.posicion[a]
    b = estado.conduce[a] if estado.conduce[a] != '' else get_camion(
        estado, a, pos)
    print(b)
    if 'D' in a and 'T' in b:
        return [('gestionar_camion', a, b, x, y)]
Пример #2
0
def do_read(state, a, x, y):
    if not state.read_book[a]:
        return [('read_book', a)]
    return False


def dont_read(state, a, x, y):
    if state.read_book[a]:
        return []
    return False


# Indicamos cual es la descomposicion de "read_if_necessary_book"

pyhop.declare_methods('read_if_necessary_book', do_read, dont_read)

# Definicion de dos metodos para "travel". Solo uno de ellos se ejecutara como maximo


def travel_by_foot(state, a, x, y):
    if state.dist[x][y] <= 2:
        return [('walk', a, x, y)]
    return False


def travel_by_taxi(state, a, x, y):
    if state.cash[a] >= taxi_rate(state.dist[x][y]):
        return [('call_taxi', a, x), ('wait_taxi', a),
                ('read_if_necessary_book', a, x, y), ('ride_taxi', a, x, y),
                ('pay_driver', a)]
Пример #3
0
pyhop.print_operators()


def travel_by_foot(state, a, x, y):
    if state.dist[x][y] <= 2:
        return [('walk', a, x, y)]
    return False


def travel_by_taxi(state, a, x, y):
    if state.cash[a] >= taxi_rate(state.dist[x][y]):
        return [('call_taxi', a, x), ('ride_taxi', a, x, y), ('pay_driver', a)]
    return False


pyhop.declare_methods('travel', travel_by_foot, travel_by_taxi)
print('')
pyhop.print_methods()

state1 = pyhop.State('state1')
state1.loc = {'me': 'home'}
state1.cash = {'me': 20}
state1.owe = {'me': 0}
state1.dist = {'home': {'park': 8}, 'park': {'home': 8}}

print("""
********************************************************************************
Call pyhop.pyhop(state1,[('travel','me','home','park')]) with different verbosity levels
********************************************************************************
""")
Пример #4
0
        z = select_new_city(state, y)
        g = pyhop.Goal('g')
        g.final = y
        return [('travel_op', z), ('travel', g)]
    return False


def already_there(state, goal):
    x = state.location
    y = goal.final
    if x == y:
        return []
    return False


pyhop.declare_methods('travel', travel_m, already_there)
print('')
pyhop.print_methods()

# INITIAL STATE

state1 = pyhop.State('state1')
state1.coordinates = {
    'Huelva': {
        'X': 25,
        'Y': 275
    },
    'Cadiz': {
        'X': 200,
        'Y': 50
    },