Пример #1
0
 def init(self):
     self.head: Location = Location(10, 10)
     self.body: List[Body] = [
         Body(Location(10, 11), Direction.UP),
         Body(Location(10, 12), Direction.UP),
         Body(Location(10, 13), Direction.UP)
     ]
     self.direction = Direction.UP
Пример #2
0
    def move(self, game):
        """
        The logic of moving the snake that includes collision detection and eating too.
        :return: whether the snake is still alive
        """
        # next location
        x, y = self.head.get_location()
        old_direction = self.direction
        # Calculate the next coordinate based on moving direction
        new = Location(*[sum(i) for i in zip((x, y), self.direction.value)])

        # verify valid move
        collision = self.check_collision(*new.get_location())

        if not collision:
            self.head.set_location(*new.get_location())
            self._add_body_part(Location(x, y), old_direction)

            # check whether he found food
            if self.check_for_food(game.board, new.get_location()):
                game.board.generate_food()
                game.score_inc(500)
            else:
                self.body.pop(-1)

        return not collision
Пример #3
0
class Board:
    """Represent the game board"""
    def __init__(self, size):
        self.table_size = size
        self.food_location = Location(0, 0)

        self.generate_food()

    def get_food_location(self):
        return self.food_location.get_location()

    def generate_food(self):
        self.food_location = Location(*random_position())
Пример #4
0
 def simulateOnce(self, showCanvas=True):
     self.virus.spread()
     
     numFlyingIndividuals = self.settings.numFlyingIndividuals
     flyingIndividuals = random.sample(self.individuals, numFlyingIndividuals)
     for flyInd in flyingIndividuals:
         (x, y, z) = self.factory.generateLocation()
         flyInd.location = Location(x, y, z)
     
     
     if showCanvas: 
         self.mainView.updateCanvas(self.individuals)
     
     self.simResults.registerTimeEpoch()
Пример #5
0
    def __init__(self):
        # место жительства, выдается случайно
        self.location = Location.random()
        # отображение имени, типа студента, места жительства
        self.name = Repository.getRandomName(
        ) + " (" + self.__class__.__name__ + ")\n" + str(self.location.name)
        # оценки студента
        self.ratings = list()
        # учебная группа студента
        self.studentGroup = None

        #     Модификатор живущего отдельно студента
        if self.location is Location.HOME:
            self.ability = self.ability + 10
    def post(self):
        self.response.out.write(self.request)
        lat = self.request.get("lat")
        long = self.request.get("long")
        email = self.request.get("email")

        location = Location(parent=Location.location_key(email))
        self.response.out.write("location : %s" % location)
        location.lat = lat
        location.long = long
        location.email = email
        location.put()
        self.redirect("/LocSubmit?" + urllib.urlencode({"email": email}))
    def get(self):
        email = self.request.get("email")
        limit = self.request.get("limit")
        query = ""
        if len(limit) > 0 and int(limit) > 0:
            query = "select * from Location where ANCESTOR IS :1 order by datetime desc limit %s" % limit
        else:
            query = "select * from Location where ANCESTOR IS :1 order by datetime desc "

        locations = db.GqlQuery(query, Location.location_key(email))

        retObject = []
        for location in locations:
            record = {}
            record["email"] = location.email
            record["lat"] = location.lat
            record["long"] = location.long
            record["DateTime"] = str(location.datetime)
            retObject.append(record)
        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(json.dumps(retObject))
    def get(self):
        email = self.request.get('email')
        locations = db.GqlQuery(
            "select * from Location where ANCESTOR IS :1 order by datetime desc limit 1 ",
            Location.location_key(email))

        for location in locations:
            self.response.out.write(
                'Existing value for : <b>email: %s, lat: %s, long: %s, timestamp: %s</b>'
                % (location.email, location.lat, location.long,
                   location.datetime))

        self.response.out.write("""<html>
        <body>
            <form action="/Location_Post" method="post">
            <div><textarea name="lat" rows="1" cols="20"></textarea>
            <textarea name="long" rows="1" cols="20"></textarea></div>
            <textarea name="email" rows="1" cols="20"></textarea>   
            <div><input type="submit" value="set lat/long"></div>
            </form>
            
            To get data in json: go to <a href="/Location.json">Location.json</a> and pass email as a parameter. eg /location.json?email=rohan.shah 
            </body></html>""")
Пример #9
0
    def __init__(self, size):
        self.table_size = size
        self.food_location = Location(0, 0)

        self.generate_food()
Пример #10
0
 def generate_food(self):
     self.food_location = Location(*random_position())
Пример #11
0
 def generateIndividual(self, sirStatus):
     sphereLoc = self.generateLocation()
     location = Location(x=sphereLoc[0], y=sphereLoc[1], z=sphereLoc[2])
     individual = Individual(self.curIndex, location, sirStatus)
     self.curIndex += 1
     return individual
Пример #12
0
 def createLocations(self):
     locations = CustomHashTable()
     addresses = self.getAddresses()
     for i in range(len(addresses)):
         locations[i] = Location(i, addresses[i])
     return locations