From 25f65f212c210638d15d73c0c8dfe1fc08bd96a2 Mon Sep 17 00:00:00 2001 From: Andinus Date: Wed, 12 Jan 2022 12:42:38 +0530 Subject: Add visualize feature using Cairo This takes parts from Fornax: https://github.com/andinus/fornax Each step is visualized and a video solution is generated. --- lib/Octans/WordSearch.rakumod | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'lib/Octans/WordSearch.rakumod') diff --git a/lib/Octans/WordSearch.rakumod b/lib/Octans/WordSearch.rakumod index 23487dc..73d05cd 100644 --- a/lib/Octans/WordSearch.rakumod +++ b/lib/Octans/WordSearch.rakumod @@ -1,9 +1,9 @@ use Octans::Neighbors; use Octans::RangeSearch; -# word-search walks the given grid & tries to find words in the -# dictionary. It walks in Depth-First manner (lookup Depth-First -# search). +#| word-search walks the given grid & tries to find words in the +#| dictionary. It walks in Depth-First manner (lookup Depth-First +#| search). sub word-search( # @dict holds the dictionary. @puzzle holds the puzzle. @dict, @puzzle, @@ -18,12 +18,19 @@ sub word-search( Int $y, Int $x, $str? = @puzzle[$y][$x], # @visited holds the positions that we've already visited. - @visited? is copy --> List + @visited? is copy, + + # If true then every iteration of walking is returned. + Bool :$visualize, + + --> List ) is export { # If @visited was not passed then mark the given cell as visited # because it's the cell we're starting at. @visited[$y][$x] = True unless @visited; + take "", @visited if $visualize; + # neighbor block loops over the neighbors of $y, $x. neighbor: for neighbors(@puzzle, $y, $x).List -> $pos { # Move on to next neighbor if we've already visited this one. @@ -53,7 +60,7 @@ sub word-search( # subset of words that start with "a", so keeping # this in mind we pass the output of last # range-starts-with (@list). - @list, @puzzle, $pos[0], $pos[1], $word, @visited + @list, @puzzle, $pos[0], $pos[1], $word, @visited, :$visualize, ); } } -- cgit 1.4.1-2-gfad0 on value='grep'>log msg
path: root/lib/Octans/WordSearch.rakumod
blob: a1ed2c393ba9236875b128ea1eb901a6b8277ded (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67