Exemple #1
0
def loop():
    '''This function is called over and over again.'''

    global i
    # do something arbitray. To be adapted.

    # create a list robot queries, one for each of the robots
    RQS = [MemeSimCommand.RQ(TEAM_NUMBER, (TEAM_NUMBER-1)*3+r) for r in range(1, 2)]

    # add a request to check the account balance
    RQS.append(MemeSimCommand.CA(TEAM_NUMBER))
    RQS.append(MemeSimCommand.RS(TEAM_NUMBER,10,150,150,(i/360)*2*pi))
    i=i+5
    # send the requests to the simulator

    for req in RQS:
        MEMESIM_CLIENT.send_command(req)



    # make a random mutation to some meme at a random position
    MY_MEMES['Meme1'][randint(0, 99)] = MemeGenome.Nucleotides[randint(0, 3)]

    # show the meme in the GUI
    MEMESIM_GUI.show_meme(MY_MEMES['Meme1'])
Exemple #2
0
def setup():
    ''' The setup function is called once at startup. You can put initialization code here. '''

    # create a collection of random memes
    for i in range(1, 11):
        mgen = MemeGenome.random_meme_genome()
        # do some arbitrary things to it
        mgen[0] = 'A'
        mgen[99] = mgen[0]
        # store the meme in the dictionary MY_MEMES under a name as a string
        MY_MEMES['Meme'+str(i)] = mgen

    # try to connect to the simulator
    if not MEMESIM_CLIENT.connect():
        print("Could not connect to the simulator.")
        exit()

    # create a list robot queries, one for each of the robots
    RQS = [MemeSimCommand.RQ(TEAM_NUMBER, (TEAM_NUMBER-1)*3+r) for r in range(1, 2)]

    # add a request to check the account balance
    RQS.append(MemeSimCommand.CA(TEAM_NUMBER))
    RQS.append(MemeSimCommand.RS(TEAM_NUMBER,10,150,150,2*pi))
    RQS.append(MemeSimCommand.RS(TEAM_NUMBER,11,150,150,2*pi))
    RQS.append(MemeSimCommand.RS(TEAM_NUMBER,12,150,150,2*pi))

    # send the requests to the simulator
    for req in RQS:
        MEMESIM_CLIENT.send_command(req)

    RESPONSES = MEMESIM_CLIENT.new_responses()
Exemple #3
0
def loop(mode):
    '''This function is called over and over again.'''
    if mode == 'rq':
        # create a list robot queries, one for each of the robots
        RQS = [MemeSimCommand.RQ(TEAM_NUMBER, Robot)]

    elif mode == 'mq':
        # add a request to check the account balance
        #res() so as to auto reset every market research
        number = input("How many individuals?")
        global nrofinterviews
        nrofinterviews = number
        RQS = [MemeSimCommand.MQ(TEAM_NUMBER, Robot, number)]
    elif mode == 'ip':
        #print(People)
        pseudoID = int(input("Person to interview:"))
        RQS = [MemeSimCommand.IP(TEAM_NUMBER, Robot, People[pseudoID][2])]
        Database.append(People[pseudoID])
        print(Database)
    elif mode == 'pi':
        for i in range(0, len(Database)):
            print(i, "numero:", Database[i][1])
            RQS = [MemeSimCommand.PI(TEAM_NUMBER, Robot, Database[i][2])]
            for req in RQS:
                MEMESIM_CLIENT.send_command(req)
            sleep(1)
    elif mode == 'tm':
        #genome=input("insert meme genome=")
        pseudoID = int(input("ID of the individual:"))
        meme_gen = ProduceGenome()
        RQS = [
            MemeSimCommand.TM(TEAM_NUMBER, Robot, meme_gen,
                              Database[pseudoID][2])
        ]
    elif mode == 'pc':
        memeName = input("Insert meme name:")
        meme_gen = ProduceGenome()
        RQS = [MemeSimCommand.PC(TEAM_NUMBER, Robot, memeName, meme_gen)]
    elif mode == 'lc':
        memeName = input("Insert meme name:")
        budget = int(input("Budeget:"))
        RQS = [MemeSimCommand.LC(TEAM_NUMBER, Robot, memeName, budget)]
    elif mode == 'db':
        RQS = [MemeSimCommand.DB(TEAM_NUMBER, 'money')]

    elif mode == 'set':
        xpos = int(input("Position x-axis:"))
        ypos = int(input("Position y-axis:"))
        angle = 20
        RQS = [MemeSimCommand.RS(TEAM_NUMBER, Robot, xpos, ypos, 20)]

    RQS.append(MemeSimCommand.CA(TEAM_NUMBER))
    #RQS.append(MemeSimCommand.MQ(4,10,20))
    #i=i+1
    # send the requests to the simulator
    if mode != 'pi':
        for req in RQS:
            MEMESIM_CLIENT.send_command(req)
def loop(mode):
    '''This function is called over and over again.'''
    if mode=='rq':
        # create a list robot queries, one for each of the robots
        RQS = [MemeSimCommand.RQ(TEAM_NUMBER,Robot) ]
    elif mode=='mq':
        # add a request to check the account balance
        number=input("How many individuals?")
        global nrofinterviews
        nrofinterviews = number
        RQS=[MemeSimCommand.MQ(TEAM_NUMBER,Robot,number)]
    elif mode=='ip':
        ID=input("ID of the individual to interview")
        RQS= [MemeSimCommand.IP(TEAM_NUMBER,Robot,ID)]
    elif mode=='pi':
        ID=input("ID of the individual to interview")
        RQS= [MemeSimCommand.PI(TEAM_NUMBER,Robot,ID)]
    elif mode=='tm':
        #genome=input("insert meme genome=")
        ID=input("ID of the individual")
        meme_gen='CCCTTTAAACCCTTTAAACCCTTTAAACCCTTTAAACCCTTTAAACCCTTTAAACCCTTTAAACCCTTTAAACCCTTTAAACCTTTAAACCCTTTAAACC'
        RQS= [MemeSimCommand.TM(TEAM_NUMBER,Robot,meme_gen,ID)]
    elif mode=='pc':
        memeN=input("insert meme name=")
        meme_gen='CCCTTTAAACCCTTTAAACCCTTTAAACCCTTTAAACCCTTTAAACCCTTTAAACCCTTTAAACCCTTTAAACCCTTTAAACCTTTAAACCCTTTAAACC'
        RQS= [MemeSimCommand.PC(TEAM_NUMBER,Robot,memeN,meme_gen)]
    elif mode=='lc':
        memeN=input("insert meme name=")
        RQS=[MemeSimCommand.LC(TEAM_NUMBER,Robot,memeN,100)]
    elif mode=='db':
        RQS=[MemeSimCommand.DB(TEAM_NUMBER,'reset')]
    elif mode=='eur':
        RQS=[MemeSimCommand.DB(TEAM_NUMBER,'reset')]
    elif mode=='set':
        xpos=int(input("xpos="))
        ypos=int(input("ypos="))
        angle=20
        RQS=[MemeSimCommand.RS(TEAM_NUMBER,Robot,xpos,ypos,20)]

    RQS.append(MemeSimCommand.CA(TEAM_NUMBER))
        #RQS.append(MemeSimCommand.MQ(4,10,20))
        #i=i+1
        # send the requests to the simulator

    for req in RQS:
        MEMESIM_CLIENT.send_command(req)


    # make a random mutation to some meme at a random position
    MY_MEMES['Meme1'][randint(0, 99)] = MemeGenome.Nucleotides[randint(0, 3)]

    # show the meme in the GUI
    MEMESIM_GUI.show_meme(MY_MEMES['Meme1'])
Exemple #5
0
def GetPosition(robotID):
    RQ = MemeSimCommand.RQ(8, robotID+14)
    MEMESIM_CLIENT.send_command(RQ)

    time.sleep(1.0)

    RESPONSES1 = MEMESIM_CLIENT.new_responses()

    for resp1 in RESPONSES1:
        if resp1.cmdtype() == 'rq':
            if not resp1.iserror():
                xpos = int(float(resp1.cmdargs()[2]))
                ypos = int(float(resp1.cmdargs()[3]))
                angle = round(math.degrees(float(resp1.cmdargs()[4])))

                if abs(angle) > 180:
                    angle = angle - sign(angle) * 360

                return [xpos, ypos], angle
    return
def update_position(robot_id):
    RQ1 = MemeSimCommand.RQ(4, robot_id)  #make a request
    MEMESIM_CLIENT.send_command(RQ1)  #send request
    sleep(0.2)  #wait a bit
    update_responses()  #find answers to responses: to x, y and angle
Exemple #7
0
def loop():
    repeatCmd = False
    global tr2
    global tr1
    global CityIDGen
    global CityID
    global city
    global MY_MEMES
    error = 0

    print(
        "What do you want to do? (rq/mqip/genmeme/genmemes/tm/pc/lc/ca/db/rs/quit/print_ind/litt/save/read/dest)"
    )
    command = input()
    if "*" in command:
        command = command.replace("*", "")
        repeatCmd = True

    if command == "rq":
        print("location of which robot? 1(henk)/2(ingrid)")
        robotID = int(input()) + 14
        RQ1 = MemeSimCommand.RQ(8, robotID)

    elif command == "mq":  # need to store city number
        print("Query with which robot? 1(henk)/2(ingrid)")
        robotID = int(input()) + 14
        print("For what group size?")
        group_size = int(input())
        RQ1 = MemeSimCommand.MQ(8, robotID, group_size)

    elif command == "ip":
        print("Interview person with which robot? 1(henk)/2(ingrid)")
        robotID = int(input()) + 14
        print("Which person do you want to interview?")
        individualID = int(float(input()))
        RQ1 = MemeSimCommand.IP(8, robotID, individualID)

    elif command == "mqip":  # need to store city number
        print("Query and interview with which robot? 1(henk)/2(ingrid)")
        robotID = int(input()) + 14
        print("For what group size?")
        group_size = int(input())
        print("In which city are you?")
        city = int(input())
        RQ1 = MemeSimCommand.MQ(8, robotID, group_size)

    elif command == "pi":  # need to store city number
        print("Process interview with which robot? 1(henk)/2(ingrid)")
        robotID = int(input()) + 14
        print("Which person was interviewed?")
        individualID = input()
        RQ1 = MemeSimCommand.PI(8, robotID, individualID)

    elif command == 'genmeme':
        print("Process interview with which robot? 1(henk)/2(ingrid)")
        robotID = int(input()) + 14
        print("For which city do you want to generate a meme?")
        city = int(input())
        print("What do you want to call the meme?")
        memename = input()
        print("What protocol do you want to use?")
        protocol = int(input())
        genmeme(robotID, memename, protocol)
        error = 1

    elif command == 'genmemes':
        print("Process interview with which robot? 1(henk)/2(ingrid)")
        robotID = int(input()) + 14
        print("For which city do you want to generate a meme?")
        city = int(input())
        print("What do you want to call the meme?")
        memename = input()
        genmemes(robotID, memename)
        error = 1
    #
    #    elif command == 'gm':
    #        print("For which city do you want to generate a meme?")
    #        citynr = int(input())
    #        print("What do you want to call the meme?")
    #        memename = input()
    #        print("What protocol do you want to use?")
    #        protocol = int(input())
    #        genomes_to_send = []
    #        for i in range(len(CityIDGen)):
    #            if CityIDGen[i][0] == citynr:
    #                genomes_to_send += [CityIDGen[i][2]]
    #        print(genomes_to_send)
    #        averageGenome = getAverage(genomes_to_send)
    #        print(averageGenome)
    #        MY_MEMES += genome_protocol(protocol, averageGenome)
    #        error = 1 bla

    elif command == "tm":
        found = False
        print("Test meme with which robot? 1(henk)/2(ingrid)")
        robotID = int(input()) + 14
        print("Which meme?")
        meme_name = input()
        print("Which person do you want to test on?")
        individualID = input()
        for i in range(len(MY_MEMES)):
            if MY_MEMES[i][0] == meme_name:
                meme_genome = MY_MEMES[i][1]
                found = True
        if found == True:
            RQ1 = MemeSimCommand.TM(8, robotID, meme_genome, individualID)
        else:
            print("That meme does not excist")
            error = 1
        found = False

    elif command == "pc":
        print("Process campaign with which robot? 1(henk)/2(ingrid)")
        robotID = int(input()) + 14
        print("Which meme?")
        meme_name = input()
        for i in range(len(MY_MEMES)):
            if MY_MEMES[i][0] == meme_name:
                meme_genome = MY_MEMES[i][1]
                found = true
        if found == true:
            RQ1 = MemeSimCommand.PC(8, robotID, meme_name, meme_genome)
        else:
            print("That meme does not excist")
            error = 1
        found = false

    elif command == "lc":
        print("Launch campaign with which robot? 1(henk)/2(ingrid)")
        robotID = int(input()) + 14
        print("What meme do you want to launch?"
              )  # optie voor later: print lijst met alle memes
        meme_name = input()
        print("What is the budget?")
        budget = input()
        RQ1 = MemeSimCommand.LC(8, robotID, meme_name, budget)

    elif command == "ca":
        RQ1 = MemeSimCommand.CA(8)

    elif command == "db":
        print("What do you want to do? money/reset")
        debug_command = input()
        RQ1 = MemeSimCommand.DB(8, debug_command)

    elif command == "rs":
        print("Set location of which robot? 1(henk)/2(ingrid)")
        robotID = int(input()) + 14
        print("At which x_position? (in mm)")
        x_pos = input()
        print("At which y_position? (in mm)")
        y_pos = input()
        print("At what angle?")
        angle = input()
        RQ1 = MemeSimCommand.RS(8, robotID, x_pos, y_pos, angle)

    elif command == "quit":
        exit()

    elif command == "print_ind":
        print(CityIDGen)
        error = 1
    elif command == "litt":
        print("Geef input")
        testcmd = input()
        exec(testcmd)
        error = 1
    elif command == "save":
        print("Saving meme genome")
        write_genome(CityIDGen)
        error = 1
    elif command == "dest":
        print("Input destination 1")
        testTr = input()
        print("Input destination 2")
        testTr = input()
        error = 1
    elif command == "read":
        print("Reading meme genome")
        read_genome(CityIDGen)
        error = 1
    else:
        print("error")
        error = 1

        # do something arbitray with the memes
    if error == 0:
        MEMESIM_CLIENT.send_command(RQ1)

    if repeatCmd:
        sleep(sleep_length)
        RESPONSES = MEMESIM_CLIENT.new_responses()
        # process new responses
        for r in RESPONSES:
            process_response(r)
        loop()