Exemplo n.º 1
0
def go_to_tile_search_broadcast(nb_forward, nb_side, socket, lvl):
    for i in range(nb_forward):
        socket.Forward()
        dire, mess, resp, level = EmptyCacheSearchBroadcast(socket, lvl)
        if level != lvl:
            return dire, mess, level
        if dire != -1 and lvl != 1:
            return dire, mess, lvl
    if (nb_side < 0):
        socket.Left()
        dire, mess, resp, level = EmptyCacheSearchBroadcast(socket, lvl)
        if level != lvl:
            return dire, mess, level
        if dire != -1 and lvl != 1:
            return dire, mess, lvl
    elif (nb_side > 0):
        socket.Right()
        dire, mess, resp, level = EmptyCacheSearchBroadcast(socket, lvl)
        if level != lvl:
            return dire, mess, level
        if dire != -1 and lvl != 1:
            return dire, mess, lvl
    nb_side = abs(nb_side)
    for i in range(nb_side):
        socket.Forward()
        dire, mess, resp, level = EmptyCacheSearchBroadcast(socket, lvl)
        if level != lvl:
            return dire, mess, level
        if dire != -1 and lvl != 1:
            return dire, mess, lvl
    return -1, [], lvl
Exemplo n.º 2
0
def movToBroadcast(direction, socket, lvl):
    print("MOVE TO INCANT")
    ListActions = [['wait'],
                   ['forward'],
                   ['forward', 'left', 'forward'],
                   ['left', 'forward'],
                   ['left', 'forward', 'left', 'forward'],
                   ['right', 'right', 'forward'],
                   ['right', 'forward', 'right', 'forward'],
                   ['right', 'forward'],
                   ['forward', 'right', 'forward']]
    for action in ListActions[direction]:
        if action == 'forward':
            socket.Forward()
            dire, mess, resp, level = EmptyCacheSearchBroadcast(socket, lvl)
            if level != lvl:
                return dire, mess, level
        elif (action == 'left'):
            socket.Left()
            dire, mess, resp, level = EmptyCacheSearchBroadcast(socket, lvl)
            if level != lvl:
                return dire, mess, level
        elif (action == 'right'):
            socket.Right()
            dire, mess, resp, level = EmptyCacheSearchBroadcast(socket, lvl)
            if level != lvl:
                return dire, mess, level
        else:
            return -1, [], lvl
    return -1, [], lvl
Exemplo n.º 3
0
def look_inventory_search_broadcast(socket, lvl):
    socket.Inventory()
    dire, mess, resp, level = EmptyCacheSearchBroadcast(socket, lvl)
    if lvl != level:
        return dire, mess, resp, level
    if len(resp) > 0 and resp[0] != "ko":
        resp[0] = resp[0][2:-2].split(', ')
    return dire, mess, resp, lvl
Exemplo n.º 4
0
def search_stone_mode(lvl, food, left_over, socket):
    while (enough_food(lvl, food) and len(left_over) != 0):
        dire, mess, resp, level = look_inventory_search_broadcast(socket, lvl)
        if level != lvl:
            return -1, [], level
        if dire != -1 and lvl != 1:
            return dire, mess, lvl
        food = get_food(resp)
        location, item, dire, mess, level = IsThereItemSearchBroadcast(socket,
                                                                       left_over,
                                                                       lvl)
        if level != lvl:
            return -1, [], level
        if dire != -1 and lvl != 1:
            return dire, mess, lvl
        if (location >= 0):
            dire, mess, level = mov_to_tile_search_broadcast(location, lvl,
                                                             socket)
            if level != lvl:
                return -1, [], level
            if dire != -1 and lvl != 1:
                return dire, mess, lvl
            socket.Take(item)
            dire, mess, resp, level = EmptyCacheSearchBroadcast(socket, lvl)
            if level != lvl:
                return -1, [], level
            if dire != -1 and lvl != 1:
                return dire, mess, lvl
            dire, mess, resp, level = look_inventory_search_broadcast(socket,
                                                                      lvl)
            if level != lvl:
                return -1, [], level
            if dire != -1 and lvl != 1:
                return dire, mess, lvl
            left_over = GetLeftOverStone(resp, GetNeededRessources(lvl))
            print ("Stone search: stone i got: " + str(food))
        else:
            socket.Forward()
            dire, mess, resp, level = EmptyCacheSearchBroadcast(socket, lvl)
            if level != lvl:
                return -1, [], level
            if dire != -1 and lvl != 1:
                return dire, mess, lvl
    return -1, [], lvl
Exemplo n.º 5
0
def level8(socket):
    level = 8
    while (1):
        inventory, level = look_inventory(socket, level)
        food = get_food(inventory)
        if (food < level + 1):
            level = survive_mode(level, food, socket)
        else:
            socket.Forward()
            dire, mess, resp, level = EmptyCacheSearchBroadcast(socket, lvl)
Exemplo n.º 6
0
def IsThereItemSearchBroadcast(socket, requested_item, lvl):
    socket.Look()
    dire, mess, resp, level = EmptyCacheSearchBroadcast(socket, lvl)
    if level != lvl:
        return -1, "None", dire, mess, level
    resp = resp[:1]
    if len(resp) > 0 and resp[0] != "ko":
        resp = resp[0][2:-2].split(',')
    for tile in range(len(resp)):
        content = resp[tile].split(' ')
        for item in content:
            for req_item in requested_item:
                if item in req_item.split(' '):
                    return tile, item, dire, mess, lvl
    for tile in range(len(resp)):
        content = resp[tile].split(' ')
        for item in content:
            if item == "food":
                return tile, item, dire, mess, lvl
    return -1, "None", dire, mess, lvl