List <levelTesterState_s> SearchAllOptionsOneLevelDeep(levelTesterState_s parentState, ref levelTesterState_s bestState, int personToExclude) { List <levelTesterState_s> returnState = new List <levelTesterState_s>(); foreach (actionPossibility _actionPossibility in FindAllPossibleActions()) { if (_actionPossibility.personIndex == personToExclude) { continue; } ReturnToPreviousLevelState(parentState); PerformAnAction(_actionPossibility); levelTesterState_s currentState = GetLevelState(); currentState.InitializeStart(); currentState.numStepsToReach = currentStepsTaken; currentState.AddPath(parentState.pathOfActions, _actionPossibility.personIndex, _actionPossibility.isGoodAction); //MonoBehaviour.print ("current and parent:" + currentState.pathOfActions + " from " + parentState.pathOfActions); if (currentState == winState) // if you find a win state... { bestWinStateHasBeenFound = true; returnState.Add(currentState); bestState = currentState; MonoBehaviour.print("the win state is: " + currentState.pathOfActions); break; } else if (CheckIfMatchingStateExists(currentState).isNull) // if it's a new state... { statesThatHaveBeenReached.Add(currentState); returnState.Add(currentState); } else { //MonoBehaviour.print ("matching state -- end branch"); } } return(returnState); }
public levelTesterState_s PathfindLevel_BreadthFirst(int personToExclude) { FindNetworkManager(); bestWinStateHasBeenFound = false; // create winning state for reference List <Mood> allPositive = new List <Mood>(); for (int i = 0; i < networkMgr.GetNumPeople(); i++) { allPositive.Add(Mood.Positive); } winState = new levelTesterState_s(allPositive, true, 0); levelTesterState_s bestWinState = new levelTesterState_s(); levelTesterState_s gameStartingState = GetLevelState(); gameStartingState.InitializeStart(); statesThatHaveBeenReached.Clear(); statesThatHaveBeenReached.Add(gameStartingState); // make a default "best win" bestWinState.numStepsToReach = 99; // create lists to hold the "levels" of depth for the search List <levelTesterState_s> parentList = new List <levelTesterState_s>(); List <levelTesterState_s> childList = new List <levelTesterState_s>(); parentList.Add(gameStartingState); // to start, game start state is in the parent list... currentStepsTaken = 0; while (!bestWinStateHasBeenFound) { currentStepsTaken++; if (currentStepsTaken > 10) { MonoBehaviour.print("breaking out early, none found"); break; } if (parentList.Count == 0) { //MonoBehaviour.print ("TESTER FEEDBACK: this level is impossible"); bestWinState.numStepsToReach = -1; return(bestWinState); } foreach (levelTesterState_s _parentState in parentList) { childList.AddRange(SearchAllOptionsOneLevelDeep(_parentState, ref bestWinState, personToExclude)); if (bestWinStateHasBeenFound) { break; } } if (!bestWinStateHasBeenFound) { parentList.Clear(); parentList.AddRange(childList); childList.Clear(); } else { //MonoBehaviour.print ("TESTER FEEDBACK: requires " + bestWinState.numStepsToReach + " steps"); } } return(bestWinState); }