def test_equal(self): path = os.path.dirname(__file__) + "/test.xml" path2 = os.path.dirname(__file__) + "/write_test.xml" env1 = udebs.battleStart(path) udebs.battleWrite(env1, path2, True) env2 = udebs.battleStart(path2) assert env1 == env2 udebs.battleWrite(env1, path2) env2 = udebs.battleStart(path2) assert env1 == env2 os.remove(path2)
def batches(boats, dmaps, death, iterations=1000): game = udebs.battleStart("xml/pushluck.xml", script=None) deck = { "boat": 27 - boats, "dmap": 9 - dmaps, "skull": 9 - death, "chest": 0, "key": 0, "map": 0, } for key, value in deck.items(): game.callSingle("{} amount REPLACE {}".format(key, value)) scores = collections.Counter() for i in range(iterations): game.castAction("deck", "shuffle") game.castMove("hand", "deck", "draw") skulls = game.getStat("hand", "skulls") if skulls > 3: skulls = 3 scores[skulls] +=1 return (boats, dmaps, death), scores
<i>EXIT</i> </effect> </gameover> <!-- Players --> <user> <lives>5</lives> </user> <computer> <lives>5</lives> </computer> </entities> </udebs> """ if __name__ == "__main__": udebs.randomPlayer("CHOICE_C", "tick", "options") udebs.humanPlayer("CHOICE_H", "tick", "options") udebs.lookup("LOOKUP", { "rock": {"paper": -1}, "paper": {"scissors": -1}, "scissors": {"rock": -1}, }) game = udebs.battleStart(xml) for i in game.gameLoop(): pass
main_map.controlTime() return main_map def printBad(main_map, expected, result): main_map.printMap() print(pos) print("result", result, "expected", expected) print("xPlayer", main_map.getStat("xPlayer", "ACT")) if __name__ == "__main__": with udebs.Timer(): modified = modifyconfig(udebs_config.config, 7, 6) main_map = udebs.battleStart(modified, field=module.Connect4()) widgets = [ "(", progressbar.SimpleProgress(), ") ", progressbar.Bar(), " ", progressbar.Timer(), " ", progressbar.AdaptiveETA(), ] for test_file in tests: module.storage = OrderedDict() module.counter = 0
"battle": {"f": "subBattle", "args": ["$1"]}, "activate": {"f": "setChar", "args": ["$1"]}, } glob = { "message": message, "playSound": playSound, "updateOverWorld": updateOverWorld, "eventQuit": eventQuit, "getItem": getItem, "subBattle": subBattle, "updateRPG": updateRPG, "setChar": setChar, "battleFinish": battleFinish, } udebs.importModule(local, glob) main_map = udebs.battleStart("xml/zanar2.xml") battle = udebs.battleStart("xml/rpg.xml") main_map.controlInit("init") def main(): # game loop while True: for event in pygame.event.get(): if event.type == QUIT: eventQuit() elif event.type == MOUSEBUTTONDOWN: mouse = pygame.mouse.get_pos() for x in range(8):
def setup(self): path = os.path.dirname(__file__) self.test = udebs.battleStart(path + "/test.xml") self.test.controlTravel("unit1", (0,0)) self.test.controlTravel("unit2", (4,3)) self.test.controlTravel("immune", (2,2))
def setup(self): path = os.path.dirname(__file__) self.test = udebs.battleStart(path + "/test.xml") self.one = self.test.map["one"] self.two = self.test.map["two"] self.map = self.test.map['map']
def setUp(self): self.env1 = udebs.battleStart(xml_test) udebs.battleWrite(self.env1, "/tmp/udebs_testing.xml", True) self.env2 = udebs.battleStart("/tmp/udebs_testing.xml")
"args": ["$1"], } } glob = { "message": message, "playSound": playSound, "updateOverWorld": updateOverWorld, "eventQuit": eventQuit, "getItem": getItem, "subBattle": subBattle, "updateRPG": updateRPG, "setChar": setChar, "battleFinish": battleFinish, } udebs.importModule(local, glob) main_map = udebs.battleStart("xml/zanar2.xml", script=False) battle = udebs.battleStart("xml/rpg.xml", script=False) main_map.controlInit("init") def main(): #game loop while True: for event in pygame.event.get(): if event.type == QUIT: eventQuit() elif event.type == MOUSEBUTTONDOWN: mouse = pygame.mouse.get_pos() for x in range(8): for y in range(8): if pygame.Rect(49*x, 49*y, 49, 49).collidepoint(mouse):
for unit in instance.getGroup(color): if "captured" not in instance.getStat(unit, "status"): for move in instance.getStat(unit, 'movelist'): if move not in {"pawn_travel", "pawn_double", "king_kcastle", "king_qcastle"}: if instance.testMove(unit, king, move): return False return True module = {"check": { "f": "check", "args": ["$1", "$2", "self"], }} udebs.importModule(module, {"check": check}) main_map = udebs.battleStart("xml/chess.xml") main_map.controlInit('init') main_map.resetState() #globals BLACK = (0,0,0) GREEN = (100,200,100, 127) RED = (200, 0, 0, 127) high = set() activeUnit = False moves = {} def redrawBoard(): surface.fill(BLACK) for x in range(10): for y in range(10):
return self.negamax(alpha, beta) @udebs.countrecursion @cache def negamax(self, alpha, beta): current = -float("inf") for child, e in self.substates(): if child is e: result = -child else: result = -child.negamax(-beta, -alpha) if result > current: current = result if result > alpha: alpha = result if alpha >= beta: break return current if __name__ == "__main__": main_map = udebs.battleStart(udebs_config.config, field=Connect4()) main_map.printMap() with udebs.Timer(): result = main_map.result() print(result)
#definitions ts = 20 BLACK = (0, 0, 0) GREEN = (0, 255, 0) WHITE = (255, 255, 255) RED = (255, 0, 0) #Setup pygame pygame.init() mainFont = pygame.font.SysFont(None, 48) mainClock = pygame.time.Clock() mainSurface = pygame.display.set_mode((500, 400), 0, 32) pygame.display.set_caption('A simple hex GUI') #Setup udebs main_map = udebs.battleStart("xml/hex.xml") main_map.controlInit('init') class hexagon: def __init__(self, a, b, ts): rad = math.cos(math.pi / 6) self.center = (ts*(2*a+b+1.5), ts*(1.5*b/rad+1.5)) self.points = [] length = ts / rad for i in range(6): angle = i * math.pi / 3 x = self.center[0] + length*math.sin(angle) y = self.center[1] + length*math.cos(angle) self.points.append((x, y))
def setUp(self): self.test1 = udebs.battleStart(xml_test)
def setUp(self): self.env = udebs.battleStart(xml_test) self.unit = self.env.data["unit1"]
def setUp(self): self.test1 = udebs.battleStart(xml_test) self.one = self.test1.map["one"] self.two = self.test1.map["two"]
def setup(self): path = os.path.dirname(__file__) self.test = udebs.battleStart(path + "/test.xml")
pygame.display.update() def dedup(lst): return list(set(lst)) if __name__ == "__main__": # Setup Udebs module = {"dedup": { "f": "dedup", "args": ["$1"], }} udebs.importModule(module, {"dedup": dedup}) # State variables ts = 10 field = udebs.battleStart("xml/life.xml") #Setup pygame pygame.init() pygame.display.set_caption("Conway's game of life.") surface = pygame.display.set_mode((ts*field.getMap().x, ts*field.getMap().y), 0, 32) mainClock = pygame.time.Clock() # #game loop for main_map in field.gameLoop(1): redrawBoard(surface, ts) mainClock.tick(60) for event in pygame.event.get(): if event.type == QUIT: pygame.quit()
}, { "f": udebs.constantPlayer, "kwargs": {"constant": "cheat"}, "name": "always cheat", "score": 0, }, { "f": udebs.randomPlayer, "kwargs": {}, "name": "random", "score": 0, }, { "f": udebs.grudgerPlayer, "kwargs": {"default": "cooperate", "trigger": "cheat"}, "name": "grudger", "score": 0, }] for x, y in itertools.combinations_with_replacement(players, 2): x["f"]("CHOICE_C", options, **x["kwargs"]) y["f"]("CHOICE_H", options, **y["kwargs"]) game = udebs.battleStart("xml/trust.xml") for i in game.gameLoop(): pass x["score"] += game.getStat("computer", "score") y["score"] += game.getStat("human", "score") for i in players: print(i["name"], i["score"])