wolfsheep: small refactor

This commit is contained in:
madmaurice 2016-02-18 14:37:59 +01:00
parent 828a841606
commit a5220fb56c
1 changed files with 3 additions and 2 deletions

View File

@ -18,10 +18,11 @@ class Model:
class Simulator:
invalid_states = [ set({Model.Wolf,Model.Sheep}), set({Model.Sheep, Model.Cabbage}) ]
all_entities = set([Model.Man, Model.Wolf, Model.Sheep, Model.Cabbage])
def simulate(self, state, stack=[]):
stack = stack + [state]
if state.right == set([Model.Man,Model.Wolf,Model.Sheep,Model.Cabbage]):
if state.right == Simulator.all_entities:
return stack
nextStates = []
@ -49,7 +50,7 @@ class Simulator:
if __name__ == "__main__":
sim = Simulator()
result = sim.simulate(Model([Model.Man, Model.Wolf, Model.Sheep, Model.Cabbage],[]))
result = sim.simulate(Model(Simulator.all_entities,[]))
i = 0
for state in result:
print("%d: %s" % (i,state.pretty()))