changes in tilesFactory and added KABOOM img

This commit is contained in:
piowyg 2021-05-17 23:22:57 +02:00
parent 7a4285c053
commit 363ea4b786
5 changed files with 53 additions and 45 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 KiB

View File

@ -34,7 +34,9 @@ for name, val in {
main_path + '/images/Tiles/' + name + ".png"
),
None if 'mine' not in name else (
'AP' if 'AP' in name else 'AT'
'AP' if 'AP' in name else (
'AT' if 'AT' in name else 'ADM'
)
)
)
)
@ -53,15 +55,15 @@ for name in [
))
DEBUG_FIELD = [
[Tile(1, 1), Tile(11, 20), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1)],
[Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(4, 1, APMine()), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1)],
[Tile(11, 20), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(11, 20), Tile(4, 0, APMine()), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1)],
[Tile(4, 0, APMine()), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(11, 20), Tile(1, 1),Tile(1, 1), Tile(4, 0, APMine()), Tile(1, 1),Tile(1, 1)],
[Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(11, 20), Tile(1, 1), Tile(1, 1)],
[Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(11, 20), Tile(4, 0, APMine()), Tile(1, 1)],
[Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(11, 20), Tile(1, 1), Tile(1, 1)],
[Tile(1, 1) for _ in range(10)],
[Tile(1, 1) for _ in range(10)],
[Tile(1, 1) for _ in range(10)],
]
# DEBUG_FIELD = [
# [Tile(1, 1), Tile(11, 20), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1)],
# [Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(4, 1, APMine()), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1)],
# [Tile(11, 20), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(11, 20), Tile(4, 0, APMine()), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1)],
# [Tile(4, 0, APMine()), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(11, 20), Tile(1, 1),Tile(1, 1), Tile(4, 0, APMine()), Tile(1, 1),Tile(1, 1)],
# [Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(11, 20), Tile(1, 1), Tile(1, 1)],
# [Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(11, 20), Tile(4, 0, APMine()), Tile(1, 1)],
# [Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(1, 1), Tile(11, 20), Tile(1, 1), Tile(1, 1)],
# [Tile(1, 1) for _ in range(10)],
# [Tile(1, 1) for _ in range(10)],
# [Tile(1, 1) for _ in range(10)],
# ]

View File

@ -4,7 +4,7 @@ from agent import Agent
from game_ui import GameUi
from environment import Environment
from tilesFactory import TilesFactory
from const import ICON, IMAGES, DEBUG_FIELD
from const import ICON, IMAGES
from src.search_algoritms.a_star import a_star
from search_algoritms.BFS import breadth_first_search_for_a_star
from machine_learning.decision_tree import get_decision, tree_root
@ -42,7 +42,7 @@ def main():
pg.display.set_icon(pg.image.load(ICON))
pg.fastevent.init()
env = Environment(DEBUG_FIELD)
env = Environment()
agent = Agent()
game_ui = GameUi(agent, env)
game_ui.update()
@ -63,7 +63,7 @@ def main():
elif event.type == pg.KEYDOWN:
if event.key == pg.K_t:
print('Starting to clear the sector')
while env.mine_count:
#while env.mine_count:
print('-' * 20)
# path, actions = breadth_first_search(env.field, agent.x, agent.y, agent.direction)
goal = breadth_first_search_for_a_star(env.field, agent.x, agent.y, agent.direction)
@ -85,6 +85,7 @@ def main():
'pressure_gt_two': True if goal_tile.mine.pressure > 2 else False
}
decision = get_decision(data, tree_root)
print(data)
print(f'Decision: {decision}')
pg.fastevent.post(pg.event.Event(pg.KEYDOWN, {'key': pg.K_SPACE}))
handle_keys(env, agent, game_ui, factory)

View File

@ -3,5 +3,5 @@ from typing import Union
class Mine:
def __init__(self, pressure: Union[float, int], armed: bool):
self.is_armed = armed
self.armed = armed
self.pressure = pressure

View File

@ -1,18 +1,23 @@
from random import uniform,choice
from typing import List
from importlib import import_module
from tile import Tile
from const import IMAGES
from machine_learning.data_set import visibility,stability,ground,armed
class TilesFactory:
def create_tile(self, number: int) -> Tile:
img = IMAGES[number]
if img.mine_type:
module = import_module(f'{img.mine_type.lower()}_mine')
return Tile(number, 0, getattr(module, f'{img.mine_type}Mine')())
return Tile(number, 0, self.get_random_value(visibility), self.get_random_value(stability), self.get_random_value(ground), getattr(module, f'{img.mine_type}Mine')(uniform(1, 5
if img.mine_type == 'AP' or img.mine_type == 'AT' else 50), self.get_random_value(armed)))
else:
return Tile(number, 5) if 'grass' in img.name else Tile(number, 30)
return Tile(number, 5, self.get_random_value(visibility), self.get_random_value(stability), self.get_random_value(ground)) if 'grass' in img.name else Tile(number, 30, self.get_random_value(visibility), self.get_random_value(stability), self.get_random_value(ground))
def get_tiles_list(self) -> List[Tile]:
return [self.create_tile(i) for i in range(13)]
def get_random_value(self, values):
return choice(values)