Maze solving: Difference between revisions
Content deleted Content added
(3 intermediate revisions by 2 users not shown) | |||
Line 1,636:
=={{header|EasyLang}}==
[https://easylang.online/show/#cod=hVTbbqMwFHz3V4zUl1yEa1KQEmnZH0FoRcE0VsCOTJo2/fqVLxi7u9p9SfCcCz5zZpjFF0eFvCQSFQ7YYTbIHjkZDM4YnrGRyMBouSUjl5jqBhI7SPIE8tp2lzet3mUPxhi5atVhPquPX1P7xUFBCYBu5K02D4PSEKYtbgq+l8EBiAFTLRpUYB4B8IkKG4EM+RaT6iHX0CMK9eIehzo1Ko3T6bRCk7pzfGKHARkGPOOAR3xaMzXvbhiwQ07L5d9H7Sz2Zx45v4JRlhNK1DDMtbl4jRwSWY5NJrdoHBmTY+Kq5oWNqb6qOQwayDKHPvQ54AUFmpi0Ar36kDeF3N+nRwXdyl5NEAskNCrYG/V13yzkmmdU6GuR0G0utTc1jd1JK/sAGiUsgYjGtCTaVDRmKE5po4TL3sQrpx6zOk9Re+GJXv4hE6+RPKwiyZVp1iEczRv/BiGDNGL/MyR9aK2yrzt7l3je89KnmZIEJyspZ7d1N77jjZIwNFkV8ISFEH2xVHZqXDixVjBYaoZHAgcjOAt0aiSp+PdW7oUXvz/ZAqG7kdvzCy0JJW+jem1HDNba1BtbjXduNstiPYvBZ61S0fz2rmUgLcxzYiyxT+nrnSwcQb7Ff1qqYRV/YaXktXBetFAklticsYcaLHN5iF3VbD57TrXONUJHFjG1P366iYM75DfpO1Y2Jne/7KYwj7b9mhfxFFVH9Egcj8ckEoiKYPrdVi4pJ+4ezMrxQMhv Run it]
<syntaxhighlight lang=text>
size = 15
n = 2 * size + 1
Line 1,664:
d[] = [ 1 2 3 4 ]
for i = 4 downto 1
d =
dir = offs[d[d]]
d[d] = d[i]
Line 1,684:
m[n * n - n + i] = 2
.
h = 2 *
m_maze h
m[endpos] = 0
Line 1,709:
return
.
of =
for h = 1 to 4
dir = (h + of) mod1 4
Line 5,803:
| > > > ^ | | >
+---+---+---+---+---+---+---+---+---+---+---+
</pre>
=={{header|Uiua}}==
Just add the following lines to the end of [https://rosettacode.org/wiki/Maze_generation#Uiua the generator]. It shows you the maze that has been solved with the path highlighted, the list of moves, and the total path length.
<syntaxhighlight lang="uiua">
# You can delete from here to SOLVE THE MAZE
# if you're appending this to the maze generator code.
# Experimental!
["+-+-+-+-+-+-+"
"|. . .|. . .|"
"+-+-+ + + + +"
"|.|. .|.|.|.|"
"+ + +-+-+ + +"
"|.|. . . .|.|"
"+ +-+-+-+-+ +"
"|. . . . . .|"
"+-+-+-+-+-+-+"]
H ← 4
W ← 6
Nfour ← +⊙¤[¯2_0 2_0 0_2 0_¯2] # Gives N4
InBounds ← ▽⊸≡(↧⊃(/↧≥1_1|/↧< +1 × 2 H_W))
GetWall ← -:⊡1:÷2/-.
# S O L V E T H E M A Z E #
.
Start ← 1_1
End ← -Start ×2 H_W
Heur ← /+⌵-End # Manhattan distance.
# (pos grid) -> 1-4 next steps, in bounds, without walls in the way.
Ns ← ≡⊡1▽:⟜(≡(=@ ⊡)⊙¤≡GetWall)≡⊟¤:InBounds Nfour.
astar(Ns|Heur|≍End) Start # Solve (costs = 1 => djikstra)
$"_ moves" ⊙⟜(⍜(⊡|+33)):°□⊢
</syntaxhighlight>
{{out}}
<pre>
╭─
╷ "+-+-+-+-+-+-+"
"|O O O|. O O|"
"+-+-+ + + + +"
"|.|O O|.|O|O|"
"+ + +-+-+ + +"
"|.|O O O O|O|"
"+ +-+-+-+-+ +"
"|. . . . . O|"
"+-+-+-+-+-+-+"
╯
╭─
╷ 1 1
1 3
1 5
3 5
3 3
5 3
5 5
5 7
5 9
3 9
1 9
1 11
3 11
5 11
7 11
╯
"14 moves"
</pre>
|