so lets say I wanted to get the values for all of the places on my side of the board, with firewalls on them
There are lots of different options (and more than I’m going to post). I’ll explain two.
The simplest would be to simply loop through the bottom half of the map and check if that location has a firewall. You could then return the points found. So this would be the function you would add to the GameMap class.
def get_all_firewall_locations(self): locations =  for x in range(self.ARENA_SIZE): for y in range(self.HALF_ARENA): if len(self.__map[x][y]) > 0: if self.__map[x][y].stationary: locations.append([x,y]) return locations
This is a very basic and unoptimized method, but the loops are relatively small (28 and 14) and it’s pretty clear what is happening.
Another method would be to keep track of all units when they are created, and then just call that list when required. For example, in my GameState class I some function you can see I have are:
def getEnemyUnits(self): return self.enemyUnits def getFriendlyUnits(self): return self.friendlyUnits
self.friendlyUnits are lists that I populate when the game_state is initialized. You could do the same, but again look at the
.stationary data to see if it is a firewall or a moving unit.
Can you explain the last method a bit more?
So how would I say,
for location in firewall_locations: check each location if it has a firewall then return the list of firewalls that have a firewall in them and put them in a var then the next time this is called, add to the list, not replace it
therefore if a unit has been removed, the variable will still be there
Nice observation, forgot to mention that. Very true, if the unit has been removed it will remain in your list for the second method. However, it will only stay in your list for that turn, since it is part of the game_state, which is overwritten every turn. I’ll cover 2 ways to handle dealing with removing the units within the same turn (during an action phase). This is applicable if you want to say, see what happens IF a firewall was removed/destroyed.
The first way is that you could loop through every unit in your list every turn and check that map location to see if it is still there. If it is not, remove it (this will not work for moving units since they still exist but in a different location). You can do this by creating a function that will be run every single action phase (look inside the AlsoCore class to see how the
on_turn function is called and then where the action phase happens). Then you would have this function in the GameState class:
def check_and_remove_firewalls(self): for unit in self.firewalls: # use whatever list you used to store the firewalls if len(self.game_map[unit.x, unit.y]) == 0: self.attempt_remove([unit.x, unit.y])
The key thing to note is that you must already have a list of firewalls. I would recommend adding to this list inside the
The second way does not involve checking multiple squares and will work for mobile units. However, you need to check the information given by the game engine. I won’t go into great detail, but you would get from the engine all units that have moved, been destroyed, removed, etc and update the list from that information. This is a little more complicated because it requires getting information from the engine. This is only necessary if you are checking information from each action phase. You can reference this awesome post:
Regarding the code you posted above,
firewall_locations could then become
game_state.get_all_firewall_locations() (using the first method from the first post). You can then check to make sure it is valid with
if len(self.game_map[unit.x, unit.y]) == 1 (we don’t want more than 1 either because then it is a mobile unit).
So your pseudo code becomes:
valid_firewalls =  for location in firewall_locations: if len(game_map[location]) == 1: valid_firewalls.append(location)
valid_firewalls is a list of firewall locations that never gets removed (this function cannot be in the GameState class, since it’s data gets overwritten every turn).
late reply, but
self.friendlyUnits gives an error saying they don’t exist, am I doing something wrong? Could you explain what I am supposed to do before writing that?