示例#1
0
文件: show.py 项目: mk12/zeldalloy
#!/usr/bin/env python3

import os, pathlib, sys

sys.path.append(os.path.relpath(pathlib.Path(__file__).resolve().parent.parent))

from common import CoordPuzzle, default_main


class SnowpeakBlocks(CoordPuzzle):

    x_range = -2, 2
    y_range = -3, 2

    object_to_coord = "pos"
    static_to_coord = "Obstacle<:pos"

    def object_char(self, obj):
        if obj[0] == "Block":
            return obj[1]
        if obj[0] == "Obstacle":
            return "o"


if __name__ == "__main__":
    default_main(SnowpeakBlocks)
示例#2
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))
示例#3
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))
示例#4
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))
示例#5
0
#!/usr/bin/env python3

import os, pathlib, sys

sys.path.append(os.path.relpath(
    pathlib.Path(__file__).resolve().parent.parent))

from common import CoordPuzzle, default_main


class MutohTiles(CoordPuzzle):

    x_range = -1, 1
    y_range = -1, 1

    coord_to_object = "colors"

    def object_char(self, obj):
        if obj == ("Red", 0):
            return "O"
        if obj == ("Blue", 0):
            return "X"


if __name__ == "__main__":
    default_main(MutohTiles)
示例#6
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))
示例#7
0

class CrownStatues(CoordPuzzle):

    x_range = -5, 4
    y_range = -3, 2

    fake = {(0, 0): "OWL"}

    state_to_coord = "block"
    state_to_coord_atom = "BLOCK"
    object_to_coord = "pos"

    def setup(self):
        super().setup()
        self.colors = self.instance["this/Statue<:color"]

    def object_char(self, obj):
        if obj == "OWL":
            return "x"
        if obj == "BLOCK":
            return "o"
        if obj[0] == "Statue":
            # First [0] to get name from atom.
            # Second [0] to get the first letter of the color.
            return the(self.colors[obj])[0][0]


if __name__ == "__main__":
    default_main(CrownStatues)
示例#8
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))
示例#9
0
文件: show.py 项目: mk12/zeldalloy
#!/usr/bin/env python3

import os, pathlib, sys

sys.path.append(os.path.relpath(
    pathlib.Path(__file__).resolve().parent.parent))

from common import CoordPuzzle, default_main


class SacredGrove(CoordPuzzle):

    x_range = -2, 2
    y_range = -3, 2

    object_to_coord = "pos"

    def object_char(self, obj):
        if obj == ("Link", 0):
            return "L"
        if obj == ("StatueA", 0):
            return "A"
        if obj == ("StatueB", 0):
            return "B"


if __name__ == "__main__":
    default_main(SacredGrove)