List of commits:
Subject Hash Author Date (UTC)
Add 'Move::r' and 'Move::l'. 9f4febe3b67175d16e19a936a6e947b0d75109d4 Jan Allersma 2018-04-30 16:13:53
Represent cracker barrel peg. Fix Move::ru and Move::ld 2d1eab4b6d1979fef27078298053de6a4e973dc7 Jan Allersma 2018-04-24 08:02:54
Change way of moving and conditions for moving from 8puzzle to peg. b66a173514c7a7b05c89d97de266beafd9e68a20 Jan Allersma 2018-04-23 08:54:56
Unix-style bracketing on opdracht3. Remove carriage returns ('\r') in opdracht3. Add Bread-first search to peg.cpp. Update gitignore: Ignore all files in opdracht3 except for source files. 17234cdf77357d8da3efa75f959e9559eb0faf91 Jan Allersma 2018-04-17 07:24:52
First attempt at completing the assignments. acd1a9c82a11066cefa28cf97afdf6f708ecefa0 Jan Allersma 2018-04-06 17:40:28
Initial commit. All original assignments. d1c1567a0ded18a38ba9d43e2a79ca8ad94d4ac5 Jan Allersma 2018-04-06 17:34:42
Commit 9f4febe3b67175d16e19a936a6e947b0d75109d4 - Add 'Move::r' and 'Move::l'.
Author: Jan Allersma
Author date (UTC): 2018-04-30 16:13
Committer name: Jan Allersma
Committer date (UTC): 2018-04-30 16:13
Parent(s): 2d1eab4b6d1979fef27078298053de6a4e973dc7
Signing key:
Tree: 5f088e74f0233fb429a6995abdb3779c6ec67b3b
File Lines added Lines deleted
opdracht3/peg.cpp 35 11
opdracht3/peg.hpp 1 1
File opdracht3/peg.cpp changed (mode: 100644) (index 9ec5d42..f052830)
... ... typename std::vector<Vertex>::const_iterator Graph::cbegin(Vertex v) const
11 11 for (int r=0; r<5; r++) { for (int r=0; r<5; r++) {
12 12 for (int c=0; c<r+1; c++) { for (int c=0; c<r+1; c++) {
13 13 if (v[r][c] == 0) { if (v[r][c] == 0) {
14 if (r>=2) adjacents.push_back(doMove(v,Move::ld));
15 if (r>=2 && c>=2) adjacents.push_back(doMove(v,Move::rd));
16 if (r<=3) adjacents.push_back(doMove(v,Move::ru));
17 if (r<=3 && c<=3) adjacents.push_back(doMove(v,Move::lu));
14 std::cout << "scanning... ";
15 if (c>=2 && r>=2) adjacents.push_back(doMove(v,Move::rd));
16 if (r<=3 && c+2<=r) adjacents.push_back(doMove(v,Move::lu));
17 if (r<=3) adjacents.push_back(doMove(v,Move::ru));
18 if (r>=2 && 0) adjacents.push_back(doMove(v,Move::ld)); // Illegal move.
19 if (c>=2) adjacents.push_back(doMove(v,Move::r));
20 if (c+2<=r) adjacents.push_back(doMove(v,Move::l));
18 21 } }
19 22 } }
20 23 } }
 
... ... Vertex doMove(const Vertex &v, const Move &m)
31 34 bool done=false; bool done=false;
32 35 Vertex n = v; Vertex n = v;
33 36
37 std::cout << "Scanning done!\n";
38 std::cout << ".......................\n" << n << ".......................\n";
39
40
34 41 for (int r=0; r<5 && !done; r++) { for (int r=0; r<5 && !done; r++) {
35 42 for (int c=0; c<r+1 && !done; c++) { for (int c=0; c<r+1 && !done; c++) {
36 43 if (v[r][c] == 0) { if (v[r][c] == 0) {
37 44 switch(m) { switch(m) {
38 45 case Move::ld: case Move::ld:
46 std::cout << "Move 'ld'\n";
39 47 n[r-1][c] = 0; n[r-1][c] = 0;
40 48 std::swap(n[r][c], n[r-2][c]); std::swap(n[r][c], n[r-2][c]);
41 49 done = true; done = true;
42 50 break; break;
43 51 case Move::rd: case Move::rd:
52 std::cout << "Move 'rd'\n";
44 53 n[r-1][c-1] = 0; n[r-1][c-1] = 0;
45 54 std::swap(n[r][c], n[r-2][c-2]); std::swap(n[r][c], n[r-2][c-2]);
46 55 done = true; done = true;
47 56 break; break;
48 57 case Move::ru: case Move::ru:
58 std::cout << "Move 'ru'\n";
49 59 n[r+1][c] = 0; n[r+1][c] = 0;
50 60 std::swap(n[r][c], n[r+2][c]); std::swap(n[r][c], n[r+2][c]);
51 61 done = true; done = true;
52 62 break; break;
53 63 case Move::lu: case Move::lu:
64 std::cout << "Move 'lu'\n";
54 65 n[r+1][c+1] = 0; n[r+1][c+1] = 0;
55 66 std::swap(n[r][c], n[r+2][c+2]); std::swap(n[r][c], n[r+2][c+2]);
56 67 done = true; done = true;
57 68 break; break;
69 case Move::r:
70 std::cout << "Move 'r'\n";
71 n[r][c-1] = 0;
72 std::swap(n[r][c], n[r][c-2]);
73 done = true;
74 break;
75 case Move::l:
76 std::cout << "Move 'l'\n";
77 n[r][c+1] = 0;
78 std::swap(n[r][c], n[r][c+2]);
79 done = true;
80 break;
58 81 } }
59 82 } }
60 83 } }
61 84 } }
85 std::cout << n;
62 86 return n; return n;
63 87 } }
64 88
 
... ... int main()
146 170 Graph graph; Graph graph;
147 171
148 172 Vertex start = {{ Vertex start = {{
149 {{0}},
173 {{1}},
150 174 {{1,1}}, {{1,1}},
151 {{1,1,1}},
175 {{1,0,1}},
152 176 {{1,1,1,1}}, {{1,1,1,1}},
153 177 {{1,1,1,1,1}} {{1,1,1,1,1}}
154 178 }}; }};
155 179
156 180 Vertex goal = {{ Vertex goal = {{
157 {{0}},
158 {{0,0}},
159 {{0,0,0}},
160 {{0,0,0,0}},
161 {{0,0,1,0,0}}
181 {{1}},
182 {{1,1}},
183 {{1,1,1}},
184 {{1,1,0,1}},
185 {{1,0,0,1,1}}
162 186 }}; }};
163 187
164 188 Path path = bfs(graph, start, [&](Vertex v) { return (v == goal); }); Path path = bfs(graph, start, [&](Vertex v) { return (v == goal); });
File opdracht3/peg.hpp changed (mode: 100644) (index c8f162e..fb740a8)
10 10 #include <stack> #include <stack>
11 11 #include <set> #include <set>
12 12
13 enum class Move { lu, ru, ld, rd };
13 enum class Move { lu, ru, ld, rd, r, l };
14 14 using State = std::array<std::array<int,5>,5>; using State = std::array<std::array<int,5>,5>;
15 15
16 16 using Vertex = State; using Vertex = State;
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/kapstok/NHL-Algoritmiek

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/kapstok/NHL-Algoritmiek

Clone this repository using git:
git clone git://git.rocketgit.com/user/kapstok/NHL-Algoritmiek

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main