|
| 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 | +} |
0 commit comments