I have a World class which stands as the root of a game simulation. All other classes are instantiated either directly from World's methods or from objects instantiated within World. I want to generate a list of specific objects and scalars for later use.
During runtime, I have another class Inspector which will run a single time, once the game world is initialized. Inspector's job is to find all marked objects or scalars and return a list of references to them for later value extraction. The need for this job is born out of the necessity of feeding various game states as input into the AI's neural net. The AI does not care what they are named, so long as they return in the same order on each run.
For instance, World has a Table, and on this Table is a Deck of cards. I'd like to be able to mark this Deck to be picked up by the Inspector.
Additionally, I'd like for the suit (str) and rank (int) of each Card in the deck to also be picked up by the Inspector. The AI does not care about the Deck; it cares about the individual suit/rank of each card.
Current python code goes something like this:
class Inspector:
@staticmethod
def inspect(obj):
found = []
# search through each class member
for entity in vars(obj):
if is_marked(entity):
# the neural net only cares about ints/chars
if isinstance(entity, int) or isinstance(entity, str):
found.append(entity)
else:
# let's explore deeper
found.append(inspect(entity))
return found
@staticmethod
def is_marked(entity):
if ???:
return true
else:
return false
I imagine using this code to run the game and build the list of marked objects:
def main():
world = World()
ai = AI()
world.init()
marked = Inspector(world).inspect()
ai.init(marked)
simulate(world, ai)
I'm tripping up a bit on the inner workings of is_marked(). How can an object or scalar be marked for later inspection?
Aucun commentaire:
Enregistrer un commentaire