import Menu import BoardSetup import BoardScreen import sys sys.path.append('../model') from Predicate import * from SpeciesDatabase import * from LocalWorld import LocalWorld def simpleRules(spec, directions): """Purpose: Build a set of simple rules of the form "If I have i neighbors, add a neighbor in direction i." Preconditions: len(direction) is 8. """ from Instruction import Instruction from Rule import Rule import Direction for i in range(0,8): spec.addRule(Rule(LiveNeighbors(i, int.__eq__), [Instruction(directions[i], spec)]), i) def roshambo(): """SamR's test. Intended to play with counting of live neighbors, and other such fun.""" #from LocalWorld import LocalWorld from Instruction import Instruction import Direction from Species import Species from Rule import Rule #make species Dead = Species("Dead", "grey") Ro = Species("Ro", "purple") Sham = Species("Sham", "red") Bo = Species("Bo", "blue") Foo = Species("Foo", "yellow") Bar = Species("Bar", "orange") Baz = Species("Baz", "green") simpleRules(Ro, [Direction.NE, Direction.SE, Direction.SW, Direction.NW, Direction.N, Direction.E, Direction.S, Direction.W]) Ro.addRule(Rule(TruePredicate(), [Instruction(Direction.C, Dead), Instruction(Direction.SE, Ro), Instruction(Direction.SW, Ro)]), 8) simpleRules(Sham, [Direction.S, Direction.SE, Direction.E, Direction.NE, Direction.N, Direction.NW, Direction.W, Direction.SW]) Sham.addRule(Rule(TruePredicate(), [Instruction(Direction.C, Dead), Instruction(Direction.E, Sham), Instruction(Direction.N, Sham)]), 8) simpleRules(Bo, [Direction.N, Direction.SE, Direction.W, Direction.NE, Direction.S, Direction.NW, Direction.E, Direction.SW]) Bo.addRule(Rule(TruePredicate(), [Instruction(Direction.C, Dead), Instruction(Direction.W, Bo), Instruction(Direction.SW, Bo)]), 8) directions = [Direction.N, Direction.SE, Direction.W, Direction.NE, Direction.S, Direction.NW, Direction.E, Direction.SW] simpleRules(Foo, directions) Foo.addRule(Rule(TruePredicate(), [Instruction(Direction.C, Dead), Instruction(Direction.N, Foo)])) simpleRules(Bar, directions[1:] + directions[:1]) Bar.addRule(Rule(TruePredicate(), [Instruction(Direction.C, Dead), Instruction(Direction.SE, Bar)])) simpleRules(Baz, directions[2:] + directions[:2]) Bar.addRule(Rule(TruePredicate(), [Instruction(Direction.C, Dead), Instruction(Direction.W, Baz)])) # Add species sd = SpeciesDatabase.getInstance() sd.addSpecies(Dead) sd.addSpecies(Ro, defaultStrength = 1, weakerList = [Sham]) sd.addSpecies(Sham, defaultStrength = 1, weakerList = [Bo]) sd.addSpecies(Bo, defaultStrength = 1, weakerList = [Ro]) # sd.addSpecies(Foo, defaultStrength = 1, weakerList = [Bar]) # sd.addSpecies(Bar, defaultStrength = 1, weakerList = [Baz]) # sd.addSpecies(Baz, defaultStrength = 1, weakerList = [Foo]) # And go! Menu.run() if __name__ == "__main__": roshambo()