• Home
  • About
  • HORIZONS EBOOK
  • EBOOKS
    • HAIKU & SHORT POEMS EBOOK
    • ABROJOS EBOOK!
    • POSTERS EBOOK!
    • TAROT EBOOK !
    • THE BRIDGE EBOOK!
  • MY BLOG POSTS
  • VISUALS / ART WORK
    • GRAPHIC DESIGN
      • ILLUSTRATIONS
  • Haiku
  • POETRY
  • PHOTOGRAPHY
    • Fall
    • Nature
  • HORIZONS POSTS
  • HAIKU & SHORT POEMS POSTS
  • THE BRIDGE POSTS
  • TAROT POSTS
  • ABROJOS POSTS
  • POSTERS
  • Translations
  • #Flash Fiction
  • MISC ITEMS
    • MISC WRITINGS
      • #Flash Non-Fiction
      • FOLK MUSIC
      • #Prose Poems/#Short Fiction
      • STOP TPP!
    • POSTCARD ART
  • VIDEOS
  • SOFTWARE
    • SOFTWARE-TO-GO
  • BOOKSTORE
  • BOOKS / REVIEWS
    • Book Reviews
  • PRINTS

Phil G's Blog/Website

~ Art, Photography, Poetry, Life

Phil G's Blog/Website

Tag Archives: Mazes

Maze Game Version 03 Is Now Ready !!!

14 Sunday Sep 2014

Posted by philsblog01 in SOFTWARE

≈ Leave a comment

Tags

HTML5, JAVASCRIPT, Mazes, Phil Gennuso, Software

screen for maze games, click for full size

screen for maze games, click for full size

Back in July, I released my first version of a Maze game, a 15 by 15 grid. This is now my third maze, and for this I used a web program I wrote that allowed me to manually create this maze. It uses a 20×20 grid, same as Maze 02, but I believe this will be a bit trickier!

You can find my maze games, along with other software at my site:

http://www.pgtestsoft.com

Once you reach my site just follow -> Mazes -> Maze Game 03

If you just want to go directly to this third Maze try this link:

http://www.pgtestsoft.com/PlayMazeGame03.htm

I have made some changes to the layout of my site to make navigation easier, so it might look a bit different from you last visit.

There are now three maze games available, also a version of Mastermind, and an application, Create Maze DFS, that will create a depth first maze for you!

I always appreciate any feedback and/or comments.

I have several more maze projects on the deck. Certainly I will post at least one more maze, possibly a multi-dimensional one. Also I may release my web software which allows you to manually build your own maze.

Stay tuned!

Software: Create Your Own Maze! (Using The Recursive Backtracking Algorithm)

31 Sunday Aug 2014

Posted by philsblog01 in SOFTWARE

≈ Leave a comment

Tags

CANVAS, HTML5, JAVASCRIPT, Mazes, Phil Gennuso, Software

Opening Screen, Click For Full Size

Opening Screen, Click For Full Size

This is my continuing project to build software games, board games, mazes, and the like.

The technology I am using is HTML5/Canvas and JavaScript, important tools for anyone working on the Web.

This particular application is perhaps more geared towards developers and computer scientists than general users but if you really like mazes you might enjoy watching how a maze gets automatically generated, right before your very eyes! And if you like you can delve into the algorithms either by reading here, looking at the code, or looking online.

If you would like to jump to the page where this particular application is use this link:
http://www.pgtestsoft.com/CreateMazeDFS.htm

If you would like to go to the web site and then link to the maze creating game use this link:
http://www.pgtestsoft.com

To create a project that is more than trivial, yet simple enough to understand, I have chosen a 15×15 size matrix for maze creation.

Ok, so just what is the Recursive Backtracking Algorithm? Quite a mouthful you might say, particularly if you have never studied Computer Science. But actually it is relatively simple to understand and something we probably all have done in our lives.

Consider talking a walk in the forest, along a trail, and you are looking for some destination at the end of that trail but you are not sure of the path you need to take. As you walk along, every time you come to a junction, where there is at least one and perhaps a few choices to make, you remember that point, then you chose one of the paths and follow it until it either reaches the goal or ends up as a dead end. If it reaches the goal, than great! You have won. If it is a dead end, you go back (backtrack) to the last point where you had to make a choice about which path to chose. Then when you get back to that junction point you mark off the path you took which was a dead end (so you don’t go over it again), and you try another path.

That’s it! Well almost. That is the backtracking part. The recursive part is how you get back to that path, in a computer. Computers have what is called a stack, like a stack of plates. So after you make your choice of a path you put each new step you make on that stack of steps, in this case. Then, if you hit a dead end, you just “pop” each step off that stack and go back (backtrack) to where you made a choice of paths. Then you mark the failed path and strike out in a new direction!

Of course, what I described is how you would search using paths that already existed. Here we are creating a path that does not yet exist in our grid. The logic however is pretty much the same, kind of like turning your socks inside out and wearing them. Here again, in the forest, you create a path, until you finally run out of paths to make. At that point, one of the paths will be correct.

That is the high level view. For those interested in the high level view of the coding and data structures you can follow from here.

First we need a few data structures. A grid of cells, in this case a matrix, 15×15, of unconnected cells. My representation is a matrix, in this case of 225 cells, with each cell represented by an array size 4, where the value can be either 0 or 1. So [1, 1, 1, 1], starts with the left wall of the cell, the top wall of the cell, the right wall of the cell, and the bottom of the cell. If the value is 1, then there is no link in that direction, if the value is 0, then there is a link (or path) in that direction. So for cell [1], the second cell in the matrix, row 0, column 1, a value of [0, 1, 0, 1] would mean the left wall isn’t there, the top wall is there, the right wall isn’t there, and the bottom wall is there. Of course the values for the adjacent cells must match up.

Next, we need a stack that contains all the cells not yet visited. We need a stack of cells that have been visited. For debugging purposes, I have included a separate, static stack of cells, that have been visited.

When we begin the program we must load the stack of not visited cells with all the cells in the matrix, or in this case 225 cells. We initialize the stack of visited cells to null.

Now we are set to begin. We must chose one of the cells as the start point, the current cell. I typically use the cell in the top left corner of the matrix, [0,0].

while there are more cells that have not been visited
–>find all neighbors (adjacent) cells that have not been connected to the current cell
–>if unlinked neighbor(s) are found
—->choose one randomly
—->connect this cell to the current cell
—->remove the current cell from the not visited stack (if it has not already been removed)
—->push the current cell onto the visited stack (this stack is used to backtrack)
—->make the cell we just connected, the current cell
->else (no unlinked neighbors found)
—->if the visited stack is not empty
——–>pop this stack, make that cell the current cell
—->else (the visited stack is empty)
——–>choose a cell (randomly) from the not visited stack
——–>make this the current cell
—->end if (visited stack not empty)
–>end if (unlinked neighbor found)
end while (more cells not visitied)

Please note, this is a general high level view. The basic algorithm is the same but you can used different types of data structures to implement the details. The important thing, from a CS point of view, is this is a variation of depth first search, using a recursive stack, and random choices when confronted with more than one path. In essence we are turning DFS inside out, using a DFS to carve out a set of paths that at some point, will connect to the end of the maze, or the goal.

This algorithm will create a maze for you with a guaranteed path, but typically you will want to fine tune the matrix to make the game a bit more interesting. The path from start to finish, usually takes many twists and turns, but there may not be all that many junctions that you face along the way. So you will have to use the arrow keys and go left, right, up, down, etc, many times, but you will not face all that many points where you have to ask, “which path should I choose?”.

There are other interesting questions here, like are you guaranteed to create a path (you are, at least after running this 100s of times, I have always created one), for example, and how would you prove it? Also, are there other ways to create a maze automatically, and yes there are.

This is just to whet the appetite and get you started!

I always appreciate any comments and suggestions.

RECENT POSTS

  • Don’t Get Too Close! (#NatureWednesday) February 8, 2023
  • Osprey Revisited ! (#Nature #Poetry #GraphicArts) February 7, 2023
  • Frosted (#Nature #Haiku #GraphicArts) February 6, 2023

Top Posts & Pages

  • HOME PAGE
  • Winter Twilight (#Haiku #GraphicArts)
  • Red Maple (#NatureWednesday #Haiku)
  • Dahlia (#NatureWednesday #Quatrain)
  • Spring Is Coming ! (#NatureWednesday #Flowers #Haiku)

Blog Stats

  • 70,023 hits
Follow Phil G's Blog/Website on WordPress.com

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 1,674 other subscribers

STATCOUNTER

wordpress com stats

META DATA

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.com

RIGHTS RESERVED

ALL RIGHTS RESERVED!

Categories

Archives

Blog at WordPress.com.

  • Follow Following
    • Phil G's Blog/Website
    • Join 1,032 other followers
    • Already have a WordPress.com account? Log in now.
    • Phil G's Blog/Website
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
 

Loading Comments...