本文整理汇总了Python中brain.Brain.process_input方法的典型用法代码示例。如果您正苦于以下问题:Python Brain.process_input方法的具体用法?Python Brain.process_input怎么用?Python Brain.process_input使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类brain.Brain
的用法示例。
在下文中一共展示了Brain.process_input方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import process_input [as 别名]
class Organism:
def __init__(self,id=0, color=None, game=None):
self.id = id
self.pos_x = random.randint(0, settings.SCREEN_WIDTH)
self.pos_y = random.randint(0, settings.SCREEN_HEIGHT)
self.pos_last_x = self.pos_x
self.pos_last_y = self.pos_y
self.energy = settings.STARTING_ENERGY
self.age = 0
self.reproduce_time = settings.REPRODUCTION_TIME * (random.randint(75, 125) / 100.0)
self.distance_from_food = 0
self.color = color or (random.randint(150,255),random.randint(150,255),random.randint(150,255))
self.game = game
self.brain = Brain()
def move(self,x,y):
self.pos_last_x = self.pos_x
self.pos_last_y = self.pos_y
self.pos_x += x
self.pos_y += y
if self.pos_x < 0:
self.pos_x = settings.SCREEN_WIDTH
if self.pos_x > settings.SCREEN_WIDTH:
self.pos_x = 0
if self.pos_y < 0:
self.pos_y = settings.SCREEN_HEIGHT
if self.pos_y > settings.SCREEN_HEIGHT:
self.pos_y = 0
def map_position(self):
x = (int(self.pos_x)/self.game.map.TILE_SIZE) % self.game.map.MAX_X
y = (int(self.pos_y)/self.game.map.TILE_SIZE) % self.game.map.MAX_Y
return x, y
def scan(self):
# build a list of all of the tiles around the organism
vals = [0,0,0,0,0,0,0,0,0]
x, y = self.map_position()
m = self.game.map.tiles
vals[0] = self.game.map.get_tile(x, y)
vals[1] = self.game.map.get_tile(x-1,y+1)
vals[2] = self.game.map.get_tile(x, y+1)
vals[3] = self.game.map.get_tile(x+1,y+1)
vals[4] = self.game.map.get_tile(x+1,y)
vals[5] = self.game.map.get_tile(x+1,y-1)
vals[6] = self.game.map.get_tile(x ,y-1)
vals[7] = self.game.map.get_tile(x-1,y-1)
vals[8] = self.game.map.get_tile(x-1,y)
return vals
def check_for_food(self):
# see if we're close enough to a food source to receive energy
x,y = self.map_position()
self.distance_from_food = 1000000
for i in range(self.game.map.MAX_X):
for j in range(self.game.map.MAX_Y):
if self.game.map.tiles[i][j] == self.game.map.FOOD_TILE:
d = math.hypot(i-(x),j-(y+1))
if d < self.distance_from_food:
self.distance_from_food = d
if d <= 1:
if self.energy < settings.MAX_ENERGY:
self.energy += 10
for fs in self.game.map.food_sources:
id = "%d-%d" % (i,j)
if fs["id"] == id:
fs["store"] -= 10
def step(self):
# process movement, food, age and reproduction
mx, my = self.brain.process_input(self.scan())
self.move(mx, my)
self.check_for_food()
self.energy -= 1
self.reproduce_time -= 1
self.age += 1