Compare commits
7 Commits
31981b541e
...
c59f7d7e39
Author | SHA1 | Date |
---|---|---|
BodgeMaster | c59f7d7e39 | |
BodgeMaster | ab0912b968 | |
BodgeMaster | ea4e8f0248 | |
BodgeMaster | f8e316bdc4 | |
BodgeMaster | e814cfe21d | |
BodgeMaster | e3475eefc3 | |
BodgeMaster | 9e9fb38b60 |
71
lambdaV.py
71
lambdaV.py
|
@ -514,13 +514,70 @@ def setup_and_run_task(start_field, start_position, start_heading, text, allowed
|
|||
field = start_field
|
||||
draw_field()
|
||||
print("\n"+text)
|
||||
print("\nAllowed commands: "+" ,".join(allowed_commands))
|
||||
print("\nAvailable conditions: "+" ,".join(allowed_conditions))
|
||||
print(evaluate_parser_result(parse_code(input("\nCode: "), allowed_commands, allowed_conditions)))
|
||||
#TODO: return information about success or failure
|
||||
|
||||
def debug_setup():
|
||||
setup_and_run_task(empty_field, [1,1], cursor_east, "Debug mode", ["step", "left", "right", "take", "repeat", "while", "if"], ["facing north", "facing south", "facing east", "facing west", "in front of wall", "goal reached", "on apple"])
|
||||
print("\nAllowed commands: "+", ".join(allowed_commands))
|
||||
if len(allowed_conditions)>0:
|
||||
print("\nAvailable conditions: "+", ".join(allowed_conditions))
|
||||
result = evaluate_parser_result(parse_code(input("\nCode: "), allowed_commands, allowed_conditions))
|
||||
print(result)
|
||||
time.sleep(3)
|
||||
if result=="Success!":
|
||||
return True
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys, os, json
|
||||
|
||||
level = 0
|
||||
single_file_mode = False
|
||||
level_file_name = ""
|
||||
|
||||
def wrong_usage():
|
||||
print("Usage:\n " + sys.argv[0] + " [l<number> | level_file_name.json]\n\n- Run without arguments to start at level 0.\n- Run with a single argument made of 'l' and a number to start at that level.\n- Run with a file name to start that specific level.")
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv)>1:
|
||||
if len(sys.argv)>2:
|
||||
wrong_usage()
|
||||
if sys.argv[1][0]=="l":
|
||||
try:
|
||||
level=int(sys.argv[1][1:])
|
||||
except:
|
||||
if os.path.isfile(sys.argv[1]):
|
||||
level_file_name = sys.argv[1]
|
||||
single_file_mode = True
|
||||
else:
|
||||
wrong_usage()
|
||||
elif os.path.isfile(sys.argv[1]):
|
||||
level_file_name = sys.argv[1]
|
||||
single_file_mode = True
|
||||
else:
|
||||
wrong_usage()
|
||||
|
||||
if not single_file_mode:
|
||||
level_file_name = os.path.join("levels", str(level)+".json")
|
||||
|
||||
while os.path.isfile(level_file_name):
|
||||
level_file = open(level_file_name, "r")
|
||||
level_raw = level_file.read()
|
||||
level_file.close()
|
||||
level_data = json.loads(level_raw)
|
||||
|
||||
cursor_start = ""
|
||||
if level_data["start heading"]=="north":
|
||||
cursor_start = cursor_north
|
||||
elif level_data["start heading"]=="south":
|
||||
cursor_start = cursor_south
|
||||
elif level_data["start heading"]=="east":
|
||||
cursor_start = cursor_east
|
||||
elif level_data["start heading"]=="west":
|
||||
cursor_start = cursor_west
|
||||
else:
|
||||
print("Unknown start heading!")
|
||||
sys.exit(1)
|
||||
while not setup_and_run_task(level_data["field"].copy(), level_data["start position"].copy(), cursor_start, level_data["text"], level_data["allowed commands"].copy(), level_data["allowed conditions"].copy()):
|
||||
pass
|
||||
|
||||
if single_file_mode:
|
||||
break
|
||||
level+=1
|
||||
level_file_name = os.path.join("levels", str(level)+".json")
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"field": [
|
||||
" _________________ ",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| $ |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
" ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ "
|
||||
],
|
||||
"start position": [ 4, 4],
|
||||
"start heading": "east",
|
||||
"text": "→ This should show up as a roughly square box with a cursor and a $ inside it.\n→ The cursor is indicated by one of these: Λ V > <\n'#' represents a wall, 'ó' represents an apple and '$' represents the goal\nthat is to be reached.\n→ With every level, there is a list of available commands and conditions\nwhich can be used in that level.\n→ Step onto the goal to continue.",
|
||||
"allowed commands": [
|
||||
"step"
|
||||
],
|
||||
"allowed conditions": [
|
||||
]
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"field": [
|
||||
" _________________ ",
|
||||
"| |",
|
||||
"| ### |",
|
||||
"| #$# |",
|
||||
"| #### # |",
|
||||
"| # # |",
|
||||
"| ###### |",
|
||||
"| |",
|
||||
"| |",
|
||||
" ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ "
|
||||
],
|
||||
"start position": [ 4, 5],
|
||||
"start heading": "east",
|
||||
"text": "[Level 1]\n\nΛV has three commands to control movement:\n→ The `step` command moves the cursor one step in the direction it is pointing.\n→ The `left` and `right` commands turn the cursor 90° in that direction.",
|
||||
"allowed commands": [
|
||||
"step",
|
||||
"left",
|
||||
"right"
|
||||
],
|
||||
"allowed conditions": [
|
||||
]
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"field": [
|
||||
" _________________ ",
|
||||
"| $ |",
|
||||
"|#################|",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
" ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ "
|
||||
],
|
||||
"start position": [ 1, 1],
|
||||
"start heading": "east",
|
||||
"text": "[Level 2]\n\nThat's quite simple but it can get tedious really quickly.",
|
||||
"allowed commands": [
|
||||
"step",
|
||||
"left",
|
||||
"right"
|
||||
],
|
||||
"allowed conditions": [
|
||||
]
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"field": [
|
||||
" _________________ ",
|
||||
"| $ |",
|
||||
"|#################|",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
" ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ "
|
||||
],
|
||||
"start position": [ 1, 1],
|
||||
"start heading": "east",
|
||||
"text": "[Level 3]\n\nInstead, we can use a loop to repeat things.\n\nΛV has a simplified \"repeat\" loop for demonstration purposes.\nHere is an example of how to use it: repeat<6>(left)",
|
||||
"allowed commands": [
|
||||
"step",
|
||||
"left",
|
||||
"right",
|
||||
"repeat"
|
||||
],
|
||||
"allowed conditions": [
|
||||
]
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"field": [
|
||||
" _________________ ",
|
||||
"| # |",
|
||||
"| # |",
|
||||
"|# # |",
|
||||
"| # # |",
|
||||
"| # # |",
|
||||
"| # # |",
|
||||
"| # # |",
|
||||
"| # $# |",
|
||||
" ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ "
|
||||
],
|
||||
"start position": [ 1, 1],
|
||||
"start heading": "east",
|
||||
"text": "[Level 4]\n\nYou can put multiple commands inside a loop.\nThis can be used to repeat a sequence of commands.\n\nExample: repeat<10>(left step left)",
|
||||
"allowed commands": [
|
||||
"step",
|
||||
"left",
|
||||
"right",
|
||||
"repeat"
|
||||
],
|
||||
"allowed conditions": [
|
||||
]
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"field": [
|
||||
" _________________ ",
|
||||
"| # #$# |",
|
||||
"| # # # |",
|
||||
"| # # # |",
|
||||
"| # # # |",
|
||||
"| # # # |",
|
||||
"| # # # |",
|
||||
"| ###### # |",
|
||||
"| # |",
|
||||
" ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ "
|
||||
],
|
||||
"start position": [ 1, 1],
|
||||
"start heading": "south",
|
||||
"text": "[Level 5]\n\nYou can even put loops inside other loops.\n\nExample: repeat<10>(step repeat<3>(left))",
|
||||
"allowed commands": [
|
||||
"step",
|
||||
"left",
|
||||
"right",
|
||||
"repeat"
|
||||
],
|
||||
"allowed conditions": [
|
||||
]
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"field": [
|
||||
" _________________ ",
|
||||
"| # # # # $|",
|
||||
"| # # # # # # # ##|",
|
||||
"| # # # # # # # # |",
|
||||
"| # # # # # # # # |",
|
||||
"| # # # # # # # # |",
|
||||
"| # # # # # # # # |",
|
||||
"| # # # # # # # # |",
|
||||
"| # # # # |",
|
||||
" ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ "
|
||||
],
|
||||
"start position": [ 1, 1],
|
||||
"start heading": "east",
|
||||
"text": "[Level 6]\n\nLet's do that again but bigger...",
|
||||
"allowed commands": [
|
||||
"step",
|
||||
"left",
|
||||
"right",
|
||||
"repeat"
|
||||
],
|
||||
"allowed conditions": [
|
||||
]
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"field": [
|
||||
" _________________ ",
|
||||
"| $ |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
" ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ "
|
||||
],
|
||||
"start position": [ 6, 8],
|
||||
"start heading": "north",
|
||||
"text": "[Level 7]\n\nNow in the real world, loops usually don't run a predefined number of times.\nOne type of loops found in most programming languages is the \"while loop\".\nIt runs while a given condition is true. Conditions can be negated by adding !\nin front of them.\nExample: while<!I have cookie>(fix_that)",
|
||||
"allowed commands": [
|
||||
"step",
|
||||
"while"
|
||||
],
|
||||
"allowed conditions": [
|
||||
"in front of wall"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"field": [
|
||||
" _________________ ",
|
||||
"| # |",
|
||||
"| # ############# |",
|
||||
"| # # # |",
|
||||
"| # #$ # # |",
|
||||
"| # ########### # |",
|
||||
"| # # |",
|
||||
"| ############### |",
|
||||
"| |",
|
||||
" ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ "
|
||||
],
|
||||
"start position": [ 1, 1],
|
||||
"start heading": "south",
|
||||
"text": "Let's do the same thing but more complex...",
|
||||
"allowed commands": [
|
||||
"step",
|
||||
"left",
|
||||
"right",
|
||||
"while"
|
||||
],
|
||||
"allowed conditions": [
|
||||
"in front of wall",
|
||||
"goal reached"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"field": [
|
||||
" _________________ ",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
" ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ "
|
||||
],
|
||||
"start position": [ 1, 1],
|
||||
"start heading": "east",
|
||||
"text": "TODO: Tell the player that loops will only check their condition at the start of the loop",
|
||||
"allowed commands": [
|
||||
"step",
|
||||
"left",
|
||||
"right",
|
||||
"take",
|
||||
"repeat",
|
||||
"while",
|
||||
"if"
|
||||
],
|
||||
"allowed conditions": [
|
||||
"facing north",
|
||||
"facing south",
|
||||
"facing east",
|
||||
"facing west",
|
||||
"in front of wall",
|
||||
"goal reached",
|
||||
"on apple"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"field": [
|
||||
" _________________ ",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| $|",
|
||||
" ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ "
|
||||
],
|
||||
"start position": [ 1, 1],
|
||||
"start heading": "east",
|
||||
"text": "Debug mode",
|
||||
"allowed commands": [
|
||||
"step",
|
||||
"left",
|
||||
"right",
|
||||
"take",
|
||||
"repeat",
|
||||
"while",
|
||||
"if"
|
||||
],
|
||||
"allowed conditions": [
|
||||
"facing north",
|
||||
"facing south",
|
||||
"facing east",
|
||||
"facing west",
|
||||
"in front of wall",
|
||||
"goal reached",
|
||||
"on apple"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"field": [
|
||||
" _________________ ",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
" ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ "
|
||||
],
|
||||
"start position": [ 1, 1],
|
||||
"start heading": "east",
|
||||
"text": "",
|
||||
"allowed commands": [
|
||||
"step",
|
||||
"left",
|
||||
"right",
|
||||
"take",
|
||||
"repeat",
|
||||
"while",
|
||||
"if"
|
||||
],
|
||||
"allowed conditions": [
|
||||
"facing north",
|
||||
"facing south",
|
||||
"facing east",
|
||||
"facing west",
|
||||
"in front of wall",
|
||||
"goal reached",
|
||||
"on apple"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue