def seek_path(self, wrld):
        search = perform_aStar(wrld, (self.x, self.y),
                               self.get_exit_location(wrld), False)

        if search == None:
            return
        self.move(search[0], search[1])
def monsterInLineOfSight(wrld, character):
    monsters = findAll(wrld, 2)
    surrounds = [(1,1),(1,-1),(-1,1),(1,0),(-1,0),(0,1),(0,-1),(-1,-1)]

    if len(monsters) == 0:
        return 0
    
    pos = (character.x, character.y)
    nearest_monster = findNearestEntity(wrld, pos, monsters)
    
    distance = perform_aStar(wrld, pos, nearest_monster, True)
    
    if len(distance) == 0:
        return 0
    
    for i in surrounds:
        x, y = character.x, character.y
        
        for j in range(8):
            x += i[0]
            y += i[1]
            
            if __inWorld(wrld, x, y) is False:
                continue
            
            if wrld.wall_at(x, y) is True:
                continue
            
            if wrld.monsters_at(x, y) is not None:
                return 1
            
            
    return 0
Exemple #3
0
    def a_star(self, wrld, dest=None):

        dest = dest if dest is not None else self.get_exit_location(wrld)
        search = perform_aStar(wrld, (self.x, self.y), dest, False)

        if len(search) == 0:
            self.move(0, 1)
            return

        self.move(search[0], search[1])
def doesPathToExitExist(wrld, character):
	exit = findAll(wrld, 0)

	pos = (character.x, character.y)
	nearest_exit = findNearestEntity(wrld, pos, exit)

	distance = len(perform_aStar(wrld, pos, nearest_exit, True))

	if distance == 0:
		return 1

	return 0
Exemple #5
0
	def do(self, wrld):
     
		monsters = findAll(wrld, 2)
		distance = 0
		nearest_monster = "nothing"
  
		if len(monsters) > 0:
			monster = findNearestEntity(wrld, (self.x,self.y), monsters)
			distance = len(perform_aStar(wrld, (self.x,self.y), (monster[0], monster[1]), True))
			nearest_monster = wrld.monsters_at(monster[0], monster[1])[0]
   
			# print(distance)
			if distance <= 2 and distance > 0 and nearest_monster.name != "aggressive":
				self.state = "qlearn"
   
   
		# print(self.state)
		if self.state == "bomb":
			if self.bomb_locations[self.location_index - 1][2] is True:
				self.place_bomb()
				self.state = "dodge"

			elif wrld.monsters_at(7, 8) or len(monsters) == 0:
				self.location_index = len(self.bomb_locations) - 1       
				self.state = "go"


		elif self.state == "dodge":
			x, y = self.x, self.y

			if self.location_index <= len(self.bomb_locations):
				if self.bomb_locations[self.location_index - 1][2] is False:
					#self.location_index = 5
					self.state = "go"
					return 

			if can_move(wrld, (x,y), self.dxdy) is True:
				if self.x >= wrld.width() - 1:
					self.move(-1, -1)
				else:
					self.move(1, self.dxdy[1])
    
			else:
				
				if self.location_index - 1 == 10:
					self.move(-1, 1)
				else:
					self.move(1, -1)

			self.state = "wait"
    
		elif self.state == "go":
			goal = self.bomb_locations[self.location_index]
			goal = (goal[0], goal[1])
			self.a_star(wrld, goal)
   
			if goal[0] == self.x and goal[1] == self.y:
				self.state = "bomb"
				self.location_index += 1
	
		elif self.state == "wait":
    
			if foundBomb(wrld) is not True:
				if foundExplosion(wrld) is not True:
					self.state = "go"
			else:
				self.move(0,0)
		else:
			if (distance > 3 or distance == 0) and self.qLearning is True:
				if self.location_index != 0:
					self.location_index -= 1
     
				self.state = "go"
				self.qLearning = False
				return

			self.qLearning = True
			self.perform_qLearning(wrld)