Compare commits

..

No commits in common. "master" and "knights_attack_v2" have entirely different histories.

10 changed files with 43 additions and 1120 deletions

View File

@ -6,7 +6,7 @@ GAME_TITLE = 'WMICraft'
WINDOW_HEIGHT = 800
WINDOW_WIDTH = 1360
FPS_COUNT = 60
TURN_INTERVAL = 200
TURN_INTERVAL = 100
GRID_CELL_PADDING = 5
GRID_CELL_SIZE = 36

View File

@ -299,4 +299,4 @@ tower_dist;mob1_dist;mob2_dist;opp1_dist;opp2_dist;opp3_dist;opp4_dist;agent_hp;
29;25;30;19;35;38;33;6;68;5;1;0;5;11;6;mob1
23;43;41;25;27;26;19;7;12;8;3;4;10;11;9;tower
7;9;18;31;36;21;16;4;23;8;4;9;8;11;5;tower
35;21;39;36;36;37;33;10;41;9;4;1;0;7;0;mob1
35;21;39;36;36;37;33;10;41;9;4;1;0;7;0;mob1
1 tower_dist mob1_dist mob2_dist opp1_dist opp2_dist opp3_dist opp4_dist agent_hp tower_hp mob1_hp mob2_hp opp1_hp opp2_hp opp3_hp opp4_hp goal
299 29 25 30 19 35 38 33 6 68 5 1 0 5 11 6 mob1
300 23 43 41 25 27 26 19 7 12 8 3 4 10 11 9 tower
301 7 9 18 31 36 21 16 4 23 8 4 9 8 11 5 tower
302 35 21 39 36 36 37 33 10 41 9 4 1 0 7 0 mob1

File diff suppressed because it is too large Load Diff

View File

@ -26,7 +26,7 @@ def parse_idx_of_opp_or_monster(s: str) -> int:
class DecisionTree:
def __init__(self) -> None:
data_frame = pd.read_csv('learning/dataset_tree_1000.csv', delimiter=';')
data_frame = pd.read_csv('learning/dataset_tree.csv', delimiter=';')
unlabeled_goals = data_frame['goal']
self.goals_label_encoder = LabelEncoder()
self.goals = self.goals_label_encoder.fit_transform(unlabeled_goals)

View File

@ -45,7 +45,6 @@ class Game:
# create level
level.create_map()
stats = Stats(self.screen, level.list_knights_blue, level.list_knights_red)
level.setup_stats(stats)
print_numbers_flag = False
running = True

View File

@ -31,15 +31,6 @@ class Level:
self.knights_queue = None
self.stats = None
def setup_stats(self, stats):
self.stats = stats
def add_points(self, team, points_to_add):
if self.stats is not None:
self.stats.add_points(team, points_to_add)
def create_map(self):
self.map = import_random_map()
self.setup_base_tiles()
@ -101,111 +92,54 @@ class Level:
self.map[row_index][col_index] = castle
self.list_castles.append(castle)
#def attack_knight(self, knights_list, positions, current_knight):
# op_pos_1 = current_knight.position[0] - 1, current_knight.position[1]
# positions.append(op_pos_1)
# op_pos_2 = current_knight.position[0], current_knight.position[1] - 1
# positions.append(op_pos_2)
# op_pos_3 = current_knight.position[0] + 1, current_knight.position[1]
# positions.append(op_pos_3)
# op_pos_4 = current_knight.position[0], current_knight.position[1] + 1
# positions.append(op_pos_4)
# for some_knight in knights_list:
# for some_position in positions:
# if (some_knight.position == some_position and some_knight.team != current_knight.team):
# some_knight.health_bar.take_dmg(current_knight.attack)
# if some_knight.health_bar.current_hp == 0:
# some_knight.kill()
# positions.clear()
def attack_knight(self, knights_list, positions, current_knight):
op_pos_1 = current_knight.position[0] - 1, current_knight.position[1]
positions.append(op_pos_1)
op_pos_2 = current_knight.position[0], current_knight.position[1] - 1
positions.append(op_pos_2)
op_pos_3 = current_knight.position[0] + 1, current_knight.position[1]
positions.append(op_pos_3)
op_pos_4 = current_knight.position[0], current_knight.position[1] + 1
positions.append(op_pos_4)
for some_knight in knights_list:
for some_position in positions:
if some_knight.position == some_position:
some_knight.health_bar.take_dmg(1)
if some_knight.health_bar.current_hp == 0:
some_knight.kill()
positions.clear()
def attack_knight_left(self, knights_list, current_knight):
position_left = current_knight.position[0] - 1, current_knight.position[1]
for some_knight in knights_list:
if (some_knight.position == position_left and some_knight.team != current_knight.team):
some_knight.health_bar.take_dmg(current_knight.attack)
if some_knight.health_bar.current_hp <= 0:
if some_knight.position == position_left:
some_knight.health_bar.take_dmg(1)
if some_knight.health_bar.current_hp == 0:
some_knight.kill()
self.add_points(current_knight.team, 5)
for monster in self.list_monsters:
if monster.position == position_left:
monster.health_bar.take_dmg(current_knight.attack)
if monster.health_bar.current_hp <= 0:
monster.kill()
self.add_points(current_knight.team, monster.points)
else:
current_knight.health_bar.take_dmg(monster.attack)
if current_knight.health_bar.current_hp <= 0:
current_knight.kill()
for castle in self.list_castles:
if castle.position == position_left:
castle.health_bar.take_dmg(current_knight.attack)
def attack_knight_right(self, knights_list, current_knight):
position_right = current_knight.position[0] + 1, current_knight.position[1]
for some_knight in knights_list:
if (some_knight.position == position_right and some_knight.team != current_knight.team):
some_knight.health_bar.take_dmg(current_knight.attack)
if some_knight.position == position_right:
some_knight.health_bar.take_dmg(1)
if some_knight.health_bar.current_hp == 0:
some_knight.kill()
self.add_points(current_knight.team, 5)
for monster in self.list_monsters:
if monster.position == position_right:
monster.health_bar.take_dmg(current_knight.attack)
if monster.health_bar.current_hp <= 0:
monster.kill()
self.add_points(current_knight.team, monster.points)
else:
current_knight.health_bar.take_dmg(monster.attack)
if current_knight.health_bar.current_hp <= 0:
current_knight.kill()
for castle in self.list_castles:
if castle.position == position_right:
castle.health_bar.take_dmg(current_knight.attack)
def attack_knight_up(self, knights_list, current_knight):
position_up = current_knight.position[0], current_knight.position[1] - 1
position_up = current_knight.position[0] , current_knight.position[1] - 1
for some_knight in knights_list:
if (some_knight.position == position_up and some_knight.team != current_knight.team):
some_knight.health_bar.take_dmg(current_knight.attack)
if some_knight.position == position_up:
some_knight.health_bar.take_dmg(1)
if some_knight.health_bar.current_hp == 0:
some_knight.kill()
self.add_points(current_knight.team, 5)
for monster in self.list_monsters:
if monster.position == position_up:
monster.health_bar.take_dmg(current_knight.attack)
if monster.health_bar.current_hp <= 0:
monster.kill()
self.add_points(current_knight.team, monster.points)
else:
current_knight.health_bar.take_dmg(monster.attack)
if current_knight.health_bar.current_hp <= 0:
current_knight.kill()
for castle in self.list_castles:
if castle.position == position_up:
castle.health_bar.take_dmg(current_knight.attack)
def attack_knight_down(self, knights_list, current_knight):
position_down = current_knight.position[0], current_knight.position[1] + 1
for some_knight in knights_list:
if (some_knight.position == position_down and some_knight.team != current_knight.team):
some_knight.health_bar.take_dmg(current_knight.attack)
if some_knight.position == position_down:
some_knight.health_bar.take_dmg(1)
if some_knight.health_bar.current_hp == 0:
some_knight.kill()
self.add_points(current_knight.team, 5)
for monster in self.list_monsters:
if monster.position == position_down:
monster.health_bar.take_dmg(current_knight.attack)
if monster.health_bar.current_hp <= 0:
monster.kill()
self.add_points(current_knight.team, monster.points)
else:
current_knight.health_bar.take_dmg(monster.attack)
if current_knight.health_bar.current_hp <= 0:
current_knight.kill()
for castle in self.list_castles:
if castle.position == position_down:
castle.health_bar.take_dmg(current_knight.attack)
def handle_turn(self):
current_knight = self.knights_queue.dequeue_knight()

View File

@ -16,7 +16,8 @@ class Castle(pygame.sprite.Sprite):
position_in_px = (parse_cord(position[0]), parse_cord(position[1]))
self.rect = self.image.get_rect(center=position_in_px)
self.max_hp = 80
self.health_bar = HealthBar(screen, self.rect, current_hp=self.max_hp, max_hp=self.max_hp, calculate_xy=True, calculate_size=True)
self.current_hp = random.randint(1, self.max_hp)
self.health_bar = HealthBar(screen, self.rect, current_hp=self.current_hp, max_hp=self.max_hp, calculate_xy=True, calculate_size=True)
def update(self):
self.health_bar.update()

View File

@ -7,11 +7,8 @@ from common.helpers import parse_cord
from logic.health_bar import HealthBar
def load_knight_textures(team):
if team == "blue":
random_index = 3
else:
random_index = 4
def load_knight_textures():
random_index = random.randint(1, 4)
states = [
pygame.image.load(f'resources/textures/knight_{random_index}_up.png').convert_alpha(), # up = 0
pygame.image.load(f'resources/textures/knight_{random_index}_right.png').convert_alpha(), # right = 1
@ -27,7 +24,7 @@ class Knight(pygame.sprite.Sprite):
super().__init__(group)
self.direction = Direction.DOWN
self.states = load_knight_textures(team)
self.states = load_knight_textures()
self.image = self.states[self.direction.value]
self.position = position
@ -36,8 +33,8 @@ class Knight(pygame.sprite.Sprite):
self.rect = self.image.get_rect(topleft=position_in_px)
self.team = team
self.max_hp = random.randint(9, 13)
self.attack = random.randint(2, 4)
self.max_hp = random.randint(7, 12)
self.attack = random.randint(4, 7)
self.defense = random.randint(1, 4)
self.points = 1
self.health_bar = HealthBar(screen, self.rect, current_hp=self.max_hp, max_hp=self.max_hp, calculate_xy=True, calculate_size=True)

View File

@ -22,13 +22,14 @@ class Monster(pygame.sprite.Sprite):
position_in_px = (parse_cord(position[0]), parse_cord(position[1]))
self.rect = self.image.get_rect(topleft=position_in_px)
self.position = position
self.max_hp = random.randrange(15, 20)
self.health_bar = HealthBar(screen, self.rect, current_hp=self.max_hp, max_hp=self.max_hp,
self.max_hp = random.randrange(15, 25)
self.current_hp = random.randint(1, self.max_hp)
self.health_bar = HealthBar(screen, self.rect, current_hp=self.current_hp, max_hp=self.max_hp,
calculate_xy=True, calculate_size=True)
self.attack = random.randrange(4, 6)
self.attack = random.randrange(2, 10)
if self.image == monster_images[0]:
self.max_hp = 20
self.attack = 6
self.attack = 9
self.points = 10
elif self.image == monster_images[1]:
self.max_hp = 15

View File

@ -23,8 +23,6 @@ class Stats:
pygame.Rect(self.x + 210, self.y + 210, 100, 15),
current_hp=sum([knight.get_current_hp() for knight in self.list_knights_red]),
max_hp=sum([knight.get_max_hp() for knight in self.list_knights_red]))
self.blue_team_points = 0
self.red_team_points = 0
def update(self):
@ -57,11 +55,5 @@ class Stats:
# points
pygame.draw.rect(self.screen, ORANGE, pygame.Rect(self.x, self.y + 390, 340, 3))
draw_text('PUNKTY: ' + str(self.blue_team_points), FONT_DARK, self.screen, self.x + 35, self.y + 408, 18, True)
draw_text('PUNKTY: ' + str(self.red_team_points), FONT_DARK, self.screen, self.x + 215, self.y + 408, 18, True)
def add_points(self, team, points):
if team == "blue":
self.blue_team_points += points
else:
self.red_team_points += points
draw_text('PUNKTY: 10', FONT_DARK, self.screen, self.x + 35, self.y + 408, 18, True)
draw_text('PUNKTY: 10', FONT_DARK, self.screen, self.x + 215, self.y + 408, 18, True)