def main():
    data = "world"

    domain = "domain.pddl"

    agents = ["Jafar", "Aladdin", "Jasmine", "Genie", "Dragon"]

    worldManagement.create(data, agents, genesis=True)

    too_long = 20

    run = True
    while run:
        calculating = [
            subprocess.Popen([
                "metricff//Metric-FF-v2.1//ff", '-o',
                os.path.join(data, domain), '-f',
                os.path.join(data, agent + ".pddl"), '-s', '3', '>',
                os.path.join(data, agent + ".soln")
            ]) for agent in agents
        ]

        thinking_time = time.clock()

        while not finished_thinking(calculating):
            time.sleep(0.1)
            thinking_time = time.clock()
            if thinking_time > too_long:
                break
        translations, formalplans = questTranslation.interpret(data)

        motivations = [
            questClassification.classify(formalplan)
            for formalplan in formalplans
        ]

        for translation, motivation in zip(translations, motivations):
            print(translation, motivation)

        action = input()

        if action == "exit":
            run = False
        else:
            worldManagement.update(data, action, agents)
def main():
    data = "world"

    domain = "domain.pddl"

    agents = ["baker","blacksmith"]

    worldManagement.create(data,agents,genesis=True)

    pyperplan = os.path.join("pyperplan","pyperplan.py")

    too_long = 20

    run = True
    while run:
        calculating = [subprocess.Popen(["C:\\Python34\python.exe", pyperplan, os.path.join(data,domain), os.path.join(data,agent+".pddl")]) for agent in agents]

        thinking_time = time.clock()

        while not finished_thinking(calculating):
            time.sleep(0.1)
            thinking_time = time.clock()
            if thinking_time > too_long:
                break
        translations, formalplans = questTranslation.interpret(data)

        motivations = [questClassification.classify(formalplan) for formalplan in formalplans]

        for translation,motivation in zip(translations,motivations):
            print(translation,motivation)

        action = input()

        if action == "exit":
            run = False
        else:
            worldManagement.update(data, action, agents)
def main():
    data = "world"

    domain = "domain.pddl"

    agents = sorted([
        "baker", "king", "lumberjack", "blacksmith", "merchant", "guard",
        "daughter"
    ])

    write_domains(data, domain, agents, worldManagement.preferences)

    worldManagement.create(data, agents, genesis=True)

    too_long = 10000

    run = True
    calculating = []
    opened_files = []
    while run:

        for agent in agents:
            opened_files.append(open(os.path.join(data, agent + ".soln"), "w"))
            calculating.append(
                subprocess.Popen([
                    os.path.join("metricff", "Metric-FF-v2.1", "ff"), '-o',
                    os.path.join(data, agent, "domain" + agent + ".pddl"),
                    '-f',
                    os.path.join(data, agent, agent + ".pddl"), '-s', '3'
                ],
                                 stdout=opened_files[-1]))

        thinking_time = time.perf_counter()
        print('Thinking')
        while not finished_thinking(calculating):
            time.sleep(0.5)
            print("..", end=".")
            thinking_time = time.perf_counter()
            if thinking_time > too_long:
                break
        for opened_file in opened_files:
            opened_file.close()

        print("Done")
        translations, _, formalplans = questTranslation.interpret(data)

        print(formalplans)

        motivations = [
            questClassification.classify(formalplan)
            for formalplan in formalplans
        ]

        for translation, motivation in zip(translations, motivations):
            print(translation, motivation)

        action = input()

        if action == "exit":
            run = False
        else:
            worldManagement.update(data, action, agents)
def main():
    data = "world"

    domain = "domain.pddl"

    #agents = sorted(["baker", "king", "lumberjack", "blacksmith", "merchant", "guard", "daughter"])
    agents = sorted(["baker", "king", "lumberjack", "blacksmith", "merchant", "guard", "daughter"])

    motivation_count = dict()
    motivations = ["Knowledge","Comfort","Reputation","Serenity","Protection","Conquest","Wealth","Ability","Equipment"]
    for motiv in motivations:
        motivation_count[motiv] = 0
    motivation_count["Not found"] = 0

    print(motivation_count)

    emptyOrComplete = 0

    quest_log = open("quest_log.txt","w")

    too_long = 600 # 10 minutes
    run = True

    #Creates all the domains and populates a list of action objects
    listOfActions = write_domains(data, domain, agents, worldManagement.preferences)

    #makes all the goals
    worldManagement.create(data,agents, attempts_per_agent=4, genesis=True, verbose=False)

    while run:


    
        calculating = []
        opened_files = []

        for agent in agents:
            calculating.append(questPlanning.plan_quest(agent))
            #opened_files.append(open(os.path.join(data,agent+".soln"),"w"))
            #calculating.append(subprocess.Popen([os.path.join("metricff","Metric-FF-v2.1","ff"), '-o', os.path.join(data,"domain"+agent+".pddl"), '-f', os.path.join(data,agent+".pddl"), '-s', '3'],stdout=opened_files[-1]))

        thinking_time = time.clock()
        thinking_timelast = thinking_time
        print('Thinking')
        while not finished_thinking(calculating):
            time.sleep(0.5)
            print(".", end=".")
            sys.stdout.flush()
            thinking_timelast += 0.5
            #print(thinking_timelast)
            if thinking_time + too_long < thinking_timelast:
                print(thinking_time)
                print("Took too long!")
                for stillcalculating in calculating:
                    if stillcalculating.poll() == None:
                        stillcalculating.kill()
                break
        
        for opened_file in opened_files:
            opened_file.close()

        print("Done")
        translations, formalplans, NPCNames = questTranslation.interpret(data)

        #print(formalplans)

        motivations = [questClassification.classify_fuzzy(formalplan) for formalplan in formalplans]
        for formalplan,motivation,npcname,translation in zip(formalplans,motivations,NPCNames,translations):

            #prints the quest
            print(npcname)
            print(translation,motivation)
            if len(formalplan) < 1:
                emptyOrComplete += 1
            else:
                print(" ".join(formalplan)+" "+motivation[0])
                quest_log.write(" ".join(formalplan))
                quest_log.write(" m:"+motivation[0])
                quest_log.write("\n\n")
            motivation_count[motivation[0]] += 1
        """
        for formalplan in formalplans:
            #print(formalplan)
            if len(formalplan) < 1:
                emptyOrComplete += 1
            else:
                print(" ".join(formalplan))
                quest_log.write(" ".join(formalplan))
                quest_log.write("\n\n")
        """
        #Prints the motivations
        #print(motivation_count)
        #print(emptyOrComplete)

        action = input()

        if action == "exit":
            run = False
        else:
            worldManagement.update(data, action, agents, listOfActions)



        #run -= 1
        #print ('This is iteration number '+ str(run))
    quest_log.close()