Maze Game

Maze Game preview image

1 collaborator

Cover Benjamin Menashe (Author)

Tags

game 

Tagged by Benjamin Menashe almost 6 years ago

games 

Tagged by Benjamin Menashe almost 6 years ago

labyrinth 

Tagged by Benjamin Menashe almost 6 years ago

maze 

Tagged by Benjamin Menashe almost 6 years ago

mazes 

Tagged by Benjamin Menashe almost 6 years ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 6.1.1 • Viewed 731 times • Downloaded 62 times • Run 0 times
Download the 'Maze Game' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

A maze-solving game!

_The goal is to get from thr right red patch to the left one by only stepping on the black space._

(This is a fun demonstration of the BAM maze generating algorithm. See "Maze Generator 1" model for more explanation on the algorithm)

HOW IT WORKS

This model lets the user generate a maze and then navigate a turtle to solve it!

  1. Generate a maze to your liking.
  2. Try to solve it.

HOW TO GENERATE THE MAZE

Press "Setup" to start. Press "Go Forever" to generate the maze. Press again once you think the maze is done to your liking. Press "Play" to start solving.

If you like it, press "Export Maze" to save it as a .png file.

You can use the sliders to change the vertical position of the red patches (Start and Finish). You can also change the difficulty level (Easy, Medium, or Hard).

HOW TO SOLVE THE MAZE

Press "Play" to srart at the right red patch. Move the green turtle using the arrows buttons or keyboard keys. Try to reach the end left red patch!

If at any moment you wish to restart, presss "Restart".

DIFFICULTY LEVELS

The difficulty levels are only an estimate. The difference between them is in the amount of turtles used to create the maze. The more turtles, the more homogenous the random pattern becomes, and thus the maze is easier to solve on average.

However, it takes a significantly shorter time to create easy mazes.

Different START and END positions also vary the difficulty a lot.

THINGS TO NOTICE

Use the sliders and pick difficulty levels. When is the maze most difficult?

For advanced users - change the world dimensions to create different size mazes.

EXTENDING THE MODEL

You may change the size of the world at any time. I recommend using 67*40. (please do not change the world wrapping - it will cause a bug).

I would like to implement a feature where mazes can be imported.

CREDITS AND REFERENCES

Benjamin Menashe, Instagram @benjamaze.original

bmenashe94@gmail.com

Comments and Questions

Click to Run Model

breed [ pacmans pacman ]
globals [ my-time ]

;; create maze
patches-own [ xxx ]

to setup
  clear-all

  ;; set white left and right sides
  ask patches with [count neighbors != 8]
    [ set xxx 1 ]
  ask patches with [pxcor = min-pxcor + 1] [set pcolor white]
  ask patches with [pxcor = max-pxcor - 1] [set pcolor white]

  ;; set top and bottom white
  ask patches with [pycor = max-pycor or pycor = min-pycor] [ set pcolor white ]
  clean-corners

  setup-start-finish ;set start and finish red patches

  ;; sprout turtles
  ask n-of edges (patches with [pcolor = white]) [
    sprout 1
      [ set color blue
        facexy -1 * pxcor pycor
        fd 1 ]
  ]
  reset-ticks
end 

to setup-start-finish
  ;; setup the red patches at both ends
  ask patches with [pxcor = max-pxcor and pycor = Right-Height] [
    set pcolor red
    ask neighbors [ set pcolor black ]
    ask patch-at 0 2 [ set pcolor white ]
    ask patch-at 0 -2 [ set pcolor white ]
  ]
  ask patches with [pxcor = min-pxcor and pycor = Left-Height] [
    set pcolor red
    ask neighbors [ set pcolor black ]
    ask patch-at 0 2 [ set pcolor white ]
    ask patch-at 0 -2 [ set pcolor white ]
  ]
end 

to clean-corners
  ;; just delete the corners from being white
  ask patches with [pycor = max-pycor and pxcor = max-pxcor ] [ set pcolor black ]
  ask patches with [pycor = max-pycor and pxcor = min-pxcor ] [ set pcolor black ]
  ask patches with [pycor = min-pycor and pxcor = max-pxcor ] [ set pcolor black ]
  ask patches with [pycor = min-pycor and pxcor = min-pxcor ] [ set pcolor black ]
end 

to go
  ;; die if neighbors are turtles
  ask turtles [
    if count turtles-on neighbors > 0
    [ die ]
  ]

  ;; turn if facing edge
  ask turtles [
    if patch-ahead 1 = nobody
    or
    patch-left-and-ahead 45 1 = nobody
    or
    patch-right-and-ahead 45 1 = nobody
    [ rt 180 ]
  ]

  ;; die if facing white
  ask turtles [
    if [pcolor] of patch-ahead 1 = white
    or
    [pcolor] of patch-left-and-ahead 45 1 = white
    or
    [pcolor] of patch-right-and-ahead 45 1 = white
    or
    [pcolor] of patch-left-and-ahead 90 1 = white
    or
    [pcolor] of patch-right-and-ahead 90 1 = white
    [ die ]
  ]


  ;; if not dead, move to random black spot with xxx = 0
  ask turtles [
    set pcolor white
    set xxx 1
    downhill4 xxx
    ;; mark the black spots connected to the move with xxx = 1 so no turtle will move their
    ask patch-left-and-ahead 135 1 [ set xxx 1 ]
    ask patch-right-and-ahead 135 1 [ set xxx 1 ]
  ]

  ;; sprout new turtles
  ask n-of edges (patches with [pcolor = white])
  [
    sprout 1
      [ set color blue
        let yyy random 4
        if yyy > 2.5
        [ set heading 0 ]
        if yyy > 1.5 and yyy < 2.5
        [ set heading 90 ]
        if yyy > 0.5 and yyy < 1.5
        [ set heading 180 ]
        if yyy > -0.5 and yyy < 0.5
        [ set heading 270 ]
        ;; turn around if facing edge
        ifelse patch-ahead 1 = nobody
        [ rt 180 fd 1]
        [ fd 1]
    ]
  ]
  tick
end 

to kill
  ;; once maze is pretty, remove al current turtles
  ask turtles [ die ]
  ;; also clean the start and finish spots a bit
  ask patches with [ pcolor = red ]
  [ask neighbors4 [ set pcolor black ]
  ]
end 

to-report edges
  ;; for how many turtles build the maze - the more the easier
    if Difficulty = "Easy" [ report count patches with [count neighbors != 8] - 6 ]
    if Difficulty = "Medium" [ report max-pycor / 3 ]
    if Difficulty = "Hard" [ report 1 ]
end 
;; end of maze creation

;; start to solve

to play
  kill
  ;; place the pacman at start
  create-pacmans 1 [
    set shape "turtle" set color green set size 1.5
    setxy max-pxcor Right-Height set heading 270
  pen-down
  ]
  reset-timer
end 

to move-pacman
    ask pacmans [
    if (patch-ahead 1 != nobody) and ([pcolor] of patch-ahead 1 != white)
    [ fd 1 ]
    if xcor = min-pxcor and ycor = Left-Height [
      set my-time timer
      user-message (word "Great job! Your time is: " my-time "sec")
    ]
  ]
end 

to move-up
  ask pacmans [ set heading 0 ]
  move-pacman
end 

to move-right
  ask pacmans [ set heading 90 ]
  move-pacman
end 

to move-down
  ask pacmans [ set heading 180 ]
  move-pacman
end 

to move-left
  ask pacmans [ set heading 270 ]
  move-pacman
end 

to restart
  clear-drawing
  ask pacmans [ die ]
  play
end 

There are 2 versions of this model.

Uploaded by When Description Download
Benjamin Menashe almost 6 years ago added timer to user message Download this version
Benjamin Menashe almost 6 years ago Initial upload Download this version

Attached files

File Type Description Last updated
Maze Game.png preview Preview for 'Maze Game' almost 6 years ago, by Benjamin Menashe Download

This model does not have any ancestors.

This model does not have any descendants.