Beispiel #1
0
def main():
    program = [
        InitSymbols(),

        START("INIT"),

        LABEL("INIT"),
        BuildCostFence(),

        LABEL ("COMPUTE COSTS"),
        CHANGE_START("COMPUTE COSTS"),

        FillMapZeros(),
        MarkObstacles(),
        ReadEnemyVars(),
        MarkDrones(),

        LET("citpath", "-1"),
        IFLESS("0", "numcet", "END COLLISION CHECK"),
            LET("i", "0"),
            LABEL("LOOP COLLISION"),
                LETADD("ptr", "cetstart", "i"),
                INC("ptr", "i"),
                GETPTR("xi", "ptr"),

                INC("ptr", "1"),
                GETPTR("yi", "ptr"),

                LETSUB("xii", "x", "xi"),
                ABS("xii", "xii"),
                IFLESS("xii", "4", "CHECK TARGET COLLISION"),
                    LETSUB("yii", "y", "yi"),
                    ABS("yii", "yii"),
                    IFLESS("yii", "4", "CHECK TARGET COLLISION"),
                        LET("citpath", "1"),
                        JMP("END COLLISION CHECK"),

                LABEL("CHECK TARGET COLLISION"),
                LETSUB("xii", "tx", "xi"),
                ABS("xii", "xii"),
                IFLESS("xii", "4", "LOOP COLLISION INC"),
                    LETSUB("yii", "ty", "yi"),
                    ABS("yii", "yii"),
                    IFLESS("yii", "4", "LOOP COLLISION INC"),
                        LET("citpath", "1"),
                        JMP("END COLLISION CHECK"),

                LABEL("LOOP COLLISION INC"),
                INC("i", "1"),
            IFLESS("maxcet", "i", "LOOP COLLISION"),
        LABEL("END COLLISION CHECK"),

        IFLESS("0", "citpath", "MARK CITIZENS"),
            MarkPasthBFS(),

        LABEL("MARK CITIZENS"),
        MarkCitizens(),
        IFLESS("citpath", "0", "PENALIZE"),
            MarkPasthBFS(),

        LABEL("PENALIZE"),
        PenalizeEdges(),

        LABEL ("MOVE"),
        GetCostPointer("ptr", "x", "y"),
        GETPTR("cost", "ptr"),
        LET("cost", "10000"),
        LET("move", "0"),
        IFLESS("movebias", "0", "MOVE BIASED VERTICAL"),
            MoveBiasedHorizontal(),
            LET("movebias", "0"),
            JMP("MAKE MOVE"),

        LABEL("MOVE BIASED VERTICAL"),
        MoveBiasedVertical(),
        LET("movebias", "-1"),

        LABEL("MAKE MOVE"),
        MOVE_HLT("move"),
    ]

    asm = DroneAssembler(program).\
        compile().\
        spit().\
        save('/Users/rodanciv/Documents/01_letsGetToKnowEachOther_v9.txt').\
        save('/Users/rodanciv/Documents/02_dontGetShot_v9.txt').\
        save('/Users/rodanciv/Documents/03_shortestPath_v9.txt').\
        save('/Users/rodanciv/Documents/04_gottaCircleAround_v9.txt').\
        save('/Users/rodanciv/Documents/05_thinkAhead_v9.txt').\
        save('/Users/rodanciv/Documents/06_beOnYourToes_v9.txt').\
        save('/Users/rodanciv/Documents/07_intoTheDark_v9.txt').\
        save('/Users/rodanciv/Documents/08_mazeOfDrones_v9.txt').\
        save('/Users/rodanciv/Documents/09_theyJustKeepOnComing_v9.txt').\
        save('/Users/rodanciv/Documents/10_labyrinth_v9.txt').\
        save('/Users/rodanciv/Documents/11_whatsTheName_v9.txt').\
        save('/Users/rodanciv/Documents/12_noWayToTarget_v9.txt').\
        assembly

    dronemem = DroneMemory('/Users/rodanciv/Documents/Maze.txt')
    sim = DroneSimulator(asm)
    while not sim.done:
        sim.memupdate(dronemem.memory)
        sim.step()
        dronemem.dumpMemoryMatrix(4000 + dronemem.memory[1] + 2, dronemem.memory[1] + 2, dronemem.memory[2] + 2)
        print "x: " + str(sim.drone_x) + ", y: " + str(sim.drone_y)
        dronemem.refresh()

    print sim.status
    print "score: " + str(sim.getscore(12))
Beispiel #2
0
    global droneSimulator
    global ipController
    logWriter.noteEvent("MainThread: endHandler")
    droneSimulator.close()
    ipController.close()
    closeServerApp = True
    logWriter.close()
    sys.exit(0)


sys.excepthook = topExceptHook

signal.signal(signal.SIGINT, endHandler)
signal.signal(signal.SIGTERM, endHandler)

droneSimulator = DroneSimulator(logWriter)

serverName = ""  # "localhost"
serverPort = 6666

ipController = IpController((serverName, serverPort), False, False, 5,
                            logWriter)


# handler for DroneSimulator onReceiveEvent
# forwards valid CommData to IpController
def onReceiveCommDataFromSymulator(commData):
    global ipController
    print "Sending: " + str(commData)
    ipController.sendCommData(commData.data)
    global ipController
    logWriter.noteEvent("MainThread: endHandler")
    droneSimulator.close()
    ipController.close()
    closeServerApp = True
    logWriter.close()
    sys.exit(0)

sys.excepthook = topExceptHook

signal.signal(signal.SIGINT, endHandler)
signal.signal(signal.SIGTERM, endHandler)



droneSimulator = DroneSimulator(logWriter)

serverName = ""  # "localhost"
serverPort = 6666

ipController = IpController((serverName, serverPort), False, False, 5, logWriter)



# handler for DroneSimulator onReceiveEvent
# forwards valid CommData to IpController
def onReceiveCommDataFromSymulator(commData):
    global ipController
    print "Sending: " + str(commData)
    ipController.sendCommData(commData.data)