private IEnumerator ProcessAction(ActionHandler action) { if (action.stateMachine.IsDead()) { yield break;//Skips the turn if actor is dead } //Calls ActionFunction method depending on which action type is being executed switch (action.actionID) { case (ActionList.Pass): yield return(ActionFunctions.Pass(action)); break; case (ActionList.BasicEnemyAttack): yield return(ActionFunctions.BasicEnemyAttack(action)); break; case (ActionList.BasicHeroAttack): yield return(ActionFunctions.BasicHeroAttack(action)); break; case (ActionList.SlimeSlap): yield return(ActionFunctions.SlimeSlap(action)); break; } yield return(WaitForKeyPress(KeyCode.Space)); yield return(null); }
public GridComponent(float x, float y, float width, float height, float renderLayer, string path) { X = x; Y = y; Width = width; Height = height; RenderLayer = renderLayer; int minX = 0; int minY = 0; int maxX = 0; int maxY = 0; int xTile = 0; int yTile = 0; Action[] actions = ActionFunctions.PathToActions(path); Dictionary <(int, int), byte[]> tiles = new Dictionary <(int, int), byte[]>() { { (0, 0), Colors[Action.Down] }, }; foreach (Action action in actions) { switch (action & ~Action.A) { case Action.Left: xTile--; break; case Action.Right: xTile++; break; case Action.Up: yTile--; break; case Action.Down: yTile++; break; } tiles[(xTile, yTile)] = Colors[action];
public void ChangePath(string path) { int minX = 0; int minY = 0; int maxX = 0; int maxY = 0; int xTile = 0; int yTile = 0; Action[] actions = ActionFunctions.PathToActions(path); Dictionary <(int, int), byte[]> tiles = new Dictionary <(int, int), byte[]>() { { (0, 0), Colors[Action.Down] }, }; foreach (Action action in actions) { switch (action & ~Action.A) { case Action.Left: xTile--; break; case Action.Right: xTile++; break; case Action.Up: yTile--; break; case Action.Down: yTile++; break; } tiles[(xTile, yTile)] = Colors[action];
public static void StartSearch(int numThreads, int minDelay, int maxDelay) { Console.WriteLine("Buffered=" + Buffered + ", Overflow=" + Overflow); List <byte[][]> stateList = new List <byte[][]>(); MakeSave(); Gold gb = new Gold(true); List <GscTile> endTiles = new List <GscTile>() { r29[38, 16] }; gb.SetTimeSec(120); for (int i = 0; i <= (maxDelay - minDelay); i++) { stateList.Add(new byte[60][]); } new GscIntroSequence(GscStrat.GfSkip, GscStrat.TitleSkip, GscStrat.Continue).ExecuteUntilIGT(gb); gb.AdvanceFrames(minDelay, Joypad.Left); byte[] state = gb.SaveState(); for (int i = 0; i < stateList.Count(); i++) { for (int igt = 0; igt < 60; igt++) { gb.LoadState(state); gb.CpuWrite("wGameTimeFrames", (byte)igt); gb.AdvanceFrames(i, Joypad.Left); gb.Hold(Joypad.A, "OWPlayerInput"); stateList[i][igt] = gb.SaveState(); } } RandomPathSearch.StartSearch <Gold, GscTile>(numThreads, new RandomSearchParameters <GscTile>() { StateList = stateList, ClusterSize = 1, SS = 60, NumPathsToFind = int.MaxValue, StartEdgeSet = 0, StartTile = gb.Tile, EndTiles = endTiles.ToArray(), ExecutionCallback = (gb, actions) => gb.Execute(actions) == gb.OverworldLoopAddress, FoundCallback = (stateIndex, actions, successes) => { lock (startWriter) { startWriter.WriteLine(successes + " " + stateIndex + " " + ActionFunctions.ActionsToPath(actions)); startWriter.Flush(); } }, }); }
void Awake() { if (instance == null) { instance = this; } else { GameObject.Destroy(gameObject); return; } instance.currState = BattleState.OUTOFBATTLE; DontDestroyOnLoad(this.gameObject); ActionFunctions.SetupAactionFunctions(); }
public static void End(Gold[] gbs, Action[] path, byte[][] states, GscTile startTile) { Console.WriteLine("Searching for end path..."); DFParameters <Gold, GscTile> parameters = new DFParameters <Gold, GscTile>() { NoEncounterSS = 60, MaxCost = 0, EndTiles = new GscTile[] { r30[17, 12] }, FoundCallback = state => { Console.WriteLine("Found an end path!!"); endWriter.WriteLine(ActionFunctions.ActionsToPath(path) + " " + state.Log); endWriter.Flush(); } }; DepthFirstSearch.StartSearch(gbs, parameters, startTile, 0, states); }
static void Cherrygrove(Gold[] gbs, Action[] path, byte[][] states, GscTile startTile) { long cherryPathsFound = 0; long numSeenPaths = 0; HashSet <(int, int, int)> rngs = new HashSet <(int, int, int)>(); while (numSeenPaths < 30) { GC.Collect(); Console.WriteLine("Searching for cherrygrove path (" + cherryPathsFound + ")..."); var ret = RandomPathSearch.StartSearch(gbs, new RandomSearchParameters <GscTile>() { StateList = new List <byte[][]>() { states }, ClusterSize = 1, SS = 60, NumPathsToFind = 1, StartEdgeSet = 0, StartTile = startTile, EndTiles = new GscTile[] { r30[12, 46], r30[13, 46] }, ExecutionCallback = (gb, actions) => gb.Execute(actions) == gb.OverworldLoopAddress, }).First(); cherryPathsFound++; Action[] actions = ret.Actions; IGTResults results = ret.Results[0]; (int, int, int)rng = (results.MostCommonHRA, results.MostCommonHRS, results.MostCommonDivider); Action[] concatPath = path.Concat(actions).ToArray(); cherrygroveWriter.WriteLine(ActionFunctions.ActionsToPath(concatPath)); cherrygroveWriter.Flush(); if (!rngs.Add(rng)) { numSeenPaths++; continue; } else { numSeenPaths = 0; } gbs[0].LoadState(results.FirstState); End(gbs, concatPath, results.States, gbs[0].Tile); } }
public List <GscTile> Sight(GscMap map) { Action dir = ActionFunctions.FromSpriteDirection(Direction); List <GscTile> sight = new List <GscTile>(); GscTile current = map[StandingMapX - 4, StandingMapY - 4]; for (int j = 0; j < Range; j++) { current = current.GetNeighbor(dir); if (current == null) { break; } sight.Add(current); } return(sight); }
public void NewBattle(int returnID, GameObject[] enemiesToAdd) { //Finds Information Panel informationPanel = GameObject.Find("InformationPanelText").GetComponent <InformationPanel>(); ActionFunctions.SetupAactionFunctions(); //Sets sceneId to return to returnSceneID = returnID; //Repopulate the enemyList enemyList.Clear(); GameObject[] enemyLocations = GameObject.FindGameObjectsWithTag("Enemy Loc"); for (int i = 0; i < enemiesToAdd.Length; i++) { GameObject newEnemy = Instantiate(enemiesToAdd[i]); newEnemy.transform.position = enemyLocations[i].transform.position; enemyList.Add(newEnemy); } //Adds enemyStates to List enemyStates.Clear(); for (int i = 0; i < enemyList.Count; i++) { if (enemyList[i] != null) { enemyStates.Add(enemyList[i].GetComponent <EnemyState>()); } } //Add heroes to scene heroList.Clear(); heroStates.Clear(); List <GameObject> heroesToAdd = HeroManager.GetInstance().heroList; GameObject[] heroLocations = GameObject.FindGameObjectsWithTag("Hero Loc"); for (int i = 0; i < heroesToAdd.Count; i++) { GameObject newHero = Instantiate(heroesToAdd[i]); newHero.transform.position = heroLocations[i].transform.position; newHero.SetActive(true); heroList.Add(newHero); heroStates.Add(newHero.GetComponent <HeroState>()); } turnNumber = 1; currState = BattleState.ENEMYDECIDE; }
private void ExecuteAction(string str, Character cData) { string response = ""; // switch statement for all the actions switch (str.ToUpper()) { case "A1": response = ActionFunctions.GivePraisingSpeech(cData); break; case "A2": response = ActionFunctions.IssuePublicReprimand(cData); break; default: break; } characterScreen.CommText.text = response; // send the text of the response to the character's screen }
private void EndOfTurn() { //Check if either side is dead if (CheckHeroDeaths()) { ActionFunctions.DisplayText("All heroes are dead"); EndBattle(false); return; } if (CheckEnemyDeaths()) { ActionFunctions.DisplayText("All enemies are dead"); EndBattle(true); return; } turnNumber++; //If so start new turn currState = BattleState.STARTOFTURN; return; }
static void R29(Gold[] gbs, byte[][] states, GscTile startTile) { HashSet <(int, int, int)> rngs = new HashSet <(int, int, int)>(); while (true) { Console.WriteLine("Searching for r29 path..."); var ret = RandomPathSearch.StartSearch(gbs, new RandomSearchParameters <GscTile>() { StateList = new List <byte[][]>() { states }, ClusterSize = 1, SS = 60, NumPathsToFind = 1, StartEdgeSet = 0, StartTile = startTile, EndTiles = new GscTile[] { cherrygrove[33, 7] }, ExecutionCallback = (gb, action) => gb.Execute(action) == gb.OverworldLoopAddress, }).First(); Action[] actions = ret.Actions; IGTResults results = ret.Results[0]; (int, int, int)rng = (results.MostCommonHRA, results.MostCommonHRS, results.MostCommonDivider); r29Writer.WriteLine(ActionFunctions.ActionsToPath(ret.Actions)); r29Writer.Flush(); if (!rngs.Add(rng)) { continue; } gbs[0].LoadState(results.FirstState); Cherrygrove(gbs, ret.Actions, results.States, gbs[0].Tile); } }
public void EndBattle(bool didHeroesWin) { ActionFunctions.DisplayText("Victory: " + didHeroesWin); //Sets current state of battle currState = BattleState.OUTOFBATTLE; //Reset states of BattleManager //Reward xp and update the heroes if (didHeroesWin) { int totalXP = 0; foreach (EnemyState enemyState in enemyStates) { totalXP += enemyState.enemy.xp; } foreach (HeroState heroState in heroStates) { heroState.hero.xp += totalXP; } List <BaseHero> updatedHeroes = new List <BaseHero>(); foreach (HeroState state in heroStates) { updatedHeroes.Add(state.hero); } HeroManager.GetInstance().ImportHeroList(updatedHeroes); } //Empty the enemylist enemyList.Clear(); //Return to platform level //Remove Enemies from level Debug.Log("Returning to: " + returnSceneID); SceneController.GetInstance().StartCoroutine("SwitchScene", returnSceneID); return; }
public static string CleanUpPathParallel <Gb>(Gb[] gbs, byte[][] states, int ss, params Action[] path) where Gb : Gsc { List <int> aPressIndices = new List <int>(); for (int i = 0; i < path.Length; i++) { if ((path[i] & Action.A) > 0) { aPressIndices.Add(i); } } foreach (int index in aPressIndices) { path[index] &= ~Action.A; int successes = IGTCheckParallel(gbs, states, gb => gb.Execute(path) == gb.SYM["OWPlayerInput"]).TotalSuccesses; if (successes < ss) { path[index] |= Action.A; } } return(ActionFunctions.ActionsToPath(path)); }