Skip to content

Commit 733d9d9

Browse files
committed
new river solution
1 parent e3fb49b commit 733d9d9

File tree

16 files changed

+805
-0
lines changed

16 files changed

+805
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
+-----------------+
2+
| Missionaries |
3+
| |
4+
| |
5+
| |
6+
| |
7+
| |
8+
| |
9+
| 1 2 3 |
10+
+-----------------+
11+
| Cannibals |
12+
| |
13+
| |
14+
| |
15+
| |
16+
| |
17+
| |
18+
| 1 2 3 |
19+
+-----------------+
20+
| |
21+
| Bank |
22+
| |
23+
| |
24+
+-----------------+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/"'~~~~~.~~~~~'"\
2+
\_______________/
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
\V/
3+
(_)O
4+
/| |+
5+
/r\|
6+
" "'
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#include <iostream>
2+
#include <cstring>
3+
#include <fstream>
4+
#include <cassert>
5+
6+
using namespace std;
7+
8+
#include "river.h"
9+
10+
int main() {
11+
12+
/* This section illustrates the use of the pre-supplied functions. */
13+
cout << "============== Pre-supplied functions ==================" << endl << endl;
14+
15+
cout << "Breakfast time!" << endl;
16+
char **scene = create_scene();
17+
add_to_scene(scene, 2, 24, "sun.txt");
18+
add_to_scene(scene,14, 45, "cannibal.txt");
19+
add_to_scene(scene,14, 9, "cannibal.txt");
20+
add_to_scene(scene, 8, 25, "missionary.txt");
21+
add_to_scene(scene, 8, 30, "missionary.txt");
22+
add_to_scene(scene, 12, 20, "pot.txt");
23+
print_scene(scene);
24+
destroy_scene(scene);
25+
26+
cout << "====================== Question 1 ======================" << endl << endl;
27+
28+
cout << "Recreating Figure 2: "<< endl;
29+
char line[100];
30+
ifstream in("boat.txt");
31+
in.getline(line,100);
32+
cout << strlen(line)<<endl;
33+
34+
35+
// the scene shown in Figure 2 in the spec
36+
cout << "The scene shown in Figure 2:" << endl;
37+
scene = make_river_scene("CM","MM");
38+
print_scene(scene);
39+
40+
// the initial state
41+
cout << "The initial state: "<< endl;
42+
scene = make_river_scene("BCCCMMM","");
43+
print_scene(scene);
44+
45+
/*
46+
cout << "Some other state: "<< endl;
47+
scene = make_river_scene("BCCMM","CM");
48+
print_scene(scene);
49+
50+
cout << "Some other state: "<< endl;
51+
scene = make_river_scene("CCMM","CM");
52+
print_scene(scene);
53+
*/
54+
55+
cout << "====================== Question 2 ======================" << endl << endl;
56+
57+
char left[10] = "MMMB";
58+
int result = perform_crossing(left, "MM");
59+
cout << status_description(result) << endl << endl;
60+
cout << "After crossing left = " << left << endl;
61+
62+
strcpy(left, "BCCCMMM");
63+
result = perform_crossing(left, "MC");
64+
cout << status_description(result) << endl << endl;
65+
cout << "After crossing left = " << left << endl;
66+
cout << endl << endl << endl;
67+
cout << "====================== Question 3 ======================" << endl << endl;
68+
69+
//result = play_game();
70+
71+
//cout << "The game ended as follows: " << status_description(result) << endl;
72+
73+
cout << "=================== Bonus Challenge ====================" << endl << endl;
74+
75+
char answer[512];
76+
answer[0]='\0';
77+
strcpy(left, "MMMCCCB");
78+
if (find_solution(left, answer)==VALID_GOAL_STATE)
79+
cout << "Solution is " << answer << endl;
80+
else
81+
cout << "Solution does not exist." << endl;
82+
83+
return 0;
84+
}

past_exams/2013_river_copy/main.o

43.9 KB
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
river: river.o main.o
2+
g++ -g -Wall river.o main.o -o river
3+
4+
river.o: river.cpp river.h
5+
g++ -g -c -Wall river.cpp
6+
7+
main.o: main.cpp river.h
8+
g++ -g -c -Wall main.cpp
9+
10+
clean:
11+
rm *.o
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
_
2+
(_)
3+
/ + \
4+
\\ //
5+
/ \
6+
.___.

past_exams/2013_river_copy/pot.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
("""""""")
2+
) (
3+
/ \
4+
___| |___
5+
()__\__________/__()
6+
.`/``||``\`.
7+
()/ () \()

past_exams/2013_river_copy/river

66 KB
Binary file not shown.

0 commit comments

Comments
 (0)