Home / utk / cs140 / fa18 / lab9 / ss_solver_template.cpp
Directory Listing
ss_solver_template.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//C++
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <sstream>

//C
#include <stdio.h>
#include <stdlib.h>

using namespace std;

// ----------------------------------------------------------------------------
// Class/Struct Function Prototypes
// ----------------------------------------------------------------------------

/*
 * Class for ShapeShifter. Has a grid of the initial setup that you will try to
 * put pieces into. Also has a struct called "shape" that stores a shape's
 * grid, width, and height.
 */

typedef unsigned int uint;

class ShapeShifter {
	struct shape {
		//Constructors
		shape();
		shape(const string&);
		
		//Variables
		vector< vector<bool> > grid;
		uint width, height;
		string text;
	};
		
	public:
		//Constructors
		ShapeShifter();
		ShapeShifter(const vector<string>&);
		
		//Dealing with shapes
		void add_shape(const string&);
		bool apply_shape(uint, uint, uint);
		
		//Solving functions
		bool all_one();
		bool find_solution(uint);
		void print_solution();
		
	private:
		//All shapes to be inserted into the grid
		vector<shape> shapes;
		
		//Game Grid
		vector< vector<bool> > grid;
		
		//(x, y) points for each shape when the solution is found.
		list< pair<uint, uint> > solution;
		
		//Game grid size
		uint width, height;
};

// ----------------------------------------------------------------------------
// Class/Struct Function Declarations
// ----------------------------------------------------------------------------

/* Shape Struct */
ShapeShifter::shape::shape() {
	/* Leave Empty */
}

ShapeShifter::shape::shape(const string& line) {
	/*
	 * Takes "line" and makes a grid out of it.
	 *
	 * - Split the string by space (probably via istringstream).
	 *   Put each row into a temporary vector<string>.
	 *
	 * - Go through each char in each row and set "grid" up.
	 *
	 * - Set width and height
	 *
	 * - Store the original string ("line") in "text".
	 */
}

/* ShapeShifter Class */
ShapeShifter::ShapeShifter() {
	/* Leave Empty */
}

ShapeShifter::ShapeShifter(const vector<string>& rows) {
	/*
	 * Similar to the "shape" constructor. Except you're given a vector of
	 * rows already. So you can skip the splitting part.
	 */
}

void ShapeShifter::add_shape(const string& line) {
	/*
	 * Should just be one line. Push back a shape made with the string "line".
	 */
}

bool ShapeShifter::apply_shape(uint shape_id, uint x, uint y) {
	/*
	 * Insert the shape into the game grid.
	 *
	 * - Check if the shape can fit in the grid when shifted by "x" and "y".
	 * - Invert all parts of the grid where the shape would be red at.
	 */
}

bool ShapeShifter::all_one() {
	/*
	 * Check if all cells in the grid are "1". If so, return true. Otherwise,
	 * return false.
	 */
}

bool ShapeShifter::find_solution(uint shape_id) {
	/*
	 * The recursive function.
	 *
	 * - With "shape_id", go through every possible position and try to insert
	 *   shape[shape_id] in.
	 *
	 * - If inserted and it isn't the last shape, call:
	 *     find_solution(shape_id + 1)
	 *
	 * - If inserted and it is the last shape, call "all_one". If true then
	 *   return true. Have the other calls to the function also handle this
	 *   return.
	 *
	 * - If you looped through all possible positions and it didn't work, undo
	 *   all changes done to the class involving this shape and return false.
	 */
}

void ShapeShifter::print_solution() {
	/*
	 * Goes through "solution" list and prints out the coordinates of each
	 * shape, along with the original string used to make up the shape.
	 */
}

// ----------------------------------------------------------------------------
// Main Function
// ----------------------------------------------------------------------------

int main(int argc, char** argv) {
	/*
	 * - Create a vector of strings holding all argv after argv[0]
	 *
	 * - Create your ShapeShifter object.
	 *
	 * - Create all shapes.
	 *
	 * - Find a solution.
	 *
	 * - Print the result.
	 */
}