Updated again state and reward features
|
@ -47,4 +47,4 @@
|
||||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,395,395,395,395,395,395,-1,-1,395,395,395,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,395,-1,-1,-1,-1,-1,-1
|
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,395,395,395,395,395,395,-1,-1,395,395,395,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,395,-1,-1,-1,-1,-1,-1
|
||||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,395,395,395,395,-1,395,395,395,395,395,395,395,395,395,-1,395,395,-1,-1,-1,-1,-1,-1
|
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,395,395,395,395,-1,395,395,395,395,395,395,395,395,395,-1,395,395,-1,-1,-1,-1,-1,-1
|
||||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,395,395,395,-1,-1,-1,-1,-1,-1,-1
|
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,395,395,395,-1,-1,-1,-1,-1,-1,-1
|
||||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
|
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,600
|
||||||
|
|
|
|
@ -19,6 +19,7 @@ class Player(pygame.sprite.Sprite):
|
||||||
player_id,
|
player_id,
|
||||||
role,
|
role,
|
||||||
position,
|
position,
|
||||||
|
map_edge,
|
||||||
groups,
|
groups,
|
||||||
obstacle_sprites,
|
obstacle_sprites,
|
||||||
visible_sprites,
|
visible_sprites,
|
||||||
|
@ -28,6 +29,7 @@ class Player(pygame.sprite.Sprite):
|
||||||
super().__init__(groups)
|
super().__init__(groups)
|
||||||
|
|
||||||
self.initial_position = position
|
self.initial_position = position
|
||||||
|
self.map_edge = map_edge
|
||||||
self.player_id = player_id
|
self.player_id = player_id
|
||||||
self.distance_direction_from_enemy = None
|
self.distance_direction_from_enemy = None
|
||||||
|
|
||||||
|
@ -146,6 +148,14 @@ class Player(pygame.sprite.Sprite):
|
||||||
|
|
||||||
def get_current_state(self):
|
def get_current_state(self):
|
||||||
|
|
||||||
|
def fermi(x, a):
|
||||||
|
# Used for rescaling features
|
||||||
|
return 1 / (np.exp(-(x - a)) + 1)
|
||||||
|
|
||||||
|
def maxwell(x, a):
|
||||||
|
# Used for rescaling features
|
||||||
|
return 1 / np.exp((x - a) / a)
|
||||||
|
|
||||||
if self.distance_direction_from_enemy != []:
|
if self.distance_direction_from_enemy != []:
|
||||||
sorted_distances = sorted(
|
sorted_distances = sorted(
|
||||||
self.distance_direction_from_enemy, key=lambda x: x[0])
|
self.distance_direction_from_enemy, key=lambda x: x[0])
|
||||||
|
@ -159,26 +169,34 @@ class Player(pygame.sprite.Sprite):
|
||||||
self.reward_features = [
|
self.reward_features = [
|
||||||
self.stats.exp,
|
self.stats.exp,
|
||||||
|
|
||||||
10/nearest_dist if nearest_dist > 10 else 1,
|
fermi(nearest_dist, 10),
|
||||||
|
|
||||||
1/(np.exp((nearest_enemy.stats.health -
|
fermi(
|
||||||
nearest_enemy.stats.monster_info['health'])
|
nearest_enemy.stats.health,
|
||||||
/ nearest_enemy.stats.monster_info['health'])) - 1,
|
nearest_enemy.stats.monster_info['health']
|
||||||
|
),
|
||||||
|
|
||||||
1/(np.exp((len(self.distance_direction_from_enemy) -
|
maxwell(
|
||||||
self.max_num_enemies)/self.max_num_enemies)) - 1,
|
len(self.distance_direction_from_enemy),
|
||||||
|
self.max_num_enemies
|
||||||
|
) - 1,
|
||||||
|
|
||||||
|
- fermi(
|
||||||
|
self.stats.health,
|
||||||
|
self.stats.stats['health']
|
||||||
|
),
|
||||||
|
|
||||||
1 - 1/(np.exp((self.stats.health -
|
|
||||||
self.stats.stats['health'])/self.stats.stats['health']))
|
|
||||||
]
|
]
|
||||||
|
|
||||||
self.state_features = [
|
self.state_features = [
|
||||||
np.exp(-self.animation.rect.center[0]),
|
self.animation.rect.center[0]/self.map_edge[0],
|
||||||
np.exp(-self.animation.rect.center[1]),
|
self.animation.rect.center[1]/self.map_edge[1],
|
||||||
self._input.movement.direction.x,
|
self._input.movement.direction.x,
|
||||||
self._input.movement.direction.y,
|
self._input.movement.direction.y,
|
||||||
self.stats.health/self.stats.stats['health'],
|
self.stats.health/self.stats.stats['health'],
|
||||||
self.stats.energy/self.stats.stats['energy']
|
self.stats.energy/self.stats.stats['energy'],
|
||||||
|
1 if 'attack' in self._input.status else 0,
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
enemy_states = []
|
enemy_states = []
|
||||||
|
@ -186,15 +204,14 @@ class Player(pygame.sprite.Sprite):
|
||||||
for distance, direction, enemy in self.distance_direction_from_enemy:
|
for distance, direction, enemy in self.distance_direction_from_enemy:
|
||||||
enemy_states.extend([
|
enemy_states.extend([
|
||||||
|
|
||||||
10/distance if distance > 10 else 1,
|
fermi(distance, 10),
|
||||||
|
|
||||||
direction[0],
|
direction[0],
|
||||||
|
|
||||||
direction[1],
|
direction[1],
|
||||||
|
|
||||||
1/(np.exp((nearest_enemy.stats.health -
|
nearest_enemy.stats.health /
|
||||||
nearest_enemy.stats.monster_info['health'])
|
nearest_enemy.stats.monster_info['health'],
|
||||||
/ nearest_enemy.stats.monster_info['health'])) - 1,
|
|
||||||
|
|
||||||
enemy.stats.exp,
|
enemy.stats.exp,
|
||||||
])
|
])
|
||||||
|
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 51 KiB |
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 29 KiB |
11
level.py
|
@ -79,12 +79,16 @@ class Level:
|
||||||
|
|
||||||
# Generate unpassable terrain
|
# Generate unpassable terrain
|
||||||
if style == 'boundary':
|
if style == 'boundary':
|
||||||
if col != '700':
|
|
||||||
|
if col == '600':
|
||||||
|
self.map_edge = (x, y)
|
||||||
|
|
||||||
|
elif col != '700':
|
||||||
Terrain((x, y),
|
Terrain((x, y),
|
||||||
[self.obstacle_sprites,
|
[self.obstacle_sprites,
|
||||||
self.visible_sprites],
|
self.visible_sprites],
|
||||||
'invisible')
|
'invisible')
|
||||||
if col == '700':
|
elif col == '700' and self.n_players > 1:
|
||||||
print(f"Prison set at:{(x, y)}")
|
print(f"Prison set at:{(x, y)}")
|
||||||
# Generate grass
|
# Generate grass
|
||||||
if style == 'grass':
|
if style == 'grass':
|
||||||
|
@ -145,6 +149,7 @@ class Level:
|
||||||
player_id,
|
player_id,
|
||||||
'tank',
|
'tank',
|
||||||
choice(self.possible_player_locations),
|
choice(self.possible_player_locations),
|
||||||
|
self.map_edge,
|
||||||
[self.visible_sprites],
|
[self.visible_sprites],
|
||||||
self.obstacle_sprites,
|
self.obstacle_sprites,
|
||||||
self.visible_sprites,
|
self.visible_sprites,
|
||||||
|
@ -215,7 +220,7 @@ class Level:
|
||||||
player.stats.energy\
|
player.stats.energy\
|
||||||
= player.stats.stats['energy']
|
= player.stats.stats['energy']
|
||||||
|
|
||||||
# player.stats.exp = 0
|
player.stats.exp = 0
|
||||||
|
|
||||||
self.get_entities()
|
self.get_entities()
|
||||||
self.get_distance_direction()
|
self.get_distance_direction()
|
||||||
|
|