Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*******************************************************************************
- * Name : waterjug.cpp
- * Author : Jake Lovrin and Mateusz Mrockzkowski
- * Date : 10/20/17
- * Description : Solving the famous water jug puzzle using breadth-first search.
- * Pledge : I pledge my honor that I have abided by the Stevens Honor System. -Jake Lovrin and Mateusz Mrockzkowski
- ******************************************************************************/
- #include <iostream>
- #include <sstream>
- #include <vector>
- #include <queue>
- using namespace std;
- vector<int> jugs;
- vector<int> goals;
- queue<State> possibilities;
- State** visited;
- // Struct to represent the state of the water in the jugs.
- struct State {
- int a, b, c;
- vector<string> directions;
- State(int _a, int _b, int _c) : a(_a), b(_b), c(_c) { }
- // String representation fo state in tuple form.
- string to_string() {
- ostringstream oss;
- oss << "(" << a << ", " << b << ", " << c << ")";
- return oss.str();
- }
- };
- bool generatepossibilities(){
- }
- void printing(){
- }
- int main(int argc, char * const argv[]) {
- if (argc != 7) {
- cerr << "Usage: ./waterjugpuzzle <cap A> <cap B> <cap C> <goal A> <goal B> <goal C>";
- return 1;
- }
- istringstream iss;
- int arguments;
- for (int i = 1; i < 4; ++i){
- iss.str(argv[i]);
- if (!(iss >> arguments) || (arguments <= 0)){
- cerr << "Error: Invalid capacity '" << iss.str() << "' for jug " << (char) ('A' + i - 1) << ".";
- return 1;
- }
- jugs.push_back(arguments);
- iss.clear();
- }
- for (int i = 4; i < 7; ++i){
- iss.str(argv[i]);
- if (!(iss >> arguments) || (arguments < 0)){
- cerr << "Error: Invalid goal '" << iss.str() << "' for jug " << (char) ('A' + i - 4) << ".";
- return 1;
- }
- goals.push_back(arguments);
- iss.clear();
- }
- for (int i = 0; i < 3; ++i){
- if (goals[i] > jugs[i]){
- cerr << "Error: Goal cannot exceed capacity of jug " << (char) ('A' + i) << ".";
- return 1;
- }
- }
- if ((goals[0] + goals[1] + goals[2]) != jugs[2]){
- cerr << "Error: Total gallons in goal state must be equal to the capacity of jug C.";
- return 1;
- }
- State s(0, 0, 8);
- cout << s.to_string() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement