/**************************************************************** * Engineering 4892 Data Structures * Assignment: 4 Question 2 Date Due: July 5th/2001 * Name: Daryl Martin * Student #: 9713520 * Username: darylm *****************************************************************/ #include "assign4a.h" /***************************************************************** * goal - determines if there is a solution to the marble game * using at most steps moves * *****************************************************************/ bool goal(int initial, int steps, std::list& m) { if (initial < 0 || steps < 0) {return false;} else if(initial%2 == 0 && initial != 38){ //if the number is even and it is not 38 initial = initial/2; //divide the initial value by 2 steps--; //decrement steps to keep track of how many "moves" we have made m.push_back(GiveBack); //push value onto the list goal(initial, steps, m); //recursive call to the function goal } else if(initial%2 != 0 && initial !=91){ //if number is not even and it is not 91 initial = initial + 53; //add 53 to your initial steps--; //decrement steps to keep track of how many "moves" we have made m.push_back(More); //push More onto the stack goal(initial,steps,m); //recursive call to the function goal } else if(initial == 38){ //if initial is 38 initial = initial + 53; // add 53 to get 91 steps--; m.push_back(More); goal(initial,steps,m); } else if (initial == 91){ //if initial is 91 than just return true return true; } }