void ReturnToPreviousLevelState(levelTesterState_s levelStateToReturnTo) { for (int i = 0; i < networkMgr.GetNumPeople(); i++) { Person p = networkMgr.GetAllPeople()[i]; p.SetMood(levelStateToReturnTo.myState[p.personalIndex]); } }
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; }
levelTesterState_s CheckIfMatchingStateExists(levelTesterState_s stateToCompare) { foreach (levelTesterState_s _state in statesThatHaveBeenReached) { if (stateToCompare == _state) { return(_state); } } levelTesterState_s nullState = new levelTesterState_s(); nullState.isNull = true; return(nullState); // a new state has been found, return a "null" state }
public bool CheckIfLevelCanBeOneClick(levelTesterState_s bestLevel) { List<int> tracker = new List<int>(); foreach (var actions in bestLevel.pathOfActions.trail) // for the path of actions to reach the best path... { if (tracker.Contains(actions.Key)) // if a person has been clicked twice { return false; } else { tracker.Add(actions.Key); } } return true; }
public bool CheckIfLevelCanBeOneClick(levelTesterState_s bestLevel) { List <int> tracker = new List <int>(); foreach (var actions in bestLevel.pathOfActions.trail) // for the path of actions to reach the best path... { if (tracker.Contains(actions.Key)) // if a person has been clicked twice { return(false); } else { tracker.Add(actions.Key); } } return(true); }
levelTesterState_s GetLevelState() { List <Mood> statesOfPeople = new List <Mood>(); for (int i = 0; i < networkMgr.GetNumPeople(); i++) { statesOfPeople.Add(Mood.Neutral); // create a place holder list, defaulting everyone to neutral } for (int i = 0; i < networkMgr.GetNumPeople(); i++) { Person _people = networkMgr.GetAllPeople()[i]; statesOfPeople[_people.personalIndex] = _people.GetMood(); // if (_people.m_Mood == Mood.Positive) // { // statesOfPeople[_people.personalIndex] = true; // } } levelTesterState_s listToReturn = new levelTesterState_s(); listToReturn.myState = statesOfPeople; return(listToReturn); }
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); }
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; }
levelTesterState_s GetLevelState() { List<Mood> statesOfPeople = new List<Mood>(); for (int i = 0; i < networkMgr.GetNumPeople(); i++) { statesOfPeople.Add(Mood.Neutral); // create a place holder list, defaulting everyone to neutral } for (int i = 0; i < networkMgr.GetNumPeople(); i++) { Person _people = networkMgr.GetAllPeople()[i]; statesOfPeople[_people.personalIndex] = _people.GetMood(); // if (_people.m_Mood == Mood.Positive) // { // statesOfPeople[_people.personalIndex] = true; // } } levelTesterState_s listToReturn = new levelTesterState_s(); listToReturn.myState = statesOfPeople; return listToReturn; }
levelTesterState_s CheckIfMatchingStateExists(levelTesterState_s stateToCompare) { foreach (levelTesterState_s _state in statesThatHaveBeenReached) { if (stateToCompare == _state) { return _state; } } levelTesterState_s nullState = new levelTesterState_s(); nullState.isNull = true; return nullState; // a new state has been found, return a "null" state }
bool RunOneLevelTrial() { FindNetworkManager(); ValidLevels thisLevel = new ValidLevels(); LevelValidator lv = new LevelValidator(); levelTesterState_s bestWinState = lv.PathfindLevel_BreadthFirst(); if (bestWinState.numStepsToReach == -1) { return(false); } else { thisLevel.numClicks = bestWinState.numStepsToReach; // set number of clicks } thisLevel.level = networkMgr.GetNumPeople(); // set how many people on this level if (thisLevel.level == 3) { thisLevel.difficulty = Difficulty.VeryEasy; } // set difficulty from number of clicks and level else if (thisLevel.level == 4 && thisLevel.numClicks < 3) { thisLevel.difficulty = Difficulty.VeryEasy; } else if (thisLevel.level == 4 && thisLevel.numClicks >= 3) { thisLevel.difficulty = Difficulty.Easy; } else if (thisLevel.level == 5 && thisLevel.numClicks < 4) { thisLevel.difficulty = Difficulty.Easy; } else if (thisLevel.level == 5 && thisLevel.numClicks >= 4) { thisLevel.difficulty = Difficulty.Medium; } else if (thisLevel.level == 6 && thisLevel.numClicks < 3) { return(false); } // this level is too easy else if (thisLevel.level == 6 && thisLevel.numClicks < 5) { thisLevel.difficulty = Difficulty.Medium; } else if (thisLevel.level == 6 && thisLevel.numClicks >= 5) { thisLevel.difficulty = Difficulty.Hard; } else if (thisLevel.level == 7 && thisLevel.numClicks < 3) { return(false); } // this level is too easy else if (thisLevel.level == 7 && thisLevel.numClicks < 5) { thisLevel.difficulty = Difficulty.Medium; } else if (thisLevel.level == 7 && thisLevel.numClicks >= 5) { thisLevel.difficulty = Difficulty.Hard; } else if (thisLevel.level == 8 && thisLevel.numClicks < 3) { return(false); } // this level is too easy else if (thisLevel.level == 8 && thisLevel.numClicks < 5) { thisLevel.difficulty = Difficulty.Medium; } else if (thisLevel.level == 8 && thisLevel.numClicks >= 5) { thisLevel.difficulty = Difficulty.Hard; } else { Debug.LogException(new System.Exception("Level and number of clicks wasn't handled by levelTester class (" + thisLevel.level + ", " + thisLevel.numClicks + ")")); } thisLevel.seed = networkMgr.usedSeed; // set used seed thisLevel.path = bestWinState.pathOfActions; if (lv.CheckIfLevelCanBeOneClick(bestWinState)) { thisLevel.oneClick = true; } // find a person for the cantTouch special level bool foundCantClickPerson = false; for (int i = 0; i < bestWinState.pathOfActions.trail.Count; i++) { int personToExclude = bestWinState.pathOfActions.trail[i].Key; networkMgr.ReloadStartingState(); LevelValidator lv2 = new LevelValidator(); levelTesterState_s bestWinState2 = lv2.PathfindLevel_BreadthFirst(personToExclude); if (bestWinState2.numStepsToReach != -1) { foundCantClickPerson = true; thisLevel.cantTouch = personToExclude; //print (bestWinState.numStepsToReach + ":" + bestWinState2.numStepsToReach); thisLevel.cantTouchPath = bestWinState2.pathOfActions; } } if (!foundCantClickPerson) { thisLevel.cantTouch = -1; } if (thisLevel.difficulty != Difficulty.Impossible) { lv.levelList.Add(thisLevel); if (fp == null) { fp = new ValidSeedListFileParse(); } fp.SerializeALevel(thisLevel); } return(true); }
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); }