List of commits:
Subject Hash Author Date (UTC)
Small cleanup. 808b149c4628b3a6445ee45542f9c866d92c943a Jan Allersma 2018-05-10 14:42:15
Fix move conditions. 9b71e9cc2703773d7c8f66cb242ca4bb615adbcc Jan Allersma 2018-05-07 20:22:25
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 808b149c4628b3a6445ee45542f9c866d92c943a - Small cleanup.
Author: Jan Allersma
Author date (UTC): 2018-05-10 14:42
Committer name: Jan Allersma
Committer date (UTC): 2018-05-10 17:05
Parent(s): 9b71e9cc2703773d7c8f66cb242ca4bb615adbcc
Signing key:
Tree: b5cc857664edb3aa47c9158525fb584ebb89cba2
File Lines added Lines deleted
opdracht3/peg.cpp 28 34
File opdracht3/peg.cpp changed (mode: 100644) (index 60dca6e..31ff971)
... ... typename std::vector<Vertex>::const_iterator Graph::cbegin(Vertex v) const
15 15 for (int r=0; r<5; r++) { for (int r=0; r<5; r++) {
16 16 for (int c=0; c<=r; c++) { for (int c=0; c<=r; c++) {
17 17 if (v[r][c] == 0) { if (v[r][c] == 0) {
18 std::cout << "scanning... ";
19 if (r>=2 && r<5 && c<=r && c>=2) adjacents.push_back(doMove(v,Move::rd));
20 18 if (r<3 && c<=r+2) adjacents.push_back(doMove(v,Move::lu)); if (r<3 && c<=r+2) adjacents.push_back(doMove(v,Move::lu));
21 19 if (r<3) adjacents.push_back(doMove(v,Move::ru)); if (r<3) adjacents.push_back(doMove(v,Move::ru));
22 if (r>=2 && r<5) adjacents.push_back(doMove(v,Move::ld));
20 if (r>=2 && r<5) {std::cout<<r<<" bij ld\n";adjacents.push_back(doMove(v,Move::ld));}
21 if (r>=2 && r<5 && c>=2) {std::cout<<r<<" bij rd\n";adjacents.push_back(doMove(v,Move::rd));}
23 22 if (c>=2) adjacents.push_back(doMove(v,Move::r)); if (c>=2) adjacents.push_back(doMove(v,Move::r));
24 23 if (c+2<=r) adjacents.push_back(doMove(v,Move::l)); if (c+2<=r) adjacents.push_back(doMove(v,Move::l));
25 24 } }
 
... ... Vertex doMove(const Vertex &v, const Move &m)
38 37 bool done=false; bool done=false;
39 38 Vertex n = v; Vertex n = v;
40 39
41 std::cout << "Scanning done!\n";
42 std::cout << ".......................\n" << n << ".......................\n";
43
44
45 40 for (int r=0; r<5 && !done; r++) { for (int r=0; r<5 && !done; r++) {
46 41 for (int c=0; c<=r && !done; c++) { for (int c=0; c<=r && !done; c++) {
47 42 if (v[r][c] == 0) { if (v[r][c] == 0) {
48 43 switch(m) { switch(m) {
49 case Move::ld:
50 std::cout << "Move 'ld'\nr: " << r << " -> " << (decltype(r))r-2 << "\n";
51 n[r-1][c] = 0;
52 std::swap(n[r][c], n[r-2][c]);
53 done = true;
54 break;
55 case Move::rd:
56 std::cout << "Move 'rd'\nr: " << r << " -> " << r-2;
57 std::cout << "\nc: " << c << " -> " << c-2 << "\n";
58 n[r-1][c-1] = 0;
59 std::swap(n[r][c], n[r-2][c-2]);
44 case Move::lu:
45 std::cout << "lu: ["<<r<<", "<<c<<"] -> ["<<r+2<<", "<<c+2<<"]\n";
46 n[r+1][c+1] = 0;
47 std::swap(n[r][c], n[r+2][c+2]);
60 48 done = true; done = true;
61 49 break; break;
62 50 case Move::ru: case Move::ru:
63 std::cout << "Move 'ru'\n";
64 std::cout << "r: " << r << " -> " << r+2 << "\n";
51 std::cout << "ru: ["<<r<<", "<<c<<"] -> ["<<r+2<<", "<<c<<"]\n";
65 52 n[r+1][c] = 0; n[r+1][c] = 0;
66 53 std::swap(n[r][c], n[r+2][c]); std::swap(n[r][c], n[r+2][c]);
67 54 done = true; done = true;
68 55 break; break;
69 case Move::lu:
70 std::cout << "Move 'lu'\nr :" << r << " -> " << r+2;
71 std::cout << "\nc: " << c << " -> " << c+2 << "\n";
72 n[r+1][c+1] = 0;
73 std::swap(n[r][c], n[r+2][c+2]);
56 case Move::ld:
57 if(r >= 2 && r < 5) {
58 std::cout << "ld: ["<<r<<", "<<c<<"] -> ["<<r-2<<", "<<c<<"]\n";
59 n[r-1][c] = 0;
60 std::swap(n[r][c], n[r-2][c]);}
61 done = true;
62 break;
63 case Move::rd:
64 if(r >= 2 && r < 5 && c >= 2) {
65 std::cout << "rd: ["<<r<<", "<<c<<"] -> ["<<r-2<<", "<<c-2<<"]\n";
66 n[r-1][c-1] = 0;
67 std::swap(n[r][c], n[r-2][c-2]);}
74 68 done = true; done = true;
75 69 break; break;
76 70 case Move::r: case Move::r:
77 std::cout << "Move 'r'\nc: " << c << " -> " << c-2 << "\n";
71 std::cout << "["<<r<<", "<<c<<"] -> ["<<r<<", "<<c-2<<"]\n";
78 72 n[r][c-1] = 0; n[r][c-1] = 0;
79 73 std::swap(n[r][c], n[r][c-2]); std::swap(n[r][c], n[r][c-2]);
80 74 done = true; done = true;
81 75 break; break;
82 76 case Move::l: case Move::l:
83 std::cout << "Move 'l'\nc: " << c << " -> " << c+2 << "\n";
77 std::cout << "l: ["<<r<<", "<<c<<"] -> ["<<r<<", "<<c+2<<"]\n";
84 78 n[r][c+1] = 0; n[r][c+1] = 0;
85 79 std::swap(n[r][c], n[r][c+2]); std::swap(n[r][c], n[r][c+2]);
86 80 done = true; done = true;
 
... ... std::ostream &operator<<(std::ostream &os, const Vertex &state)
98 92 for (int r=0; r<5; r++) { for (int r=0; r<5; r++) {
99 93 for (int x=4-r; x>0; x--) for (int x=4-r; x>0; x--)
100 94 os << " "; os << " ";
101 for (int c=0; c<r+1; c++) {
102 if (state[r][c] != 0) {
95 for (int c=0; c<=r; c++) {
96 if (state[r][c] == 1) {
103 97 os << "X "; os << "X ";
104 98 } else { } else {
105 99 os << "O "; os << "O ";
 
... ... int main()
185 179 }}; }};
186 180
187 181 Vertex goal = {{ Vertex goal = {{
188 {{1}},
189 {{1,1}},
190 {{1,1,1}},
191 {{1,1,0,1}},
192 {{1,0,0,1,1}}
182 {{0}},
183 {{0,0}},
184 {{0,0,0}},
185 {{0,0,0,0}},
186 {{0,0,1,0,0}}
193 187 }}; }};
194 188
195 189 Path path = bfs(graph, start, [&](Vertex v) { return (v == goal); }); Path path = bfs(graph, start, [&](Vertex v) { return (v == goal); });
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