List of commits:
Subject Hash Author Date (UTC)
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 2d1eab4b6d1979fef27078298053de6a4e973dc7 - Represent cracker barrel peg. Fix Move::ru and Move::ld
Author: Jan Allersma
Author date (UTC): 2018-04-24 08:02
Committer name: Jan Allersma
Committer date (UTC): 2018-04-25 07:00
Parent(s): b66a173514c7a7b05c89d97de266beafd9e68a20
Signing key:
Tree: 1c294e645f7eefdf5d69e5bb8684fbf683ae47c3
File Lines added Lines deleted
opdracht3/peg.cpp 35 29
opdracht3/peg.hpp 2 2
File opdracht3/peg.cpp changed (mode: 100644) (index adedfd3..9ec5d42)
... ... typename std::vector<Vertex>::const_iterator Graph::cbegin(Vertex v) const
8 8 { {
9 9 adjacents.clear(); adjacents.clear();
10 10
11 for (int r=0; r<3; r++) {
12 for (int c=0; c<3; c++) {
11 for (int r=0; r<5; r++) {
12 for (int c=0; c<r+1; c++) {
13 13 if (v[r][c] == 0) { if (v[r][c] == 0) {
14 if (c<1) adjacents.push_back(doMove(v,Move::l));
15 if (c>1) adjacents.push_back(doMove(v,Move::r));
16 if (r<1) adjacents.push_back(doMove(v,Move::u));
17 if (r>1) adjacents.push_back(doMove(v,Move::d));
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));
18 18 } }
19 19 } }
20 20 } }
 
... ... Vertex doMove(const Vertex &v, const Move &m)
31 31 bool done=false; bool done=false;
32 32 Vertex n = v; Vertex n = v;
33 33
34 for (int r=0; r<3 && !done; r++) {
35 for (int c=0; c<3 && !done; c++) {
34 for (int r=0; r<5 && !done; r++) {
35 for (int c=0; c<r+1 && !done; c++) {
36 36 if (v[r][c] == 0) { if (v[r][c] == 0) {
37 37 switch(m) { switch(m) {
38 case Move::l:
39 n[r][c+1] = 0;
40 std::swap(n[r][c], n[r][c+2]);
38 case Move::ld:
39 n[r-1][c] = 0;
40 std::swap(n[r][c], n[r-2][c]);
41 41 done = true; done = true;
42 42 break; break;
43 case Move::r:
44 n[r][c-1] = 0;
45 std::swap(n[r][c], n[r][c-2]);
43 case Move::rd:
44 n[r-1][c-1] = 0;
45 std::swap(n[r][c], n[r-2][c-2]);
46 46 done = true; done = true;
47 47 break; break;
48 case Move::u:
48 case Move::ru:
49 49 n[r+1][c] = 0; n[r+1][c] = 0;
50 std::swap(n[r+2][c], n[r][c]);
50 std::swap(n[r][c], n[r+2][c]);
51 51 done = true; done = true;
52 52 break; break;
53 case Move::d:
54 n[r-1][c] = 0;
55 std::swap(n[r-2][c], n[r][c]);
53 case Move::lu:
54 n[r+1][c+1] = 0;
55 std::swap(n[r][c], n[r+2][c+2]);
56 56 done = true; done = true;
57 57 break; break;
58 58 } }
 
... ... Vertex doMove(const Vertex &v, const Move &m)
64 64
65 65 std::ostream &operator<<(std::ostream &os, const Vertex &state) std::ostream &operator<<(std::ostream &os, const Vertex &state)
66 66 { {
67 for (int r=0; r<3; r++) {
68 for (int c=0; c<3; c++) {
67 for (int r=0; r<5; r++) {
68 for (int x=4-r; x>0; x--)
69 os << " ";
70 for (int c=0; c<r+1; c++) {
69 71 if (state[r][c] != 0) { if (state[r][c] != 0) {
70 os << state[r][c];
72 os << "X ";
71 73 } else { } else {
72 os << " ";
74 os << "O ";
73 75 } }
74 76 } }
75 77 os << std::endl; os << std::endl;
 
... ... int main()
144 146 Graph graph; Graph graph;
145 147
146 148 Vertex start = {{ Vertex start = {{
147 {{1,2,3}},
148 {{0,7,4}},
149 {{8,6,5}}
149 {{0}},
150 {{1,1}},
151 {{1,1,1}},
152 {{1,1,1,1}},
153 {{1,1,1,1,1}}
150 154 }}; }};
151 155
152 156 Vertex goal = {{ Vertex goal = {{
153 {{1,2,3}},
154 {{4,0,0}},
155 {{8,6,5}}
157 {{0}},
158 {{0,0}},
159 {{0,0,0}},
160 {{0,0,0,0}},
161 {{0,0,1,0,0}}
156 162 }}; }};
157 163
158 164 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 85363fd..c8f162e)
10 10 #include <stack> #include <stack>
11 11 #include <set> #include <set>
12 12
13 enum class Move { l, r, u, d };
14 using State = std::array<std::array<int,3>,3>;
13 enum class Move { lu, ru, ld, rd };
14 using State = std::array<std::array<int,5>,5>;
15 15
16 16 using Vertex = State; using Vertex = State;
17 17 using Path = std::vector<Vertex>; using Path = std::vector<Vertex>;
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