private void insertGhostDanger(DangerMap dm) { foreach (PredictEntity pg in tempGhosts) { ripple(dm, pg.Node, 1.0f, 0); } }
private void insertGhostDanger(DangerMap dm) { foreach (PredictGhost pg in tempGhosts) { dm.Danger[pg.Node.X, pg.Node.Y] |= pg.Danger; } }
private void insertGhostDanger(DangerMap dm) { foreach (PredictEntity pg in ghosts) { //Console.WriteLine("Ghost: " + pg.Node); ripple(dm, pg.Node, 0.8f, 2); } }
public DangerMap(DangerMap dm) { Danger = new GhostDanger[Map.Width, Map.Height]; for (int x = 0; x < Map.Width; x++) { for (int y = 0; y < Map.Height; y++) { Danger[x, y] = dm.Danger[x, y]; } } }
private void insertGhostDanger(DangerMap dm) { foreach (PredictGhost pg in tempGhosts) { dm.Danger[pg.Node.X, pg.Node.Y] += pg.Danger; if (dm.Danger[pg.Node.X, pg.Node.Y] > 1.0f) { dm.Danger[pg.Node.X, pg.Node.Y] = 1.0f; } } }
public DangerMap(DangerMap dm) { Danger = new float[Map.Width, Map.Height]; for (int x = 0; x < Map.Width; x++) { for (int y = 0; y < Map.Height; y++) { Danger[x, y] = dm.Danger[x, y]; // / 2.0f; } } }
public DangerMap(DangerMap dm) { Danger = new float[Map.Width, Map.Height]; for (int x = 0; x < Map.Width; x++) { for (int y = 0; y < Map.Height; y++) { Danger[x, y] = dm.Danger[x, y] / iterationDevaluator; } } }
private void ripple(DangerMap dm, Node node, float danger, int size) { dm.Danger[node.X, node.Y] = danger; if (size == 0) { return; } ripple(dm, node.Up, danger / rippleDevaluator, size - 1); ripple(dm, node.Down, danger / rippleDevaluator, size - 1); ripple(dm, node.Left, danger / rippleDevaluator, size - 1); ripple(dm, node.Right, danger / rippleDevaluator, size - 1); }
private void run() { // generate danger maps insertGhostDanger(dangerMaps[0]); for (int i = 1; i < dangerMaps.Length; i++) { dangerMaps[i] = new DangerMap(dangerMaps[i - 1]); updateGhosts(); insertGhostDanger(dangerMaps[i]); Console.WriteLine(i + ": " + dangerMaps[i].Danger[13, 23]); //Console.WriteLine(i + ": " + dangerMaps[i].Danger[gs.Pacman.Node.X, gs.Pacman.Node.Y]); } }
private void run() { // generate danger maps insertGhostDanger(dangerMaps[0]); for (int i = 1; i < dangerMaps.Length; i++) { dangerMaps[i] = new DangerMap(dangerMaps[i - 1]); updateGhosts(); insertGhostDanger(dangerMaps[i]); //Console.WriteLine(i + ": " + dangerMaps[i].Danger[13, 23]); } // calculate direction dangers runPac(Direction.Up, gs.Pacman.Node.Up); runPac(Direction.Down, gs.Pacman.Node.Down); runPac(Direction.Left, gs.Pacman.Node.Left); runPac(Direction.Right, gs.Pacman.Node.Right); Console.WriteLine("------------------"); Console.WriteLine(PacDanger[0] + ", " + PacDanger[1] + ", " + PacDanger[2] + ", " + PacDanger[3]); //Console.WriteLine(PacDangerLimit[0] + ", " + PacDangerLimit[1] + ", " + PacDangerLimit[2] + ", " + PacDangerLimit[3]); }
public PredictionOld(GameState gs, int iterations) { if (iterations < 1) { throw new ApplicationException("At least one iteration must be predicted"); } this.Iterations = iterations; this.gs = gs; ghosts = new List <PredictEntity>(4); curGhosts = new List <PredictEntity>(4); foreach (Ghosts.Ghost ghost in gs.Ghosts) { //if( ghost == gs.Red ) //if( ghost.Chasing || ghost.RemainingFlee < 200 ) { ghosts.Add(new PredictEntity(ghost, gs)); curGhosts.Add(new PredictEntity(ghost, gs)); //} } dangerMaps = new DangerMap[iterations + 1]; dangerMaps[0] = new DangerMap(gs); run(); }
public PredictionOld3(GameState gs, int iterations) { this.gs = gs; this.Iterations = iterations; ghosts = new List <PredictGhost>(4); tempGhosts = new List <PredictGhost>(4); foreach (Ghosts.Ghost ghost in gs.Ghosts) { /*ghost.Enabled = false; * if( ghost == gs.Red ){ * ghost.Enabled = true;*/ if (ghost.Chasing || ghost.RemainingFlee < 200) { ghosts.Add(new PredictGhost(ghost, gs)); tempGhosts.Add(new PredictGhost(ghost, gs)); } } dangerMaps = new DangerMap[iterations + 1]; dangerMaps[0] = new DangerMap(); run(); //Console.WriteLine("ghosts: " + tempGhosts.Count); }
private void run() { // generate danger maps insertGhostDanger(dangerMaps[0]); for (int i = 1; i < dangerMaps.Length; i++) { dangerMaps[i] = new DangerMap(gs); updateGhosts(); insertGhostDanger(dangerMaps[i]); //Console.WriteLine(i + ": " + dangerMaps[i].Danger[13, 23]); //Console.WriteLine(i + ": " + dangerMaps[i].Danger[gs.Pacman.Node.X, gs.Pacman.Node.Y]); } // calculate danger for pacman PossibleDirections = new List <Direction>(); foreach (Node node in gs.Pacman.Node.PossibleDirections) { PossibleDirections.Add(gs.Pacman.Node.GetDirection(node)); } // eliminate directions where ghosts close for (int i = 1; i < 2; i++) { foreach (PredictGhost ghost in ghosts) { if (!ghost.Chasing) { continue; } Node.PathInfo shortestPath = gs.Pacman.Node.ShortestPath[ghost.Node.X, ghost.Node.Y]; if (shortestPath != null) { if (i == 1) { //Console.WriteLine("shortest: " + shortestPath.Direction + " @ " + shortestPath.Distance + " : " + ghost.Node); } if (shortestPath.Distance < i) { // remove PossibleDirections.Remove(shortestPath.Direction); if (PossibleDirections.Count == 1) { if (debug) { Console.WriteLine(":: Close danger decision: " + PossibleDirections[0]); } goto OneDirectionLeft; } } } else if (gs.Pacman.Node == ghost.Node) { List <Direction> newPossibles = new List <Direction>(); foreach (Direction d in PossibleDirections) { newPossibles.Add(d); } newPossibles.Remove(StateInfo.GetInverse(ghost.Direction)); if (newPossibles.Count == 1) { PossibleDirections = newPossibles; if (debug) { Console.WriteLine(":: Extreme danger decision: " + PossibleDirections[0]); } goto OneDirectionLeft; } } } } // circular run ... for (int i = 3; i < 10; i++) { int result; if (i < 6) { result = circularTest(i, i - 2); } else { result = circularTest(i, i); } if (result == 0) { break; } // warp hack if (gs.Map.Tunnels[gs.Pacman.Node.Y]) { if (gs.Pacman.Node.X < 2 || gs.Pacman.Node.X > Map.Width - 3) { PossibleDirections.Remove(Direction.Left); PossibleDirections.Remove(Direction.Right); PossibleDirections.Add(Direction.Left); PossibleDirections.Add(Direction.Right); } } if (PossibleDirections.Count == 1) { if (debug) { Console.WriteLine(":: Circular test decision: " + PossibleDirections[0]); } goto OneDirectionLeft; } } /* * // try and predict safe route * List<Direction> Safe = new List<Direction>(); * List<UnsafeDirection> Unsafe = new List<UnsafeDirection>(); * foreach( Direction d in PossibleDirections ) { * int result = evasionPac(d); * Console.WriteLine(d + ": " + result); * if( result >= Iterations ) { * Safe.Add(d); * } else { * Unsafe.Add(new UnsafeDirection(d,result)); * } * } * if( Safe.Count > 0 ) { * PossibleDirections = Safe; * } else{ * Unsafe.Sort(new Comparison<UnsafeDirection>(delegate(UnsafeDirection u1, UnsafeDirection u2){ * if( u1.Safety == u2.Safety ) return 0; * if( u1.Safety > u2.Safety ) return -1; * return 1; * })); * foreach( UnsafeDirection u in Unsafe ) { * Console.WriteLine(" - " + u.Direction + ": " + u.Safety); * } * PossibleDirections = new List<Direction>(); * int best = Unsafe[0].Safety; * foreach( UnsafeDirection u in Unsafe ) { * if( u.Safety == best ) { * PossibleDirections.Add(Unsafe[0].Direction); * } * } * } * if( PossibleDirections.Count == 1 ) { * Console.WriteLine(":: Unsafe decision: " + PossibleDirections[0]); * } */ // finished OneDirectionLeft: //Console.WriteLine("------------------"); return; }