public DFState KeyDown(Keys key) { if (states[currentState] is PressFireState) game.ResetGame(); currentState = states[CurrentState].KeyDown(key); return currentState; }
public DogfightStateMachine(IGame game) { this.game = game; states = new Dictionary<DFState, IState>(); states[DFState.PressFire] = new PressFireState(); states[DFState.InGame] = new InGameState(game); states[DFState.GameOver] = new GameOverState(); currentState = DFState.PressFire; }
public static void EvaluateTototdile(Gold gb, DFState <GscMap, GscTile> state) { GscPokemon toto = Textboxes(gb); int atk = toto.DVs.Attack; int def = toto.DVs.Defense; int spd = toto.DVs.Speed; int spc = toto.DVs.Special; int stars = 0; if (atk == 15) { stars += 2; } else if (atk >= 12) { stars++; } else if (atk <= 7) { stars -= 3; } else if (atk <= 8) { stars -= 2; } else if (atk <= 9) { stars--; } if (def >= 13) { stars += 2; } else if (def >= 10) { stars++; } else if (def <= 5) { stars -= 3; } else { stars--; } if (spd == 15) { stars += 2; } else if (spd >= 11) { stars++; } else if (spd <= 3) { stars -= 3; } else if (spd <= 7) { stars -= 2; } else if (spd <= 9) { stars--; } if (spc == 15) { stars += 2; } else if (spc >= 14) { stars++; } else if (spc <= 7) { stars -= 3; } else if (spc <= 9) { stars -= 2; } else if (spc <= 11) { stars--; } string starsStr; if (stars == 8) { starsStr = "[***]"; } else if (stars >= 6) { starsStr = "[ **]"; } else if (stars >= 4) { starsStr = "[ *]"; } else { starsStr = "[ ]"; } //if(stars >= 8) { lock (Writer) { Writer.WriteLine("{0} [{1} cost] {2}- {3:x4}", starsStr, state.WastedFrames, state.Log, toto.DVs); Writer.Flush(); } // } }
private static void RecursiveSearch <Gb, M, T>(Gb[] gbs, DFParameters <Gb, M, T> parameters, DFState <M, T> state, HashSet <int> seenStates) where Gb : PokemonGame where M : Map <M, T> where T : Tile <M, T> { if (parameters.EndTiles != null && state.EdgeSet == parameters.EndEdgeSet && parameters.EndTiles.Any(t => t.X == state.Tile.X && t.Y == state.Tile.Y)) { if (parameters.FoundCallback != null) { parameters.FoundCallback(state); } } if (parameters.PruneAlreadySeenStates && !seenStates.Add(state.GetHashCode())) { return; } foreach (Edge <M, T> edge in state.Tile.Edges[state.EdgeSet]) { if (state.WastedFrames + edge.Cost > parameters.MaxCost) { continue; } if ((state.BlockedActions & edge.Action) > 0) { continue; } if (edge.Action == Action.A && state.APressCounter > 0) { continue; } IGTResults results = PokemonGame.IGTCheckParallel <Gb>(gbs, state.IGT, gb => gb.Execute(edge.Action) == gb.OverworldLoopAddress, parameters.NoEncounterSS); DFState <M, T> newState = new DFState <M, T>() { Tile = edge.NextTile, EdgeSet = edge.NextEdgeset, Log = state.Log + edge.Action.LogString() + " ", IGT = results, WastedFrames = state.WastedFrames + edge.Cost, }; int noEncounterSuccesses = results.TotalSuccesses; if (noEncounterSuccesses >= parameters.NoEncounterSS) { int rngSuccesses = results.RNGSuccesses(0x9); if (rngSuccesses >= parameters.RNGSS) { newState.APressCounter = edge.Action == Action.A ? 2 : Math.Max(state.APressCounter - 1, 0); Action blockedActions = state.BlockedActions; if ((edge.Action & Action.A) > 0) { blockedActions |= Action.A; } else { blockedActions &= ~(Action.A | Action.StartB); } newState.BlockedActions = blockedActions; RecursiveSearch(gbs, parameters, newState, seenStates); } } } }
public DFState Tick(double deltaMS) { currentState = states[CurrentState].Tick(deltaMS); return currentState; }
public DFState KeyUp(Keys key) { currentState = states[CurrentState].KeyUp(key); return currentState; }
private static void RecursiveSearch <Gb, T>(Gb[] gbs, DFParameters <Gb, T> parameters, DFState <T> state, HashSet <int> seenStates) where Gb : GameBoy where T : Tile <T> { if (parameters.EndTiles != null && state.EdgeSet == parameters.EndEdgeSet && parameters.EndTiles.Any(t => t.X == state.Tile.X && t.Y == state.Tile.Y)) { if (parameters.FoundCallback != null) { parameters.FoundCallback(state); } else { Console.WriteLine(state.Log); } } if (parameters.PruneAlreadySeenStates && !seenStates.Add(state.GetHashCode())) { return; } byte[][] states = state.IGT.States; foreach (Edge <T> edge in state.Tile.Edges[state.EdgeSet]) { if (state.WastedFrames + edge.Cost > parameters.MaxCost) { continue; } if ((state.BlockedActions & edge.Action) > 0) { continue; } IGTResults results = GameBoy.IGTCheckParallel <Gb>(gbs, states, gb => gb.Execute(edge.Action) == gb.OverworldLoopAddress, parameters.EncounterCallback == null ? parameters.NoEncounterSS : 0); DFState <T> newState = new DFState <T>() { Tile = edge.NextTile, EdgeSet = edge.NextEdgeset, Log = state.Log + edge.Action.LogString() + " ", IGT = results, WastedFrames = state.WastedFrames + edge.Cost, }; int noEncounterSuccesses = results.TotalSuccesses; if (parameters.EncounterCallback != null) { int encounterSuccesses = results.TotalFailures; for (int i = 0; i < results.NumIGTFrames && encounterSuccesses >= parameters.EncounterSS; i++) { gbs[0].LoadState(results.States[i]); if (parameters.EncounterCallback(gbs[0])) { encounterSuccesses++; } } if (encounterSuccesses >= parameters.EncounterSS) { if (parameters.FoundCallback != null) { parameters.FoundCallback(newState); } else { Console.WriteLine(state.Log); } } } if (noEncounterSuccesses >= parameters.NoEncounterSS) { Action blockedActions = state.BlockedActions; if (edge.Action == Action.A) { blockedActions |= Action.StartB; } if ((edge.Action & Action.A) > 0) { blockedActions |= Action.A; } else { blockedActions &= ~(Action.A | Action.StartB); } newState.BlockedActions = blockedActions; RecursiveSearch(gbs, parameters, newState, seenStates); } } }