Ejemplo n.º 1
0
def layAnEgg(level, socket):
    inventory, lvl = look_inventory(socket, level)
    food = get_food(inventory)
    if (not enough_food_incant(level, food)):
        search_food_incant_mode(level, food, socket)
    socket.Fork()
    EmptyCacheIgnoreBroadcast(socket, level)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def incant(socket, food, lvl):
    dire, mess, level = search_before_broadcast(socket, food, lvl)
    if level != lvl:
        return -1, [], level
    if dire != -1 and lvl != 1:
        return dire, mess, lvl
    while food >= lvl + 3:
        count = 0
        SendIncantBroadcast(socket, lvl)
        resp, level = EmptyCacheIgnoreBroadcast(socket, lvl)
        if level != lvl:
            return dire, mess, level
        socket.Look()
        resp, level = EmptyCacheIgnoreBroadcast(socket, lvl)
        if level != lvl:
            return dire, mess, level
        resp = resp[:1]
        if len(resp) > 0 and resp[0] != "ko":
            resp = resp[0][2:-2].split(',')
            content = resp[0].split(' ')
            for item in content:
                if item == "player":
                    count += 1
        if count == number_of_people_to_incant(lvl):
            socket.Look()
            resp, level = EmptyCacheIgnoreBroadcast(socket, lvl)
            if level != lvl:
                return dire, mess, level
            resp = resp[:1]
            resp = resp[0][2:-2].split(',')
            get_all_item_here(socket, resp[0], lvl)
            set_stones(socket, lvl)
            socket.Incantation()
            resp, level = EmptyCacheIgnoreBroadcastIncant(socket, lvl)
            if level != lvl:
                return dire, mess, level
            else:
                ko_incant(socket, lvl)
                return dire, mess, lvl
        inventory, level = look_inventory(socket, lvl)
        if level != lvl:
            return dire, mess, level
        food = get_food(inventory)
    return dire, mess, lvl
Ejemplo n.º 4
0
def search_food_incant_mode(lvl, food, socket):
    while food < lvl + 8:
        location, item, level = IsThereItem(socket, ["food"], lvl)
        if level != lvl:
            return level
        if (location >= 0):
            mov_to_tile(location, lvl, socket)
            socket.Take(item)
            resp, level = EmptyCacheIgnoreBroadcast(socket, lvl)
            if level != lvl:
                return level
            inventory, level = look_inventory(socket, lvl)
            if level != lvl:
                return level
            food = get_food(inventory)
            print("search food incant: food i got: " + str(food))
        else:
            for i in range(lvl):
                socket.Forward()
                resp, level = EmptyCacheIgnoreBroadcast(socket, lvl)
                if level != lvl:
                    return level
Ejemplo n.º 5
0
def survive_mode(lvl, food, socket):
    while food < lvl + 1:
        location, item, level = IsThereItem(socket, ["food"], lvl)
        if level != lvl:
            return level
        if (location >= 0):
            mov_to_tile(location, lvl, socket)
            socket.Take(item)
            resp, level = EmptyCacheIgnoreBroadcast(socket, lvl)
            if level != lvl:
                return level
            inventory, level = look_inventory(socket, lvl)
            if level != lvl:
                return level
            food = get_food(inventory)
            print ("SURVIVE: food i got: " + str(food))
        else:
            socket.Forward()
            resp, level = EmptyCacheIgnoreBroadcast(socket, lvl)
            if level != lvl:
                return level
    return lvl
Ejemplo n.º 6
0
def level1(lvl, socket):
    level = lvl
    needed_stones = GetNeededRessources(level)
    dire = -1
    mess = []
    while (level == lvl):
        inventory, level = look_inventory(socket, level)
        if level != lvl:
            return level
        food = get_food(inventory)
        left_over = GetLeftOverStone(inventory, needed_stones)
        print("BASE:food i got: " + str(food))
        if (not enough_food(level, food)):
            print('MODE: survive')
            survive_mode(level, food, socket)
        elif (not enough_food_incant(level, food)):
            print('MODE: search food incant')
            search_food_incant_mode(level, food, socket)
        elif (dire != -1 and level != 1):
            print('MODE: go to incant')
            level = go_to_incant_state(socket, level, food, dire, mess)
            dire = -1
            mess = []
            socket.target_id = ""
        elif len(left_over) != 0 and enough_food_incant(level, food):
            print('MODE: search stone')
            dire, mess, level = search_stone_mode(level, food, left_over,
                                                  socket)
            if level != lvl:
                return lvl
        else:
            print('MODE: INCANT')
            dire, mess, level = incant(socket, food, level)
            if level != lvl:
                return level
    return (level)