Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions EscapeRoom.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ def set_metadata(self, author, room_name):
def get_metadata(self):
return {"author": self.author, "room_name": self.room_name, "levels": len(self.levels)}

def check_solution(self, solution_filename, correct_function, data):
def check_solution(self, solution_filename, correct_function, data, algorithm):
solution = self.run_code(solution_filename, data)
correct = solution == correct_function(data)
try:
correct = algorithm(solution)
except:
result_error = 1
if 'result_error' in locals() and result_error == 1:
correct = solution == correct_function(data)
return {"correct": correct, "solution": solution}

def run_code(self, filename, data):
Expand Down
2 changes: 1 addition & 1 deletion EscapeRoomWeb.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def post_solve_level(room_nr, level_nr):
string.ascii_lowercase + string.digits, k=7))
file.save(filename+".py")
solution = room.check_solution(
filename, level["solution_function"], level["data"])
filename, level["solution_function"], level["data"], level.get("algorithm", None))
os.remove(filename+".py")
return jsonify(solution)

Expand Down
6 changes: 6 additions & 0 deletions rooms/ExampleRoom.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def create_level1(self):
"Werfen Sie einen Blick auf die Anfangsbuchstaben!"
]
return {"task_messages": task_messages, "hints": hints, "solution_function": self.first_letters, "data": secret}
# if using an algorithm to check the correctness of an answer use:
# return {"task_messages": task_messages, "hints": hints, "solution_function": self.first_letters, "data": secret, "algorithm": self.algorithm}

### SOLUTIONS ###

Expand All @@ -34,3 +36,7 @@ def first_letters(self, secret):
for word in words:
result += word[0]
return result

def algorithm(self, solution_attempt):
# check solution and return True or False
return True