Exemplo n.º 1
0
    def visit_Number(self, tree: ms.Number):
        return True

    def visit_Assign(self, tree: ms.Assign):
        self.visit(tree.target)
        self.visit(tree.value)
        return True

    def generic_visit(self, tree):
        if isinstance(tree, list):
            ok = True
            for t in tree:
                ok |= self.visit(t)
            return ok
        else:
            raise self.error(tree)


class Level2Monitor(ms.ArithmeticOpRule, ms.BaseMonitor):
    pass


if __name__ == '__main__':
    default_main(
        Challenge(name='very basic challenge',
                  challenge=[('h', 'l', lambda: ms.TNumber(
                      random.randrange(1000000000), label={'high'}))],
                  monitor=Level2Monitor,
                  restrictions=AstRestrictor().visit))
Exemplo n.º 2
0
#!/usr/bin/env python
import context
import miniscript as ms
import random
from common import Challenge, default_main


class NoIfNodeVisitor(ms.NodeVisitor):
    def visit_If(self, tree: ms.If):
        raise ms.IllegalStateError('If statements not allowed')


class Level4Monitor(ms.ArithmeticOpRule, ms.UnaryOperatorRule, ms.LiteralRule,
                    ms.AssignRule, ms.BaseMonitor):
    pass


if __name__ == '__main__':
    default_main(
        Challenge(name='extract boolean without using if',
                  challenge=[('h', 'l', lambda: ms.TBoolean(random.choice(
                      (True, False)),
                                                            label={'high'}))],
                  monitor=Level4Monitor,
                  restrictions=NoIfNodeVisitor().visit,
                  nruns=8))
Exemplo n.º 3
0
#!/usr/bin/env python
import context
import miniscript as ms
import random
from common import Challenge, default_main


class Level3Monitor(ms.ArithmeticOpRule, ms.UnaryOperatorRule, ms.BaseMonitor):
    pass


if __name__ == '__main__':
    default_main(
        Challenge(name='extract boolean',
                  challenge=[('h', 'l', lambda: ms.TBoolean(random.choice(
                      (True, False)),
                                                            label={'high'}))],
                  monitor=Level3Monitor,
                  nruns=8))
Exemplo n.º 4
0
#!/usr/bin/env python
import context
import miniscript as ms
import random
import copy
from common import Challenge, default_main


class Level4Monitor(ms.ArithmeticOpRule, ms.UnaryOperatorRule, ms.LiteralRule,
                    ms.AssignRule, ms.BaseMonitor):
    pass


def setup(s: ms.Scope):
    g = ms.GlobalScope()
    s['print'] = g['print']


if __name__ == '__main__':
    default_main(
        Challenge(name='extract boolean without using if',
                  challenge=[('h', 'l', lambda: ms.TNumber(
                      random.randint(1, 1000000007), label={'high'}))],
                  monitor=Level4Monitor(),
                  setup=setup,
                  nruns=8))
Exemplo n.º 5
0
#!/usr/bin/env python
import context
import miniscript as ms
import random
from common import Challenge, default_main


def setup(s: ms.Scope):
    g = ms.GlobalScope()
    s['print'] = g['print']
    s['labelPrint'] = g['labelPrint']


#, ms.ReturnRule
class ChallengeMonitor(ms.BlockLoopReturnRule, ms.LiteralRule,
                       ms.ArithmeticOpRule, ms.UnaryOperatorRule,
                       ms.AssignRule, ms.BaseMonitor):
    pass


if __name__ == '__main__':
    default_main(
        Challenge(name='final challenge',
                  challenge=[('h', 'l', lambda: ms.TBoolean(
                      random.randint(1, 1000000007), label={'high'}))],
                  monitor=ChallengeMonitor,
                  setup=setup))