Skip to content

Instantly share code, notes, and snippets.

@quat1024
Created July 23, 2023 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quat1024/93575ee53de30df6bd2a5803c6e59d4c to your computer and use it in GitHub Desktop.
Save quat1024/93575ee53de30df6bd2a5803c6e59d4c to your computer and use it in GitHub Desktop.
backtracking maze algorithm (PuzzleScript Script)
Play this game by pasting the script in http://www.puzzlescript.net/editor.html
title backtracking maze algorithm
author quat
again_interval 0.01
key_repeat_interval 0.08
run_rules_on_level_start
color_palette proteus_mellow
background_color darkred
========
OBJECTS
========
Background #
transparent
Player p
red
..0..
.000.
00000
.000.
.0.0.
Wall .
black
Head h
red
Trail
purple
Maze
white
Token
transparent
Once
transparent
=======
LEGEND
=======
x = Wall and Token
=======
SOUNDS
=======
endlevel 51180303
================
COLLISIONLAYERS
================
Background
Token
Once
Head Trail Maze
Wall Player
======
RULES
======
( Once is used to create a Markov algorithm. Only the first applicable rule runs. )
( Token is simply somewhere to put the Once )
[Token Once] -> [Token]
( explore a new passage and tentatively add it to the maze )
random [Token no Once] [Head | Wall | Wall] -> [Token Once] [Trail | Trail | Head] again
( if we reached a dead end: back up and commit what we have )
[Token no Once] [Head | Trail | Trail] -> [Token Once] [Maze | Maze | Head] again
( if we backtracked all the way to the beginning, we are done; drop a player in the maze )
[Token no Once] [Head] -> [] [Player Maze]
[action Player] -> [] (win)
==============
WINCONDITIONS
==============
no Player
no Token
=======
LEVELS
=======
message Press X to go to the next maze
x..............
...............
...............
...............
...............
...............
...............
.......h.......
...............
...............
...............
...............
...............
...............
...............
x..........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
.............h.............
...........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
x..........................
.h.........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
x..........................
.h.........................
...........................
...........................
...........................
...........................
...........................
...........................
...........................
############...............
...........#...............
...........#...............
...........#...............
...#####...#...............
...#.......#...............
...#.......#...............
...#.......#...............
...#########...............
...........#...............
...........#...............
...........................
...........................
...........................
...........#...............
...........#...............
...........#...............
...........#...............
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment