SlideShare uma empresa Scribd logo
1 de 38
Baixar para ler offline
Fun with Mazes
Hendrik Neumann
2
https://pragprog.com/titles/jbmaze/
Standing on the shoulders of giants (one in particular)
3
What is a Maze?
4
Some more..
5
grid
cells
walls
passages
Build mazes
6
Build mazes
7
For each cell in the grid,
randomly carve either north or
east.
• strong diagonal texture
tending toward the north-
east corner of the grid.
• corridors run the length of
the northern row and the
eastern column.
Binary Tree
8
„every cell can reach every
other cell by exactly one path”
logical and mathematical purity
perfect but yet flawed
Perfect maze
9
opposite of a perfect maze
„characterized by few (if any)
dead ends, and passages
forming loops”
multiple different paths
Braid maze
10
Easy by hand for a 4x4 maze ;-)
Computer should do the work:
Dijkstra
Solve a maze
11
Measures the shortest distance
between some starting point
(which we specify), and every
other cell in the maze.
• shortest path from a chosen
endpoint to our starting point
Dijstra‘s Algorithm
0
12
Measures the shortest distance
between some starting point
(which we specify), and every
other cell in the maze.
• shortest path from a chosen
endpoint to our starting point
Dijstra‘s Algorithm
0 1
13
Measures the shortest distance
between some starting point
(which we specify), and every
other cell in the maze.
• shortest path from a chosen
endpoint to our starting point
Dijstra‘s Algorithm
0 1 2
2
14
Measures the shortest distance
between some starting point
(which we specify), and every
other cell in the maze.
• shortest path from a chosen
endpoint to our starting point
Dijstra‘s Algorithm
0 1 2 3 4
3 2 3 8 5
4 3 6 7 6
5 4 5 6 7
6 7 8 7 8
15
Measures the shortest distance
between some starting point
(which we specify), and every
other cell in the maze.
• shortest path from a chosen
endpoint to our starting point
• walk backward from end to
start.
Dijstra‘s Algorithm
0 1 2 3 4
3 2 3 8 5
4 3 6 7 6
5 4 5 6 7
6 7 8 7 8
16
Finding the longest path in a
maze
• find the longest path
between two cells
• might not be the longest
path of the maze! – but just
part of it
• run Dijstra again in the other
direction
Dijstra‘s Algorithm
17
Finding the longest path in a
maze
• find the longest path
between two cells
• might not be the longest
path of the maze! – but just
part of it
• run Dijstra again in the other
direction
Dijstra‘s Algorithm
18
Finding the longest path in a
maze
• find the longest path
between two cells
• might not be the longest
path of the maze! – but just
part of it
• run Dijstra again in the other
direction
Dijstra‘s Algorithm
19
Finding the longest path in a
maze
• find the longest path
between two cells
• might not be the longest
path of the maze! – but just
part of it
• run Dijstra again in the other
direction
Dijstra‘s Algorithm
20
Color a maze
21
 coloring emphazises the maze‘s texture
Color a maze
Binary Tree Sidewinder Recursive
Backtracker
22
Texture in a maze is a result of
the bias of the algorithm.
Other signs might be long
passages or the amount of dead
ends.
Not automatically a bad thing!
Example: 2x2 grid perfect maze
 four possibilities:
• Binary Tree: A, B  50%
• Sidewinder: A, B, C  75%
Bias
Random walk  for unbiased algorithm
23
Aldous-Broder Wilson‘s
Unbiased mazes
Random walk  for unbiased algorithm
24
Starting at an arbitrary location
in the grid, move randomly from
cell to cell.
If moving to a previously
unvisited cell, carve a passage
to it.
End when all cells have been
visited.
Aldous-Broder
25
1. Pick a cell at random
2. Pick a random neighbour: east – not visited yet, link cells together
3. Pick next random neighbour..
Aldous-Broder
26
Aldous-Broder
4. Pick a random neighbour: west – not visited yet: link cells together
5. Pick a random neighbour: north – already visited: don‘t link cells
6. Finish the maze by randomly visiting neighbours until all are visited
27
Starts quickly but can take a
very long time to finish.
Mazes are guaranteed perfectly
random.
Unbiased – no preference to
any particular texture or feature.
Aldous-Broder
28
Random Walks…
• ..can take a long time (Aldous-Broder)
• ..can need a lot of memory (Wilson‘s)
Bias not automatically a bad thing!
Let’s look a algorithms that add constraints to random walks:
• Hunt-and-Kill
• Recursive Backtracker
Adding Constraints to Random Walks
29
Starting at an arbitrary location,
perform a random walk,
avoiding previously visited cells.
When no more moves are
possible, backtrack to the most
recently visited cell and resume
the random walk from there.
The algorithm ends when it tries
to backtrack from the cell where
it started.
Recursive Backtrack
30
• Start at A4. Put current cell on the stack
• Choose an unvisited neighbor randomly - Carve a path and push it
on the stack. A3 = current cell
Recursive Backtracker
stack
A4
stack
 A3
A4
stack
31
• Continue with the process.. Put the cells on the stack
• We‘re stuck - B4 has no unvisited neighbors
Recursive Backtracker
stack
C4
C3
…
A3
A4
stack
B4
C4
C3
…
A3
A4
32
• Pop the dead end from the stack  C4 is again our current cell
• C4 has an unvisited neighbor  D4
Recursive Backtracker
stack
B4
C4
C3
…
A3
A4
stack
D4
C4
C3
…
A3
A4
33
• Continue until every cell has been visited
• Final cell is always a dead end  backtrack to the beginning.
Recursive Backtracker
stack
A2
A1
B1
…
A3
A4
stack
A2
A1
B1
…
A3
A4
34
• Stack is empty. Algorithm is finished.
Recursive Backtracker
stack
deapth-first search
35
• long, twisty passages with
relatively few dead ends
• fast - as it visits every cell
only twice
• needs considerably memory
to keep track of visited cells
Recursive Backtrack
36
ABAP
• colored mazes in html view
• more 7.4/7.5 magic
Github
Javascript mazes… and UI
• D3.js
• openUI5
Future with Mazes
37
More is possible…
Thanks
Hendrik Neumann
h.neumann@reply.de

Mais conteúdo relacionado

Último

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Último (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Destaque

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 

Destaque (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

Fun with Mazes

  • 2. 2 https://pragprog.com/titles/jbmaze/ Standing on the shoulders of giants (one in particular)
  • 3. 3 What is a Maze?
  • 7. 7 For each cell in the grid, randomly carve either north or east. • strong diagonal texture tending toward the north- east corner of the grid. • corridors run the length of the northern row and the eastern column. Binary Tree
  • 8. 8 „every cell can reach every other cell by exactly one path” logical and mathematical purity perfect but yet flawed Perfect maze
  • 9. 9 opposite of a perfect maze „characterized by few (if any) dead ends, and passages forming loops” multiple different paths Braid maze
  • 10. 10 Easy by hand for a 4x4 maze ;-) Computer should do the work: Dijkstra Solve a maze
  • 11. 11 Measures the shortest distance between some starting point (which we specify), and every other cell in the maze. • shortest path from a chosen endpoint to our starting point Dijstra‘s Algorithm 0
  • 12. 12 Measures the shortest distance between some starting point (which we specify), and every other cell in the maze. • shortest path from a chosen endpoint to our starting point Dijstra‘s Algorithm 0 1
  • 13. 13 Measures the shortest distance between some starting point (which we specify), and every other cell in the maze. • shortest path from a chosen endpoint to our starting point Dijstra‘s Algorithm 0 1 2 2
  • 14. 14 Measures the shortest distance between some starting point (which we specify), and every other cell in the maze. • shortest path from a chosen endpoint to our starting point Dijstra‘s Algorithm 0 1 2 3 4 3 2 3 8 5 4 3 6 7 6 5 4 5 6 7 6 7 8 7 8
  • 15. 15 Measures the shortest distance between some starting point (which we specify), and every other cell in the maze. • shortest path from a chosen endpoint to our starting point • walk backward from end to start. Dijstra‘s Algorithm 0 1 2 3 4 3 2 3 8 5 4 3 6 7 6 5 4 5 6 7 6 7 8 7 8
  • 16. 16 Finding the longest path in a maze • find the longest path between two cells • might not be the longest path of the maze! – but just part of it • run Dijstra again in the other direction Dijstra‘s Algorithm
  • 17. 17 Finding the longest path in a maze • find the longest path between two cells • might not be the longest path of the maze! – but just part of it • run Dijstra again in the other direction Dijstra‘s Algorithm
  • 18. 18 Finding the longest path in a maze • find the longest path between two cells • might not be the longest path of the maze! – but just part of it • run Dijstra again in the other direction Dijstra‘s Algorithm
  • 19. 19 Finding the longest path in a maze • find the longest path between two cells • might not be the longest path of the maze! – but just part of it • run Dijstra again in the other direction Dijstra‘s Algorithm
  • 21. 21  coloring emphazises the maze‘s texture Color a maze Binary Tree Sidewinder Recursive Backtracker
  • 22. 22 Texture in a maze is a result of the bias of the algorithm. Other signs might be long passages or the amount of dead ends. Not automatically a bad thing! Example: 2x2 grid perfect maze  four possibilities: • Binary Tree: A, B  50% • Sidewinder: A, B, C  75% Bias Random walk  for unbiased algorithm
  • 23. 23 Aldous-Broder Wilson‘s Unbiased mazes Random walk  for unbiased algorithm
  • 24. 24 Starting at an arbitrary location in the grid, move randomly from cell to cell. If moving to a previously unvisited cell, carve a passage to it. End when all cells have been visited. Aldous-Broder
  • 25. 25 1. Pick a cell at random 2. Pick a random neighbour: east – not visited yet, link cells together 3. Pick next random neighbour.. Aldous-Broder
  • 26. 26 Aldous-Broder 4. Pick a random neighbour: west – not visited yet: link cells together 5. Pick a random neighbour: north – already visited: don‘t link cells 6. Finish the maze by randomly visiting neighbours until all are visited
  • 27. 27 Starts quickly but can take a very long time to finish. Mazes are guaranteed perfectly random. Unbiased – no preference to any particular texture or feature. Aldous-Broder
  • 28. 28 Random Walks… • ..can take a long time (Aldous-Broder) • ..can need a lot of memory (Wilson‘s) Bias not automatically a bad thing! Let’s look a algorithms that add constraints to random walks: • Hunt-and-Kill • Recursive Backtracker Adding Constraints to Random Walks
  • 29. 29 Starting at an arbitrary location, perform a random walk, avoiding previously visited cells. When no more moves are possible, backtrack to the most recently visited cell and resume the random walk from there. The algorithm ends when it tries to backtrack from the cell where it started. Recursive Backtrack
  • 30. 30 • Start at A4. Put current cell on the stack • Choose an unvisited neighbor randomly - Carve a path and push it on the stack. A3 = current cell Recursive Backtracker stack A4 stack  A3 A4 stack
  • 31. 31 • Continue with the process.. Put the cells on the stack • We‘re stuck - B4 has no unvisited neighbors Recursive Backtracker stack C4 C3 … A3 A4 stack B4 C4 C3 … A3 A4
  • 32. 32 • Pop the dead end from the stack  C4 is again our current cell • C4 has an unvisited neighbor  D4 Recursive Backtracker stack B4 C4 C3 … A3 A4 stack D4 C4 C3 … A3 A4
  • 33. 33 • Continue until every cell has been visited • Final cell is always a dead end  backtrack to the beginning. Recursive Backtracker stack A2 A1 B1 … A3 A4 stack A2 A1 B1 … A3 A4
  • 34. 34 • Stack is empty. Algorithm is finished. Recursive Backtracker stack deapth-first search
  • 35. 35 • long, twisty passages with relatively few dead ends • fast - as it visits every cell only twice • needs considerably memory to keep track of visited cells Recursive Backtrack
  • 36. 36 ABAP • colored mazes in html view • more 7.4/7.5 magic Github Javascript mazes… and UI • D3.js • openUI5 Future with Mazes