示例#1
0
	def calculateDamage(self, move_name, user_pokemon, reciever_pokemon, reciever_hp):
		#accuracy removed
		move = Pokedex.getMove(move_name)
		user_type = Pokedex.get(user_pokemon)['type']
		reciever_type = Pokedex.get(reciever_pokemon)['type']
		STAB = 1
		if move['type'] in user_type:
			STAB = 1.5
		type_multiplier = Pokedex.getTypeEffectiveness(move['type'], reciever_type)
		power = 0 if move['power'] is None else move['power']
		damage = STAB * type_multiplier * power
		return damage
示例#2
0
	def extract_atk(self, game_state):
		'''
		Returns booleans for all attack type effectiveness features
		'''
		p2 = game_state.getp2_in_play()
		p1 = game_state.getp1_in_play()
		p2_index = game_state.getp2_pokemon_names().index(p2)
		p1_index = game_state.getp1_pokemon_names().index(p1)
		p1_type = game_state.getp1_pokemon_types()[p1_index]
		p2_type = game_state.getp2_pokemon_types()[p2_index]
		STAB1 = 1
		STAB2 = 1
		type_atk1 = 0
		power_atk1 = 0
		type_atk2 = 0
		power_atk2 = 0
		if game_state.getp1_action() != "switch" and game_state.getp1_action() != "None":
			move1 = Pokedex.getMove(game_state.getp1_action())
			if move1['type'] in p1_type:
				STAB1 = 1.5
		elif game_state.getp1_action() == "None":
			if p1 in game_state.getp1_pokemon_moves().keys():
				moves = game_state.getp1_pokemon_moves()[p1]
				move1 = moves[numpy.random.choice(range(len(moves)))]
				move1 = Pokedex.getMove(move1)
			else:
				moves = Pokedex.getLegalMoves(p1)
				move1 = moves[numpy.random.choice(range(len(moves)))]['name']
				move1 = Pokedex.getMove(move1)
		else:
			move1 = None
		if game_state.getp2_action() != "switch" and game_state.getp2_action() != "None":
			move2 = Pokedex.getMove(game_state.getp2_action())
			if move2['type'] in p2_type:
				STAB2 = 1.5
		elif game_state.getp2_action() == "None":
			if p2 in game_state.getp2_pokemon_moves().keys():
				moves = game_state.getp2_pokemon_moves()[p2]
				move2 = moves[numpy.random.choice(range(len(moves)))]
				move2 = Pokedex.getMove(move2)
			else:
				moves = Pokedex.getLegalMoves(p2)
				move2 = moves[numpy.random.choice(range(len(moves)))]['name']
				move2 = Pokedex.getMove(move2)
		else:
			move2 = None
		#TODO: REMOVE TYPE EFFECTIVENESS ON STATUS MOVES
		if move1 != None:
			type_atk1 = Pokedex.getTypeEffectiveness(move1['type'],p2_type)
			power_atk1 = move1['power']
			if power_atk1 == None:
				power_atk1 = 0
		if move2 != None:
			type_atk2 = Pokedex.getTypeEffectiveness(move2['type'],p1_type)
			power_atk2 = move2['power']
			if power_atk2 == None:
				power_atk2 = 0
		return [type_atk1*power_atk1*STAB1, type_atk2*power_atk2*STAB2]
示例#3
0
	def calculateExpectedNextFeatures(self,active_index, current_features, move_name, my_team, opponent_pokemon):
		#true_effect = anticipated reward, anticipated
		#TODO: FINISH IMPLIMENTATION --> expected damage from attack, expected change in status features, expected effect on own hp. 
		#TODO: FIGURE OUT ORDER OF TURNS
		next_state_features = current_features
		if move_name == 'None' or move_name == None:
			move_name = 'Growl'
		move = Pokedex.getMove(move_name)
		effect_id = move['effect_id']
		effect_prob = move['effect_prob']
		if effect_id in Pokedex.effects.keys():
			effect = Pokedex.effects[effect_id]
		else:
			effect = 'None'
		p1 = my_team[active_index]
		p2 = opponent_pokemon
		p1_faint = 0
		p2_faint = 0
		order = self.getFirstPlayer(my_team,active_index,opponent_pokemon,move_name)
		atk1 = self.calculateDamage(move_name, p1['name'], p2['name'], p1['current_hp'])*move['accuracy']
		if 'par' in p1['status']:
			atk1 = atk1 *.75
		next_state_features['atk1'] = atk1
		if self.calculateDamage(move_name, p1['name'], p2['name'], p2['current_hp']) > p2['current_hp']:
			#doesn't include possibility of opponent switch
			next_state_features['remaining2']=current_features['remaining1']-move['accuracy']
			p2_faint = move['accuracy']
		if effect == "heal":
			max_hp = p1['hp']
			if move == "rest":
				if .5*max_hp+p1['current_hp'] < max_hp:
					heal1 = .5*max_hp+p1['current_hp']* effect_prob
				else:
					heal1 = max_hp*effect_prob - p1['current_hp']
			elif move == "rest":
				heal1 = max_hp*effect_prob - p1['current_hp']
			else:
				heal1 = .5*atk1
			next_state_features['heal1']=heal1
		if effect == "opponent_status:psn":
			if current_features['tox2'] < 1:
				next_state_features['tox2']= move['effect_prob']
		elif effect == "opponent_status:par":
			if current_features['par2'] < 1:
				next_state_features['par2']= move['effect_prob']
		elif effect == "opponent_status:brn":
			if current_features['brn2'] < 1:
				next_state_features['brn2']= move['effect_prob']
		atk2 = 0
		avg_accuracy = 0
		for i in opponent_pokemon['known_moves']:
			atk2 += Pokedex.getMove(i)*self.calculateDamage(i,my_team[active_index]['name'],opponent_pokemon['name'],opponent_pokemon['current_hp'])/4
			avg_accuracy += Pokedex.getMove(i)['accuracy']/4
		for num in range(4-len(opponent_pokemon['known_moves'])):
			poss_moves2 = Pokedex.getLegalMoves(opponent_pokemon['name'])
			move_added = False
			while not move_added:
				i = random.choice(range(len(poss_moves2)))
				if i not in opponent_pokemon['known_moves']:
					atk2 += poss_moves2[i]['accuracy'] * self.calculateDamage(poss_moves2[i]['name'], my_team[active_index]['name'], opponent_pokemon['name'], opponent_pokemon['current_hp']) / 4
					avg_accuracy += poss_moves2[i]['accuracy']/4
					move_added = True
		next_state_features['atk2'] = atk2*avg_accuracy
		if order[0] == 1:
			next_state_features['atk2'] = atk2*(1-move['accuracy'])
		if atk2 > p1['current_hp']:
			next_state_features['remaining1']=current_features['remaining1']-avg_accuracy
			p1_faint = avg_accuracy
		if order[0] == 2:
			next_state_features['atk1'] = next_state_features['atk1']*(1-avg_accuracy)
		#Not dealing with effects on p1, too difficult to account for
		next_state_features['par1'] = current_features['par1']
		next_state_features['tox1'] = current_features['tox1']
		next_state_features['brn1'] = current_features['brn1']
		return next_state_features