Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. /*******************************************************************************
  2. * Name : waterjug.cpp
  3. * Author : Jake Lovrin and Mateusz Mrockzkowski
  4. * Date : 10/20/17
  5. * Description : Solving the famous water jug puzzle using breadth-first search.
  6. * Pledge : I pledge my honor that I have abided by the Stevens Honor System. -Jake Lovrin and Mateusz Mrockzkowski
  7. ******************************************************************************/
  8.  
  9. #include <iostream>
  10. #include <sstream>
  11. #include <vector>
  12. #include <queue>
  13.  
  14. using namespace std;
  15.  
  16. vector<int> jugs;
  17. vector<int> goals;
  18. queue<State> possibilities;
  19. State** visited;
  20.  
  21. // Struct to represent the state of the water in the jugs.
  22. struct State {
  23. int a, b, c;
  24. vector<string> directions;
  25.  
  26. State(int _a, int _b, int _c) : a(_a), b(_b), c(_c) { }
  27.  
  28. // String representation fo state in tuple form.
  29. string to_string() {
  30. ostringstream oss;
  31. oss << "(" << a << ", " << b << ", " << c << ")";
  32. return oss.str();
  33. }
  34. };
  35.  
  36. bool generatepossibilities(){
  37.  
  38. }
  39.  
  40. void printing(){
  41.  
  42. }
  43.  
  44. int main(int argc, char * const argv[]) {
  45. if (argc != 7) {
  46. cerr << "Usage: ./waterjugpuzzle <cap A> <cap B> <cap C> <goal A> <goal B> <goal C>";
  47. return 1;
  48. }
  49. istringstream iss;
  50. int arguments;
  51. for (int i = 1; i < 4; ++i){
  52. iss.str(argv[i]);
  53. if (!(iss >> arguments) || (arguments <= 0)){
  54. cerr << "Error: Invalid capacity '" << iss.str() << "' for jug " << (char) ('A' + i - 1) << ".";
  55. return 1;
  56. }
  57. jugs.push_back(arguments);
  58. iss.clear();
  59. }
  60. for (int i = 4; i < 7; ++i){
  61. iss.str(argv[i]);
  62. if (!(iss >> arguments) || (arguments < 0)){
  63. cerr << "Error: Invalid goal '" << iss.str() << "' for jug " << (char) ('A' + i - 4) << ".";
  64. return 1;
  65. }
  66. goals.push_back(arguments);
  67. iss.clear();
  68. }
  69. for (int i = 0; i < 3; ++i){
  70. if (goals[i] > jugs[i]){
  71. cerr << "Error: Goal cannot exceed capacity of jug " << (char) ('A' + i) << ".";
  72. return 1;
  73. }
  74. }
  75. if ((goals[0] + goals[1] + goals[2]) != jugs[2]){
  76. cerr << "Error: Total gallons in goal state must be equal to the capacity of jug C.";
  77. return 1;
  78. }
  79.  
  80. State s(0, 0, 8);
  81. cout << s.to_string() << endl;
  82. return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement