def cmp_objects(a, b, max_rows): ((ai, aj, ar, ac, _), _, _) = a ((bi, bj, br, bc, _), _, _) = b if Rect((ai, aj, ar, ac)).contains(bi, bj, br, bc): return -1 elif Rect(bi, bj, br, bc).contains(ai, aj, ar, ac): return 1 else: return rule(ai + ar, aj, max_rows) - rule(bi + br, bj, max_rows)
def compile(self, rules): for r in rules: r.pattern = normalize(r.pattern) r.pattern.set_context(self) name = r.pattern.compile(r.symbol) if name != r.symbol: self.rules[r.symbol].append(rule(r.symbol, [name], identity))
def __init__(self, tokens, rules): self.symbols = defaultdict(set) self.edges = defaultdict(set) self.rules = defaultdict(list) self.rules["_empty_"].append(rule("_empty_", [])) for r in rules: self.rules[r.symbol].append(r) self.predict(0, "start")
from rules import rule rule("if\s+(?!\(){{anything:condition}}\s*{", "if ({condition}) {") rule("(?<![;\{\}\n])\n", ";\n")
#Import class from file #TODO: Refactor this, looks messy from GamePlan import GamePlan import rules import Player import cards #Instatiations gameplan = GamePlan() ruleDeck = cards.Deck() #Adding rules-------------------------- #Architect's job! higherRule = rules.rule() higherRule.effect = "Higher" higherRule.usesCards = ruleDeck.getAll()[0:28] gameplan.ruleList.append(higherRule) lowerRule = rules.rule() lowerRule.effect = "Lower" lowerRule.usesCards = ruleDeck.getAll()[28:52] gameplan.ruleList.append(lowerRule) anyRule = rules.rule() anyRule.effect="Play_Any" anyRule.usesCards = ruleDeck.getAll() gameplan.ruleList.append(anyRule) #--------------------------------------
def partition(elem): if not elem.tag in part1: return rules.rule(elem.text) else: return elem.text