diff --git a/debug.py b/debug.py index 45fbf48..27df5ca 100644 --- a/debug.py +++ b/debug.py @@ -3,14 +3,39 @@ import random as _rand import main as _main from utils import logs as _logs from bot_libs import syms as _syms +from entities.items import syms as _isyms + + +def _extract_random_number_of_items(Arena): + players= Arena.get_players() + nplayers= len(players) + min_extraction= max(nplayers - 5, 3) + max_extraction= min(nplayers - 1, 8) + nitems= _rand.randint(min_extraction, max_extraction) + return nitems + +def _get_random_items(Arena): + items= [] + nitems= _extract_random_number_of_items(Arena) + for n in range(nitems): + itype= _rand.sample(_isyms.ITEMS_LIST, 1)[0] + items.append(itype) + return items def _debug_data(): players= _syms.COLORS_NAMES - weapons= [] + nelected_players= _rand.randint(6, 12) + elected_players= _rand.sample(players, nelected_players) Arena= _main.init_arena() - for player in players: + for player in elected_players: Arena.add_player(player) + _logs.log_debug('Players: {elected_players}') + + items= _get_random_items(Arena) + for item in items: + Arena.add_item(item) + _logs.log_info('Items: {items}') return Arena def _end_game_debug(alive_players, day): @@ -89,7 +114,7 @@ def init_debug_simulation(): _logs.log_debug('#################') _logs.log_debug('#################') _logs.log_debug('#################') - _time.sleep(0.3) + _time.sleep(0.7) def init_debug_attack_loop(): Arena= _debug_data() diff --git a/entities/arena.py b/entities/arena.py index 6db7137..da6a516 100644 --- a/entities/arena.py +++ b/entities/arena.py @@ -1,33 +1,33 @@ from entities import player as _player from entities import event_picker as _events from entities import gamemap as _map -from entities.items import weapons as _weapons +from entities.items import item as _items from utils import logs as _logs class BrSimArena(): # players = [{'name': name, 'inventory': default_inventory, other_stats}] - # weapons = [{WEAPON.KNIFE: quantity}, etc...] # this is the whole quantity of the items available on the world + # items = [{WEAPON.KNIFE: quantity}, etc...] # this is the whole quantity of the items available on the world - def __init__(self, players= None, weapons= None): + def __init__(self, players= None, items= None): self.day= 1 self.players= [] - self.weapons= [] + self.items= [] self.eventClass = _events.ArenaEventPicker(self.players) self.init_players(players) - self.init_weapons(weapons) - self.Map= _map.BrSimMap(self.players, self.weapons) + self.init_items(items) + self.Map= _map.BrSimMap(self.players, self.items) def init_players(self, players): if not players: return for player in players: self.add_player(player['name'], player.get('inventory')) - def init_weapons(self, weapons): - if not weapons: return - for weapon in weapons: - for wtype, quantity in weapon.items(): - for i in range(quantity): self.weapons.append(_weapons.BrSimWeapon(wtype)) + def init_items(self, items): + if not items: return + for item in items: + for itype, quantity in item.items(): + for i in range(quantity): self.items.append(_items.BrSimItem(wrype)) def next_day(self): self.day+= 1 @@ -116,19 +116,19 @@ class BrSimArena(): self.players.append(player) self.Map.add_player_to_map(player) - def add_weapon(self, weapon_type): - weapon= _weapons.BrSimWeapon(weapon_type) - self.weapons.append(weapon) - self.Map.add_item_to_map(item) + def add_item(self, item_id): + Item= _items.BrSimItem(item_id) + self.items.append(Item) + self.Map.add_item_to_map(Item) def get_players(self): return self.players - def get_weapons(self): + def get_items(self): res= [] - for w in self.weapons: + for i in self.items: #XXX implement me - res.append(w) + res.append(i) return res def get_map(self): diff --git a/entities/gamemap.py b/entities/gamemap.py index 79679f0..0547975 100644 --- a/entities/gamemap.py +++ b/entities/gamemap.py @@ -6,7 +6,6 @@ from PIL import ImageDraw as _ImageDraw from utils import logs as _logs from bot_libs import syms as _bot_syms from entities import resource as _resource -from utils import logs as _logs class BrSimMap(): @@ -52,20 +51,18 @@ class BrSimMap(): #if i == 0 or i == self.world_height - 1: self.game_map.append(mon) #else: self.game_map.append(_copy.deepcopy(width)) self.game_map.append(_copy.deepcopy(width)) - _logs.log_debug(f'init_map_matrix: {self.game_map}') + #_logs.log_debug(f'init_map_matrix: {self.game_map}') + _logs.log_debug(f'players: %s'% [(p.get_name(), p.get_coordinates()) for p in self.players]) + print('##') + _logs.log_debug(f'items: %s' % [(p.get_name(), p.get_coordinates()) for p in self.items]) def populate_map(self): for player in self.players: p_coord_x, p_coord_y= player.get_coordinates() self.game_map[p_coord_y][p_coord_x]= player - #if not player.is_alive(): self.game_map[p_coord_y][p_coord_x]= self.dead_player_sym - #elif player.player_gender_is_male(): self.game_map[p_coord_y][p_coord_x]= self.player_male_sym - #elif player.player_gender_is_female(): self.game_map[p_coord_y][p_coord_x]= self.player_female_sym - #else: self.game_map[p_coord_y][p_coord_x]= self.player_nonbinary_sym for item in self.items: i_coord_x, i_coord_y= item.get_coordinates() - self.game_map[p_coord_y][p_coord_x]= item - #self.game_map[i_coord_y][i_coord_x]= self.item_sym + self.game_map[i_coord_y][i_coord_x]= item def _put_resource_on_map(self, target): #x= _random.randint(1, self.world_width -2) # from 1 to width-2 because 1 cell is occupied by the mountain diff --git a/entities/items/item.py b/entities/items/item.py index 31f0c47..f191cd4 100644 --- a/entities/items/item.py +++ b/entities/items/item.py @@ -1,27 +1,35 @@ import random as _random from entities import resource as _resource +from entities.items import syms as _isyms class BrSimItem(_resource.BrSimResource): + #XXX i don't know yet if we need to call this clas + # or we need to have subclasses that inherit this one + # for example class Weapon and class Medikit (or something else) + # this decision would change everything from Arena init - # test - def __init__(self): - self.coord_x= 0 - self.coord_y= 0 + def __init__(self, item_id): + self.item= _isyms.ITEMS[item_id] def is_item(self): return True - def get_name(self): - return self.name + def get_data(self): + return self.item - def get_item_type(self): - return self.item_type + def get_name(self): + idata= self.get_data() + return idata['name'] def get_weight(self): - return self.weight + idata= self.get_data() + return idata['weight'] def is_weapon(self): - return False + idata= self.get_data() + return idata['is_weapon'] def is_cure(self): - return False + #XXX not sure about it + # maybe we could have more item type, like foods, drink, poison... + return not self.is_weapon() diff --git a/entities/items/weapon_syms.py b/entities/items/syms.py similarity index 54% rename from entities/items/weapon_syms.py rename to entities/items/syms.py index 789be0d..44dd524 100644 --- a/entities/items/weapon_syms.py +++ b/entities/items/syms.py @@ -1,11 +1,23 @@ -KNIFE= 1 -ARCH= 2 +MEDIKIT= 1 +#FOOD= 2 #XXX not yet implemented, how to manage it? +#DRINK= 3 #XXX not yet implemented, how to manage it? + +KNIFE= 4 +ARCH= 5 SHORT_RANGE= 1 FAR_RANGE= 2 -WEAPONS= { +ITEMS= { + MEDIKIT: { + 'is_weapon': False, + 'weight': 0.5, + 'name': 'medikit', + 'description': 'useful tool to restore health', + 'health': 1, + }, KNIFE: { + 'is_weapon': True, 'weight': 1, 'name': 'knife', 'damage': 3, @@ -14,6 +26,7 @@ WEAPONS= { 'range': SHORT_RANGE, }, ARCH: { + 'is_weapon': True, 'weight': 2, 'name': 'gun', 'damage': 3, @@ -22,3 +35,5 @@ WEAPONS= { 'range': FAR_RANGE, }, } + +ITEMS_LIST= list(ITEMS.keys()) diff --git a/entities/items/weapons.py b/entities/items/weapons.py index 1e82a72..705beaa 100644 --- a/entities/items/weapons.py +++ b/entities/items/weapons.py @@ -5,7 +5,7 @@ from entities.items import weapon_syms as _syms class BrSimWeapon(_item.BrSimItem): def __init__(self, wtype= None): - self.weapon= _syms.WEAPONS[wtype or _random.randint(1,2)] + self.weapon= _syms.WEAPONS.get(wtype) or _syms.WEAPONS.get(_random.choice(list(_syms.WEAPONS.keys()))) self.name= self.weapon['name'] self.damage= self.weapon['damage'] self.weight= self.weapon['weight'] diff --git a/main.py b/main.py index aa6e50a..c2d47ef 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,7 @@ from entities import arena as _arena -def init_arena(players= None, weapons= None): - return _arena.BrSimArena(players, weapons) +def init_arena(players= None, items= None): + return _arena.BrSimArena(players, items) def run_events(Arena): #A event for each player: