-
Notifications
You must be signed in to change notification settings - Fork 0
/
kara.py
43 lines (38 loc) · 1.61 KB
/
kara.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import js as __js
import pyodide as __py
class KaraError(BaseException): pass
class MovedTowardsStone(KaraError): pass
class NoWormThere(KaraError): pass
class WormAlreadyPlaced(KaraError): pass
class MovedMultipleBalls(KaraError): pass
__errors = {
"towardsstone": MovedTowardsStone("Can't move! There is a tree in the way!"),
"noworm": NoWormThere("No leaf to remove"),
"aworm": WormAlreadyPlaced("There is already a leaf"),
"multipleballs": MovedMultipleBalls("Can't move multiple mushrooms at the same time!")
}
def __jsfunc(func):
def __wrapper():
error = None
try:
result = func()
except __py.ffi.JsException as e:
try:
error = __errors[str(e).removeprefix("Error: ")]
except KeyError as a:
raise KaraError("This Error is not meant to be thrown! Please report it (the entire message) on GitHub! (Go to Welcome Guide and click the desired link)") from e
if error is not None:
raise error
__js.saveState()
return result
return __wrapper;
move = __jsfunc(__js.window.coati.move)
turnLeft = __jsfunc(__js.window.coati.turnLeft)
turnRight = __jsfunc(__js.window.coati.turnRight)
putLeaf = __jsfunc(__js.window.coati.putWorm)
removeLeaf = __jsfunc(__js.window.coati.removeWorm)
onLeaf = __jsfunc(__js.window.coati.onWorm)
mushroomFront = __jsfunc(__js.window.coati.ballFront)
treeFront = __jsfunc(__js.window.coati.stoneFront)
treeLeft = __jsfunc(__js.window.coati.stoneLeft)
treeRight = __jsfunc(__js.window.coati.stoneRight)