public PodRacerCommand EvaluateCommand(Race race) { PodRacerCommand command; command = new PodRacerCommand() { Thrust = 100, Destination = race. RaceState. PodRacerRaceStates[PodRacer]. CurrentCheckPoint. Position }; return(command); }
public PodRacerCommand EvaluateCommand(Race race) { PodRacerCommand command; //command = new PodRacerCommand() //{ // Thrust = 100, // Destination = new Vector(0,0) //}; CheckPoint currentCheckPoint = race. RaceState. PodRacerRaceStates[PodRacer]. CurrentCheckPoint; //inHeading.SetInput(PodRacer.Heading / 360); //inVelocityAngle.SetInput(PodRacer.Velocity.GetAngle() / 360); //inVelocityLength.SetInput(Math.Min(PodRacer.Velocity.Length, 1000) / 1000); Vector toCurrentCheckpoint = PodRacer.Position - currentCheckPoint.Position; double distanceToCurrentCheckPoint = toCurrentCheckpoint.Length; if (distanceToCurrentCheckPoint < 500) { inNextCheckpointDistance0.SetInput(1); } else { inNextCheckpointDistance0.SetInput(-1); } if (distanceToCurrentCheckPoint < 1500) { inNextCheckpointDistance1.SetInput(1); } else { inNextCheckpointDistance1.SetInput(-1); } if (distanceToCurrentCheckPoint < 3000) { inNextCheckpointDistance2.SetInput(1); } else { inNextCheckpointDistance2.SetInput(-1); } if (distanceToCurrentCheckPoint < 10000) { inNextCheckpointDistance3.SetInput(1); } else { inNextCheckpointDistance3.SetInput(-1); } int angle; angle = (int)Math.Round(PodRacer.Orientation.GetAngle(toCurrentCheckpoint)); if (angle < -18) { angle = -18; } if (angle > 18) { angle = 18; } angle = angle + 18; if ((angle & 1) == 1) { inNextCheckpointAngle0.SetInput(1); } else { inNextCheckpointAngle0.SetInput(-1); } if ((angle & 2) == 2) { inNextCheckpointAngle1.SetInput(1); } else { inNextCheckpointAngle1.SetInput(-1); } if ((angle & 4) == 4) { inNextCheckpointAngle2.SetInput(1); } else { inNextCheckpointAngle2.SetInput(-1); } if ((angle & 8) == 8) { inNextCheckpointAngle3.SetInput(1); } else { inNextCheckpointAngle3.SetInput(-1); } if ((angle & 16) == 16) { inNextCheckpointAngle4.SetInput(1); } else { inNextCheckpointAngle4.SetInput(-1); } if ((angle & 32) == 32) { inNextCheckpointAngle5.SetInput(1); } else { inNextCheckpointAngle5.SetInput(-1); } Vector toCurrentNextCheckpoint = PodRacer.Position - race.Arena.GetNextCheckPoint(currentCheckPoint).Position; angle = (int)Math.Round(PodRacer.Orientation.GetAngle(toCurrentNextCheckpoint)); if (angle < -18) { angle = -18; } if (angle > 18) { angle = 18; } angle = angle + 18; if ((angle & 1) == 1) { inNextNextCheckpointAngle0.SetInput(1); } else { inNextNextCheckpointAngle0.SetInput(-1); } if ((angle & 2) == 2) { inNextNextCheckpointAngle1.SetInput(1); } else { inNextNextCheckpointAngle1.SetInput(-1); } if ((angle & 4) == 4) { inNextNextCheckpointAngle2.SetInput(1); } else { inNextNextCheckpointAngle2.SetInput(-1); } if ((angle & 8) == 8) { inNextNextCheckpointAngle3.SetInput(1); } else { inNextNextCheckpointAngle3.SetInput(-1); } if ((angle & 16) == 16) { inNextNextCheckpointAngle4.SetInput(1); } else { inNextNextCheckpointAngle4.SetInput(-1); } if ((angle & 32) == 32) { inNextNextCheckpointAngle5.SetInput(1); } else { inNextNextCheckpointAngle5.SetInput(-1); } //inNextCheckpointDistance.SetInput(Math.Min(toCurrentCheckpoint.Length, 100000) / 100000); nn.UpdateOutput(); //List<Heading> headings = new List<Heading>(); //headings.Add(new Heading() { HeadingValue = outHeading0.Output, Angle = 0 }); //headings.Add(new Heading() { HeadingValue = outHeading1.Output, Angle = -9 }); //headings.Add(new Heading() { HeadingValue = outHeading2.Output, Angle = -18 }); //headings.Add(new Heading() { HeadingValue = outHeading3.Output, Angle = 9 }); //headings.Add(new Heading() { HeadingValue = outHeading4.Output, Angle = 18 }); //List<Heading> sorted = headings.OrderBy(h => h.HeadingValue).ToList(); double heading = 0; if (outHeading0.Output >= 0.5) { heading += 1; } if (outHeading1.Output >= 0.5) { heading += 2; } if (outHeading2.Output >= 0.5) { heading += 4; } if (outHeading3.Output >= 0.5) { heading += 8; } if (outHeading4.Output >= 0.5) { heading += 16; } if (outHeading5.Output >= 0.5) { heading += 32; } heading = heading / 63.0 * 36.0 - 18.0; //heading = sorted.First().Angle; double thrust = 0; if (outThrust0.Output >= 0.5) { thrust += 1; } if (outThrust1.Output >= 0.5) { thrust += 2; } if (outThrust2.Output >= 0.5) { thrust += 4; } if (outThrust3.Output >= 0.5) { thrust += 8; } if (outThrust4.Output >= 0.5) { thrust += 16; } if (outThrust5.Output >= 0.5) { thrust += 32; } if (outThrust6.Output >= 0.5) { thrust += 64; } thrust = thrust / 127.0 * 100.0; Vector destination = 1600 * PodRacer.Orientation; destination = PodRacer.Position + destination.Rotate(heading); command = new PodRacerCommand() { Thrust = (int)(thrust), Destination = destination }; //command = new PodRacerCommand() //{ // Thrust = random.Next(0, 10), // Destination = race. // RaceState. // PodRacerRaceStates[PodRacer]. // CurrentCheckPoint. // Position //}; return(command); }