Example #1
0
    def act(self):
        angle = ai.enemyHeadingDeg(self.idE)
        pos = np.array([ai.screenEnemyXId(self.idE), ai.screenEnemyYId(self.idE)])
        vel = ai.enemySpeedId(self.idE) * np.array([np.cos(angle), np.sin(angle)])
        self.target = pos - vel * self.K
        self.open_fire()

        # Put up shield if no good enemy. XOR operation:
        if id_valid(self.idE) == ai.selfShield():
            ai.shield()
Example #2
0
 def __init__(self, idE=None, gain=FIRE_GAIN):
     if idE is None:
         print("FireEnemy: No enemy selected! Exiting now.")
         ai.quitAI()
         sys.exit(1)
     print("Open fire to:", ai.enemyNameId(idE))
     if ai.selfShield():
         ai.shield()
     self.idE = idE
     self.K = gain
Example #3
0
 def __init__(self, idE=None, gain=FIRE_GAIN):
     if idE is None:
         print("FireEnemy: No enemy selected! Exiting now.")
         ai.quitAI()
         sys.exit(1)
     print("Open fire to:", ai.enemyNameId(idE))
     if ai.selfShield():
         ai.shield()
     self.idE = idE
     self.K = gain
Example #4
0
 def __init__(self, target=None):
     self.name = "fire"
     if target is None:
         print("Fire: Target not specified!!")
         ai.quitAI()
         sys.exit(1)
     else:
         self.target = target
     if ai.selfShield():
         ai.shield()
Example #5
0
 def __init__(self, target=None):
     self.name = "fire"
     if target is None:
         print("Fire: Target not specified!!")
         ai.quitAI()
         sys.exit(1)
     else:
         self.target = target
     if ai.selfShield():
         ai.shield()
Example #6
0
    def act(self):
        angle = ai.enemyHeadingDeg(self.idE)
        pos = np.array(
            [ai.screenEnemyXId(self.idE),
             ai.screenEnemyYId(self.idE)])
        vel = ai.enemySpeedId(self.idE) * np.array(
            [np.cos(angle), np.sin(angle)])
        self.target = pos - vel * self.K
        self.open_fire()

        # Put up shield if no good enemy. XOR operation:
        if id_valid(self.idE) == ai.selfShield():
            ai.shield()
Example #7
0
    def act(self):
        """ Act according to the current action """
        if self.was_dead:
            for _ in range(2): ai.shield()
            self.was_dead = False
        elif self.was_dead_before:
            if not ai.selfShield(): ai.shield()
            self.was_dead_before = False

        try:
            self.action.act()
        except AttributeError:
            if not self.warned:
                print("Action not yet initialised!")
                self.warned = True
Example #8
0
    def act(self):
        """ Act according to the current action """
        if self.was_dead:
            for _ in range(2):
                ai.shield()
            self.was_dead = False
        elif self.was_dead_before:
            if not ai.selfShield(): ai.shield()
            self.was_dead_before = False

        try:
            self.action.act()
        except AttributeError:
            if not self.warned:
                print("Action not yet initialised!")
                self.warned = True
Example #9
0
def tick():
    #NO EXCEPTION HANDLING
    try:
        #
        #GLOBAL VARIABLES
        #

        #XPILOT-SPEC
        global tickCount
        global mode
        global selfVelX, selfVelY
        global selfX, selfY
        global selfSpeed
        global selfTracking

        #ITEMS
        global item
        global itemId
        global lastItemCount

        #COMMUNICATION
        global latestTask

        #A*
        global mapWidth
        global mapHeight
        global maplist
        global finalPath
        global finalPosition

        #REFUELING
        global fuelIndex
        global stationId

        #MULTITHREADING
        global maplistQueue
        global searchForPath
        global searchQueue
        global pathQueue

        #RESET IF DEAD
        if not ai.selfAlive():
            tickCount = 0

            #CLEAR A*
            finalPosition = []
            finalPath = []

            mode = "idle"
            return

        tickCount += 1

        #
        #SENSORS READINGS
        #

        #XPILOT-SPEC
        selfX = ai.selfX()
        selfY = (mapHeight * ai.blockSize()) - ai.selfY()
        selfVelX = ai.selfVelX()
        selfVelY = ai.selfVelY()
        selfSpeed = ai.selfSpeed()
        selfTracking = ai.selfTrackingRad()
        selfHeading = ai.selfHeadingRad()

        #DOES NOT EXIST FIRST TICKS
        if tickCount > 6:
            mass = ai.selfMass()

        thrustPower = ai.getPower()
        friction = ai.getOption("friction")
        mapWidth = ai.getOption("mapwidth")
        mapHeight = ai.getOption("mapheight")

        print ("tick count:", tickCount, "mode", mode)

        #IN THIS MODE WE ARE WAITING FOR THE PLAYER TO GIVE THE BOT INSTRUCTIONS
        if mode == "idle":
            mode, value, latestTask = getMessage()

            if mode == "move":
                finalPosition = value
            elif mode == "collect":
                item = value
            elif mode == "refuel":
                fuelIndex = value

        #IN THIS MODE WE ARE CALUCLATING PATH USING ASTAR
        elif mode == "move":

            #MULTITHREADING
            searchForPath = True
            searchQueue.put(searchForPath)
            try:
                finalPath = pathQueue.get(timeout=1)
                maplist = maplistQueue.get(timeout=1)
            except queue.Empty:
                pass

            #SEARCH-PATH-PART
            if not finalPath:
                print("CALCULATING PATH")
                maplist, finalPath = getPath(pixelsToBlockSize(mapWidth, mapHeight), tuple(finalPosition), mapWidth, mapHeight)
                print("CALCULATED MAPLIST LENGTH:", len(maplist))
                print("CALCULATED FINAL PATH:", len(finalPath))
            else:
                if maplist:
                    printMap(finalPath, True)

                #MULTITHREADING
                searchForPath = False
                searchQueue.put(searchForPath)

                print("Final Path:", finalPath)
                print("Player Pos:","(",selfY // ai.blockSize(), selfX // ai.blockSize(),")")
                targetPosition = finalPath[0]

                if finalPath[0][1] == selfX // ai.blockSize() and finalPath[0][0] == selfY // ai.blockSize():
                    if len(finalPath) > 1:
                        finalPath = finalPath[1:]
                    else:
                        print("REACHED TARGETPOS")
                        sendMessage("teacherbot")

                        finalX = finalPosition[1]
                        finalY = finalPosition[0]
                        finalPosition = []
                        finalPath = []

                        print(latestTask)
                        if "refuel" in latestTask:
                            mode = "refueling"
                        elif latestTask == "use-item mine":
                            mode = useMine(finalX, finalY)
                        elif latestTask == "use-item missile":
                            mode = useMissile(finalX, finalY)
                        elif latestTask == "use-item laser":
                            mode = useLaser(finalX, finalY)
                        else:
                            mode = "idle"

            #MOVE-PART
            if finalPosition:
                stoppingDist = stopping_distance(mass, friction, thrustPower, selfSpeed)
                moveToPos(selfX, selfY, [targetPosition[1]*ai.blockSize(), targetPosition[0]*ai.blockSize()], stoppingDist)

        #IF OTHER PLAYER IS SHOOTING TOWARDS YOU FLEE
        elif mode == "flee":
            if ai.selfItem(18):
                usePhasing(0, 0)
            elif ai.selfItem(17):
                useHyperJump(0, 0)
            elif ai.selfItem(10):
                useEcm(0,0)
            elif ai.selfItem(15):
                useEmergencyShield(0, 0)
            else:
                ai.shield()

        #IN THIS MODE WE ARE REFUELING
        elif mode == "refuel":

            mode, finalPath, finalPosition = moveToFuelStation()
        elif mode == "refueling":
            '''Amount of fuel in station'''
            if ai.fuelstationFuel(fuelIndex) > 0:
                '''Keep calling to refuel'''
                ai.refuel()
            else:
                mode = "idle"

        #IN THIS MODE WE ARE COLLECTING ITEMS
        elif mode == "collect":
            if ai.itemCountScreen() > 0:
                itemOnScreen = False
                for i in range(ai.itemCountScreen()):
                    if ai.itemType(i) == item:
                        itemId = i
                        itemOnScreen = True
                        break

                if not itemOnScreen:
                    print("No item of type " + str(item) + " on screen")
                    mode = "idle"

                collectAim(itemId)

                if selfSpeed < 10:
                    thrust(10)
                else:
                    brake(2)

    except:
        print(traceback.print_exc())
Example #10
0
def initialise():
    """ Initial procedure """
    print("New Game!")
    ship.set_action("do_nothing")
    for _ in range(3): ai.shield() # Avoid initial shield locking
Example #11
0
 def preempt(self):
     if not ai.selfShield():
         ai.shield()
Example #12
0
 def preempt(self):
     if not ai.selfShield():
         ai.shield()