Permalink
Browse files

Implement a basic Evaluator system for actions.Find()

  • Loading branch information...
jleclanche committed Jul 13, 2015
1 parent 4c1467c commit 27ef2cca62c6742ab99baa9db758b6d1a11c1523
Showing with 35 additions and 0 deletions.
  1. +35 −0 fireplace/actions.py
@@ -24,6 +24,41 @@ def pick(self) -> str:
return random.choice(self.cards)
class Evaluator:
"""
Lazily evaluate a condition at runtime.
"""
def __init__(self):
self._if = None
def __and__(self, action):
self._if = action
return self
def get_actions(self, source, game):
ret = self.evaluate(source, game)
if ret:
if self._if:
return [self._if]
return []
def trigger(self, source, game):
for action in self.get_actions(source, game):
action.trigger(source, game)
class Find(Evaluator):
"""
Evaluates to True if \a selector has a match.
"""
def __init__(self, selector):
super().__init__()
self.selector = selector
def evaluate(self, source, game):
return bool(self.selector.eval(game, source))
class Copy(object):
"""
Lazily return a list of copies of the target

0 comments on commit 27ef2cc

Please sign in to comment.