Пример #1
0
 def test_add_pointset(self):
     new_ps = e.Pointset(
         [e.Point(0, 1, 1),
          e.Point(0, 1, 2),
          e.Point(0, 1, 3)])
     self.ps += new_ps
     assert self.ps.points == new_ps.points
Пример #2
0
 def test_sub_pointset(self):
     new_ps = e.Pointset(
         [e.Point(0, 1, 1),
          e.Point(0, 1, 2),
          e.Point(0, 1, 3)])
     self.ps -= new_ps
     assert self.ps.points == set([])
Пример #3
0
 def test_child_drinking(self):
     agent = e.Agent(e.Point(10,1,1), self.dispatch_object, hunger_percent=0, thirst_percent=95)
     self.dispatch_object.create_item_at('food/dairy/cave_grub_spawn', e.Point(10,4,4))
     # We should also be thirsty
     for x in xrange(0,15):
         agent.tick()
         sleep(.1)
     assert agent.alive
     agent.exit()
Пример #4
0
 def test_child_eating(self):
     agent = e.Agent(e.Point(10,1,1), self.dispatch_object, hunger_percent=100, thirst_percent=0)
     self.dispatch_object.create_item_at('food/plant/apple', e.Point(10,2,2))
     # There's food, and we should already be hungry
     for x in xrange(0,10):
         agent.tick()
         sleep(.1)
     assert agent.alive
     agent.exit()
Пример #5
0
def draw(img, screen, grid, bgGrid, screenW,
         screenH):  #originPoint, viewH viewW (IN GRIDS)
    origin = grid.origin
    for y in range(0, screenH):
        for x in range(0, screenW):
            p = entities.Point(x + origin.x, y + origin.y)
            value = model.get_cell(grid, p)
            bgValue = model.get_cell(bgGrid, p)
            #Background handling - concrete and grass

            screen.blit(img.Background, (x * CELL_SIZE, y * CELL_SIZE))

            if bgValue == model.CONCRETE:
                screen.blit(img.Concrete, (x * CELL_SIZE, y * CELL_SIZE))
            #Entity handling

            if value == model.GATHERER:
                g = grid.entityList[controller.findEntity(grid.entityList, p)]
                if g.move:
                    screen.blit(img.gathSprite, (x * CELL_SIZE, y * CELL_SIZE))
                else:
                    screen.blit(img.consumeList[g.animationLoop],
                                (x * CELL_SIZE, y * CELL_SIZE))

            elif value == model.GENERATOR:
                g = grid.entityList[controller.findEntity(grid.entityList, p)]
                screen.blit(img.marketList[g.times],
                            (x * CELL_SIZE, y * CELL_SIZE))
            elif value == model.RESOURCE:
                screen.blit(img.resSprite, (x * CELL_SIZE, y * CELL_SIZE))
            elif value == model.OBSTACLE:
                screen.blit(img.Rock, (x * CELL_SIZE, y * CELL_SIZE))
            elif value == model.TRAIL:
                screen.blit(img.Trail, (x * CELL_SIZE, y * CELL_SIZE))
            elif value == model.TRANSFORM:
                g = grid.entityList[controller.findEntity(grid.entityList, p)]
                screen.blit(img.transformList[g.times - 1],
                            (x * CELL_SIZE, y * CELL_SIZE))
                #if click-drag is used to place these, and then tried to transform,
                #get error

    mPointx = grid.mouseHover.x + origin.x
    mPointy = grid.mouseHover.y + origin.y
    mPoint = entities.Point(mPointx, mPointy)
    hoverVal = model.get_cell(grid, mPoint)
    if hoverVal == model.EMPTY:
        screen.blit(
            img.greenBox,
            (grid.mouseHover.x * CELL_SIZE, grid.mouseHover.y * CELL_SIZE))
    else:
        screen.blit(
            img.redBox,
            (grid.mouseHover.x * CELL_SIZE, grid.mouseHover.y * CELL_SIZE))
Пример #6
0
def initialEntities(grid):
    #create points for the initial gatherer and generator
    p1 = entities.Point(random.randrange(0, grid.width),
                        random.randrange(0, grid.height))
    p2 = entities.Point(random.randrange(5, grid.width - 5),
                        random.randrange(5, grid.height - 5))

    gatherer = entities.CSCStudent(5, p1)
    generator = entities.CampusMarket(.5, p2)
    resourceList = spawnResources(grid, generator.position, [], 3, 3)
    entList = [gatherer, generator]
    for ent in resourceList:
        entList.append(ent)
    return entList
Пример #7
0
def save(grid, bgGrid):
    entityList = grid.entityList
    f = open('gaia.sav', 'w')

    for entity in entityList:
        if isinstance(entity, entities.CSCStudent):
            f.write('gatherer ' + str(entity.position.x) + ' ' +
                    str(entity.position.y) + ' ' + str(entity.rate) + '\n')
        elif isinstance(entity, entities.CampusMarket):
            f.write('generator ' + str(entity.position.x) + ' ' +
                    str(entity.position.y) + '\n')
        elif isinstance(entity, entities.MonsterEnergy):
            f.write('resource ' + str(entity.position.x) + ' ' +
                    str(entity.position.y) + '\n')
        elif isinstance(entity, entities.Obstacle):
            f.write('obstacle ' + str(entity.position.x) + ' ' +
                    str(entity.position.y) + '\n')

    for x in range(0, bgGrid.width):
        for y in range(0, bgGrid.height):
            p = entities.Point(x, y)
            if model.get_cell(bgGrid, p) == model.CONCRETE:
                f.write('concrete ' + str(x) + ' ' + str(y) + '\n')

    f.close()
    print("You saved the file!")
Пример #8
0
 def post(self):
     # Read in comma seperated values and split them into arrays
     lat = str.split(str(self.request.get('lat')), ',')
     lng = str.split(str(self.request.get('lng')), ',')
     bearing = str.split(str(self.request.get('bearing')), ',')
     speed = str.split(str(self.request.get('speed')), ',')
     accuracy = str.split(str(self.request.get('accuracy')), ',')
     wifi_power_levels = str.split(
         str(self.request.get('wifi_power_levels')), ',')
     timestamp = str.split(str(self.request.get('timestamp')), ',')
     # Read user id
     user_id = self.request.get('user_id')
     # All arrays must have the same size
     if ((len(lat) != len(lng)) or (len(lat) != len(bearing))
             or (len(lat) != len(wifi_power_levels))
             or (len(lat) != len(timestamp)) or (len(lat) != len(speed))
             or (len(lat) != len(accuracy))):
         self.error(400)
     # Add each data point to the database
     for i in range(len(lat)):
         location = db.GeoPt(lat[i], lng[i])
         # Store data point
         point = entities.Point(location=location,
                                bearing=float(bearing[i]),
                                speed=float(speed[i]),
                                accuracy=float(accuracy[i]),
                                wifi_power_levels=wifi_power_levels[i],
                                timestamp=int(timestamp[i]),
                                user_id=user_id)
         point.put()
Пример #9
0
def centroid(points):
    x_average = 0
    y_average = 0
    for p in points:
        x_average += p.x
        y_average += p.y
    x_average /= len(points)
    y_average /= len(points)
    return entities.Point(x_average, y_average)
Пример #10
0
def load(grid, bgGrid):
    model.emptyGrid(grid)
    model.emptyGrid(bgGrid)
    newList = []

    with open('gaia.sav', 'r') as f:
        for line in f:
            l = line.split()
            if l[0] == 'gatherer':
                p = entities.Point(int(l[1]), int(l[2]))
                resLim = 5
                newEnt = entities.CSCStudent(resLim, p)
                newEnt.rate = int(l[2]) * 100
                #print('YOU FOUND A GATHERER')

            elif l[0] == 'generator':
                p = entities.Point(int(l[1]), int(l[2]))
                rate = 2
                newEnt = entities.CampusMarket(rate, p)
                #print('YOU FOUND A GENERATOR')

            elif l[0] == 'resource':
                p = entities.Point(int(l[1]), int(l[2]))
                newEnt = entities.MonsterEnergy(p)
                #print('YOU FOUND A RESOURCE')

            elif l[0] == 'obstacle':
                p = entities.Point(int(l[1]), int(l[2]))
                newEnt = entities.Obstacle(p)

            elif l[0] == 'concrete':
                p = entities.Point(int(l[1]), int(l[2]))
                value = 6
                model.set_cell(bgGrid, p, value)

            newList.append(newEnt)
        f.close()
        grid.entityList = newList
        print("You loaded the file!")
Пример #11
0
def determineNewGathererPosition(grid, gat, res):
	#Determines position one grixel toward the CLOSEST resource in both the x and y axis
	#Eventually, will determine the closest resource of a list of resources


	newGathP = entities.Point(gat.position.x, gat.position.y)
	diry = gat.diry
	dirx = gat.dirx

	if not isinstance(res, entities.MonsterEnergy): 
		return
	

	if not (gat.position.x == res.position.x) and not gat.priY: 
		direction = res.position.x - gat.position.x
		unitDir = int(direction / abs(direction)) #will be either +1 or -1
		newGathP.x += unitDir
		cellVal = model.get_cell(grid, newGathP)
		if not canMove(cellVal):
			newGathP.x -= unitDir
			newGathP.y += diry
			cellVal = model.get_cell(grid, newGathP) 
			if not canMove(cellVal): 
				newGathP.y -= 2 * diry
				cellVal = model.get_cell(grid, newGathP) 
				if not canMove(cellVal): 
					newGathP.y -= diry
					newGathP.x -= unitDir
					gat.priY = True

	elif not gat.position.y == res.position.y or gat.priY: 
		direction = res.position.y - gat.position.y
		if direction == 0: direction = 1
		unitDir = int(direction / abs(direction) )
		newGathP.y += unitDir
		gat.priY = False
		cellVal = model.get_cell(grid, newGathP)
		if not canMove(cellVal): 
			newGathP.y -= unitDir 
			newGathP.x += dirx
			gat.priY = True
			cellVal = model.get_cell(grid, newGathP)
			if not canMove(cellVal): 
				newGathP.x -= 2 * dirx
				cellVal = model.get_cell(grid, newGathP)
				if not canMove(cellVal): 
					newGathP.x -= dirx
					newGathP.y -= unitDir
					gat.priY = False

	gat.position = newGathP
Пример #12
0
def getSurrounding(centerPoint, cellRange, grid):
    #returns a list of the values of surrounding cells
    #find the coordinates of the surrounding cells within range
    minx = centerPoint.x - cellRange
    maxx = centerPoint.x + cellRange
    miny = centerPoint.y - cellRange
    maxy = centerPoint.y + cellRange

    #get the values of surrounding cells
    getCells = []
    for x in range(minx, maxx + 1):
        for y in range(miny, maxy + 1):
            getCells.append(get_cell(grid, entities.Point(x, y)))

    return getCells
Пример #13
0
def spawnResources(grid, centerPoint, resourceL, numRes, cellRange):
    #creates new resources in empty cells nearby
    spawnedResources = []
    occupiedList = [centerPoint]  #list of currently filled positions
    for resource in resourceL:
        occupiedList.append(resource.position)
        #is there a reason that I don't just put in the resource.position?
    for x in range(0, numRes):
        resPoint = centerPoint
        loopAgain = True

        #will loop until 2 valid and empty position are found
        while loopAgain or (not isValidPosition(grid, resPoint)):

            cellList = getSurrounding(centerPoint, cellRange, grid)

            #check how many empty surrounding cells
            numEmpty = 0
            for cell in cellList:
                if cell == 0:
                    numEmpty += 1

            #if there are less than 2 empty surrounding cells, stop
            if numEmpty < 2:
                print("No space for Resources")
                return []

            #Reset loopAgain and isOccupied.
            #This way if not occupied but not valid, will reset
            loopAgain = True
            isOccupied = False
            resPoint = entities.Point(
                occupiedList[0].x +
                random.randrange(-cellRange, cellRange + 1),
                occupiedList[0].y +
                random.randrange(-cellRange, cellRange + 1))
            for pos in occupiedList:
                if (resPoint.x == pos.x) and (resPoint.y == pos.y):
                    isOccupied = True
            if not isOccupied:
                loopAgain = False

        occupiedList.append(resPoint)
        spawnedResources.append(entities.MonsterEnergy(resPoint))
    return spawnedResources
Пример #14
0
    def __init__(self, width, height, occupancy_value, screenW, screenH):
        self.width = width
        self.height = height
        self.cells = []
        self.screenW = screenW
        self.screenH = screenH
        self.origin = entities.Point(0, 0)
        self.entityList = []  #so this should really be a dictionary.
        self.keyPressed = 0
        self.spacePressed = False
        self.placeMode = 0
        self.mouseHover = None

        # initialize grid to all specified occupancy value
        for row in range(0, self.height):
            self.cells.append([])
            for col in range(0, self.width):
                self.cells[row].append(occupancy_value)
Пример #15
0
    def on_mouse_right_click(event):
        if Main.points_entered:
            return
        point = entities.Point(event.x, event.y)
        if any(point.x == p.x and point.y == p.y for p in Main.points):
            return

        if len(Main.points) != 0:
            edge = graphics.Line(
                graphics.Point(Main.points[-1].x, Main.points[-1].y),
                graphics.Point(point.x, point.y))
            edge.setWidth(2)
            edge.setFill("black")
            edge.setOutline("black")
            edge.draw(Main.win)

        Main.points.append(point)
        point.draw(Main.win)
Пример #16
0
def determineNewGathererPosition(grid, gatherer, resource):
    #Determines position one grixel toward the CLOSEST resource in both the x and y axis
    #Eventually, will determine the closest resource of a list of resources
    oldx = gatherer.position.x
    oldy = gatherer.position.y
    oldpoint = entities.Point(oldx, oldy)

    if resource.position.x > gatherer.position.x:
        gatherer.position.x += 1
    elif resource.position.x < gatherer.position.x:
        gatherer.position.x -= 1
    if model.get_cell(grid, gatherer.position) == 4:
        gatherer.position.x = oldx

    #Handling Y
    if resource.position.y > gatherer.position.y:
        gatherer.position.y += 1
    elif resource.position.y < gatherer.position.y:
        gatherer.position.y -= 1
    if model.get_cell(grid, gatherer.position) == 4:
        gatherer.position.y = oldy

    if not samePt(gatherer.position, oldpoint):
        model.set_cell(grid, oldpoint, 5)
Пример #17
0
import os
import entities
import pickle

p1 = entities.Point(2, 2)
p2 = entities.Point(3, 5)
p3 = entities.Point(2, 9)
p4 = entities.Point(0, 1)
gatherer = entities.CSCStudent('Nathan', 3, p1)
generator = entities.CampusMarket('market', 6, p2)
res1 = entities.MonsterEnergy('res', p3)
res2 = entities.MonsterEnergy('res2', p4)

entList = [gatherer, generator, res1, res2]

with open('gaia.sav', 'wb') as output:
    pickle.dump(entList, output, pickle.HIGHEST_PROTOCOL)

f = open('gaia.sav', 'r')
newList = pickle.load(f)
'''
for ent in entList: 
	if isinstance(ent, entities.CSCStudent): 

		f.write('gatherer' + ' ' + ent.name + ' ' + str(ent.resource_limit) + ' ' + str(ent.position.x) + ' ' + str(ent.position.y))
	elif isinstance(ent, entities.CampusMarket): 
		f.write(ent.name + ' ' + ent.rate + ' ' + ent.position.x + ' ' + ent.position.y)
	elif isinstance(ent, entities.MonsterEnergy): 
		f.write(ent.name + ' ' + ent.position.x + ' ' + ent.position.y)

	
Пример #18
0
 def test_sub_point(self):
     self.ps -= e.Point(0, 1, 1)
     assert self.ps.points == set([])
Пример #19
0
def emptyGrid(grid):
    for x in range(0, grid.width):
        for y in range(0, grid.height):
            p = entities.Point(x, y)
            set_cell(grid, p, 0)
Пример #20
0
 def test_add_point(self):
     self.ps += e.Point(0, 1, 1)
     assert self.ps.points == set([e.Point(0, 1, 1)])
Пример #21
0
 def test_create_agent_and_exit(self):
     self.dispatch_object.create_agent_at(e.Point(10, 1, 1))
     assert self.dispatch_object.agents[0].location == e.Point(10, 1, 1)
     self.dispatch_object.exit()
     self.dispatch_object.update()
     assert self.dispatch_object.agents == []
Пример #22
0
def handleHover(grid, x, y): 
	x = math.trunc(x / view.CELL_SIZE)
	y = math.trunc(y / view.CELL_SIZE)
	p = entities.Point(x, y)
	grid.mouseHover = p
Пример #23
0
 def test_create_item(self):
     self.dispatch_object.create_item_at('food/meat/shank',
                                         e.Point(10, 1, 1))
     assert self.dispatch_object.items[0][1] == e.Point(10, 1, 1)
Пример #24
0
 def setUp(self):
     self.dispatch_object = e.Dispatch()
     self.agent = e.Agent(e.Point(10,1,1), self.dispatch_object, hunger_percent=100, thirst_percent=90)
Пример #25
0
 def test_right_neighbor(self):
     assert self.test_point.right_neighbor() == e.Point(1, 3, 3)
Пример #26
0
def clickToPoint(grid, x, y): #need to write to take in origin point 
	#converts position of clicks to a point on the grid

	x = math.trunc(x / view.CELL_SIZE) + grid.origin.x
	y = math.trunc(y/ view.CELL_SIZE) + grid.origin.y
	return entities.Point(x, y)
Пример #27
0
 def test_bottom_neighbor(self):
     assert self.test_point.bottom_neighbor() == e.Point(1, 2, 4)
Пример #28
0
 def setUp(self):
     self.test_point = e.Point(1, 2, 3)
Пример #29
0
 def get_fake_point(p):
     return entities.Point(p.x, p.y - 1)