private void ActivateThruster(ParticleSystem particleSystem, AudioSource sound, ref float speedToAdjust, float accelerationVal, float maxSpeedVal) { // TODO play Sound float fuel = Lander.GetInstance().GetFuel(); if (fuel > 0) { if (!sound.isPlaying) { sound.Play(); } if (!particleSystem.isPlaying) { particleSystem.Play(); } speedToAdjust += accelerationVal * Time.deltaTime; if (speedToAdjust > maxSpeedVal) { speedToAdjust = maxSpeedVal; } Lander.GetInstance().ReduceFuel(speedToAdjust); } else { DisableThruster(particleSystem, sound, ref speedToAdjust); } }
/// <summary> /// The main entry point for the application. /// </summary> private static void Main(string[] args) { using (var game = new Lander()) { game.Run(); } }
public IEnumerator LandedOnPlatform(GameObject landingPad, float distanceToCenter, float maxFuelRestore) { if (landingPad.Equals(lastLandingPad)) { Debug.Log("Feet on the Ground: " + amountOfFeet + " ... you get Points and Fuel! Dist: " + distanceToCenter.ToString()); bool perfectLanding = amountOfFeet == 4; int multiplier = amountOfFeet; /*if(perfectLanding){ * // TODO perfect landing * Debug.Log("Perfect Landing"); * SetMessageLabelText("Perfect Landing", 1f); * yield return new WaitForSeconds(1f); * }*/ LandingPlatform platformScript = landingPad.GetComponent <LandingPlatform>(); float points = platformScript.scorePoints - distanceToCenter - impact; int bonusMultiplier = platformScript.multiply; int score = ((int)(points + 0.5f)) * (multiplier + bonusMultiplier); string scoreText = (perfectLanding ? "Perfect Landing\n" : "") + (multiplier + bonusMultiplier).ToString() + " x " + ((int)(score / (multiplier + bonusMultiplier))).ToString(); SetMessageLabelText(scoreText, 24, 2f); yield return(new WaitForSeconds(2f)); currentLevelScore += score; // TODO Score textlabel aufblitzen lassen float bonusFuel = (maxFuelRestore * multiplier) - distanceToCenter; Lander.GetInstance().AddFuel(bonusFuel / 3); Debug.Log("Added Fuel"); if (GetRemainingLandingPads() == 0) { yield return(StartCoroutine(EndLevel())); } } }
// Use this for initialization void Start() { if (scalingOverlays.Length < scalings.Length) { Debug.LogError ("Lengths of overlays and scalings have to match!!!"); } lander = referencedGameObject.GetComponent<Lander>(); }
/// <summary>Getting the distance from the surface directly under the lander.</summary> public double GetDistanceFromSurface(Lander lander) { if (lander.Situation.X < 0 || lander.Situation.X > MarsLanderRules.Width) { return(double.MaxValue); } return(lander.Situation.Y - _surfaceElements[(int)Math.Round(lander.Situation.X)].Y); }
void Start() { playerLander = GameObject.Find("Lander").GetComponent <Lander>(); if (playerLander == null) { Debug.LogError("Cannot find Lander gameobject. Make sure your Lander is named Lander."); } }
// Use this for initialization void Start() { if (scalingOverlays.Length < scalings.Length) { Debug.LogError("Lengths of overlays and scalings have to match!!!"); } lander = referencedGameObject.GetComponent <Lander>(); }
void FixedUpdate() { if (Lander.GetInstance().isStarted()) { direction = jetBone.transform.right; //Debug.Log("Fly to: " + direction.ToString()); if (speed > 0) { if (transform.position.y >= maxHeight) { direction.y = 0; } //rigidbody.AddForceAtPosition(direction * speed * Time.fixedDeltaTime, mainThruster.transform.position); rigidbody.AddForce(direction * speed * Time.fixedDeltaTime); } if (frontThrusterSpeed > 0) { //Debug.Log ("Backthruster angle " + finalAngleForward); float speedRot = frontThrusterSpeed * Time.fixedDeltaTime; Vector3 force = frontThruster.transform.forward * speedRot * -1; rigidbody.AddForceAtPosition(force, frontThruster.transform.position); } if (backThrusterSpeed > 0) { //Debug.Log ("Frontthruster angle: " + finalAngleForward); float speedRot = backThrusterSpeed * Time.fixedDeltaTime; Vector3 force = backThruster.transform.forward * speedRot * -1; //rigidbody.AddRelativeTorque (torque); rigidbody.AddForceAtPosition(force, backThruster.transform.position); } if (rightThrusterSpeed > 0) { //Debug.Log ("Rightthruster angle: " + finalAngleRight); float speedRot = rightThrusterSpeed * Time.fixedDeltaTime; Vector3 force = rightThruster.transform.forward * speedRot * -1; //rigidbody.AddRelativeTorque (torque); rigidbody.AddForceAtPosition(force, rightThruster.transform.position); } if (leftThrusterSpeed > 0) { //Debug.Log ("Leftthruster angle: " + finalAngleRight); float speedRot = leftThrusterSpeed * Time.fixedDeltaTime; Vector3 force = leftThruster.transform.forward * speedRot * -1; //rigidbody.AddRelativeTorque (torque); rigidbody.AddForceAtPosition(force, leftThruster.transform.position); } if (topThrusterSpeed > 0) { //Debug.Log ("Leftthruster angle: " + finalAngleRight); float speedRot = topThrusterSpeed * Time.fixedDeltaTime; Vector3 force = topThruster.transform.forward * speedRot * -1; //rigidbody.AddRelativeTorque (torque); rigidbody.AddForce(force); } } }
private void GenerateActors(int count, Lander original) { Actors = new List <MarsLanderActor>(); for (var i = 0; i < count; i++) { Actors.Add(new MarsLanderActor(original, _environment)); } }
public void ApplyFullRangeRandomActions(RandomNessProvider randomNessProvider) { while (Lander.Status == LanderStatus.Flying) { var randomAngle = randomNessProvider.GetRandomAngle(); var randomPower = randomNessProvider.GetRandomPower(); Lander.Apply(randomAngle, randomPower, _environment); } }
// Use this for initialization void Start() { Camera cam = cameras [currentCamera]; cam.enabled = true; cam.gameObject.GetComponent <AudioListener> ().enabled = true; instance = this; rigidbody.useGravity = false; controller = gameObject.GetComponent <LanderWiiMote> (); this.started = false; }
public void ApplyActions(IEnumerable <string> actions) { foreach (var actionArray in actions.Select(action => action.Split(" "))) { if (Lander.Status != LanderStatus.Flying) { continue; } Lander.Apply(int.Parse(actionArray[0]), int.Parse(actionArray[1]), _environment); } }
public Distance GetDistanceFromFlatSurface(Lander lander) { if (_landingZone == null) { SetLandingZone(); } var side = Side.Above; if (lander.Situation.X < _landingZone.LeftX) { side = Side.Left; } if (lander.Situation.X > _landingZone.RightX) { side = Side.Right; } var horizontalDistance = 0.0; var fullDistance = 0.0; if (side == Side.Left) { horizontalDistance = _landingZone.LeftX - lander.Situation.X; fullDistance = Trigonometry.GetDistance( new Point(_landingZone.LeftX, _landingZone.LeftY), new Point(lander.Situation.X, lander.Situation.Y)); } if (side == Side.Right) { horizontalDistance = _landingZone.RightX - lander.Situation.X; fullDistance = Trigonometry.GetDistance( new Point(_landingZone.RightX, _landingZone.RightY), new Point(lander.Situation.X, lander.Situation.Y)); } if (side == Side.Above) { fullDistance = Trigonometry.GetDistance( new Point(lander.Situation.X, // We are above, so we do not need to move to the left or right. _landingZone.LeftY), // Y is the same everywhere in the landing zone. new Point(lander.Situation.X, lander.Situation.Y)); } return(new Distance { HorizontalDistance = horizontalDistance, VerticalDistance = lander.Situation.Y - _landingZone.LeftY, // Y is the same everywhere in the landing zone. FullDistance = fullDistance }); }
/// <summary> /// <para>Search for a grid.</para> /// The search happens when the action is executed. /// When action is executed, an error may occur and instructionErrorIndex will be updated. /// </summary> private bool getAction_gridDest(out Action execute, string instruction) { myLogger.debugLog("entered getAction_gridDest(out Action execute, string " + instruction + ")", "getAction_gridDest()"); //string searchName = owner.CNS.tempBlockName; //myLogger.debugLog("searchName = " + searchName + ", owner.CNS.tempBlockName = " + owner.CNS.tempBlockName, "getAction_gridDest()"); //owner.CNS.tempBlockName = null; int myInstructionIndex = currentInstruction; execute = () => { IMyCubeBlock blockBestMatch; LastSeen gridBestMatch; myLogger.debugLog("calling lastSeenFriendly with (" + instruction + ", " + owner.CNS.tempBlockName + ")", "getAction_gridDest()"); if (owner.myTargeter.lastSeenFriendly(instruction, out gridBestMatch, out blockBestMatch, owner.CNS.tempBlockName)) { Base6Directions.Direction?landDir = null; if ((blockBestMatch != null && owner.CNS.landLocalBlock != null && owner.CNS.landDirection == null) && !Lander.landingDirection(blockBestMatch, out landDir)) { log("could not get landing direction from block: " + owner.CNS.landLocalBlock.DefinitionDisplayNameText, "getAction_gridDest()", Logger.severity.INFO); instructionErrorIndex_add(myInstructionIndex); return; } if (landDir != null) // got a landing direction { owner.CNS.landDirection = landDir; myLogger.debugLog("got landing direction of " + landDir + " from " + owner.CNS.landLocalBlock.DefinitionDisplayNameText, "getAction_gridDest()"); log("set land offset to " + owner.CNS.landOffset, "getAction_gridDest()", Logger.severity.TRACE); } else // no landing direction { if (blockBestMatch != null) { myLogger.debugLog("setting centreDestination to " + gridBestMatch.Entity.getBestName() + ", " + blockBestMatch.DisplayNameText + " seen by " + owner.currentRCblock.getNameOnly(), "getAction_gridDest()"); } else { myLogger.debugLog("setting centreDestination to " + gridBestMatch.Entity.getBestName() + " seen by " + owner.currentRCblock.getNameOnly(), "getAction_gridDest()"); } } owner.CNS.setDestination(gridBestMatch, blockBestMatch, owner.currentRCblock); return; } // did not find grid log("did not find a friendly grid", "getAction_gridDest()", Logger.severity.TRACE); instructionErrorIndex_add(myInstructionIndex); }; return(true); }
public SurfaceZone GetCurrentSurface(Lander lander) { if (lander.Situation.X < 0) { return(null); } if (lander.Situation.X > MarsLanderRules.Width) { return(null); } return(_surfaceZones .LastOrDefault(element => element.LeftX <= lander.Situation.X && element.RightX > lander.Situation.X)); }
private IEnumerator EndLevel() { this.currentLevelScore += (int)((finishScore + timeToBeat + Lander.GetInstance().GetFuel()) + 0.5f); //this.currentLevelScore += (int)( + 0.5f); TheBrain.GetInstance().ApplyCurrentScore(currentLevelScore); SetMessageLabelText("Well done ...", 48, 3); yield return(new WaitForSeconds(3)); // TODO vernünftiges Verhalten für das Beenden eines Levels SetGameOver(); }
/// <summary>Getting distance from the surface directly under the lander, but we don't need to find the surface /// elements under the lander.</summary> public static int GetDistanceFromSurface(Lander lander, SurfaceZone leftZone, SurfaceZone rightZone) { if (rightZone == null || leftZone == null) { return(int.MaxValue); } var zoneAngle = Trigonometry .GetAngle(new Point(leftZone.LeftX, leftZone.LeftY), new Point(rightZone.LeftX, rightZone.LeftY)); var landerXInZone = lander.Situation.X - leftZone.LeftX; var surfaceYPosition = leftZone.LeftY + Math.Round(Trigonometry.GetNewYPosition(zoneAngle, landerXInZone)); return((int)Math.Round(lander.Situation.Y - surfaceYPosition)); }
public override void LoadContent() { lander = new Lander(StateManager.game); lander.Initialize(); VectorFont.Initialize(StateManager.game); terrain = new Terrain(StateManager.game); terrain.TerrainName = terrainFileName; terrain.Initialize(); sentScore = false; win = StateManager.Content.Load <SoundEffect>("LanderVictorySound"); lose = StateManager.Content.Load <SoundEffect>("LanderExplosionSound"); bgColor = Color.Black; oldKeyboardState = Keyboard.GetState(); }
public PlayScreen() { terrain = new Terrain(); soundEffects = new List <SoundEffect>(); pb = new PrimitiveBatch(StateManager.graphicsDevice); lander = new Lander(StateManager.game); //Components.Add(lander); terrain.GenerateTerrain(); terrain.GeneratePads(); elapsedTime = TimeSpan.Zero; fuelWord = new Font("FUEL 000", 5); LoadContent(); }
public void GetPosition(string consoleText) { var splitText = consoleText.Split(' '); if (splitText.Length > 6) { this.Lander = new Lander(); this.Lander.Position = new Point(int.Parse(splitText[0]), int.Parse(splitText[1])); this.Lander.HorizontalSpeed = int.Parse(splitText[2]); this.Lander.VerticalSpeed = int.Parse(splitText[3]); this.Lander.Fuel = int.Parse(splitText[4]); this.Lander.Angle = int.Parse(splitText[5]); this.Lander.Power = int.Parse(splitText[6]); } }
public Distance GetDistanceFromFlatSurfaceCenter(Lander lander) { if (_landingZone == null) { SetLandingZone(); } return(new Distance { HorizontalDistance = Math.Abs(lander.Situation.X - _centerLandingZoneX), VerticalDistance = Math.Abs(lander.Situation.Y - _landingZone.LeftY), FullDistance = Trigonometry.GetDistance( new Point(_centerLandingZoneX, _landingZone.LeftY), new Point(lander.Situation.X, lander.Situation.Y)) }); }
public override void LoadContent() { StateManager.game.Window.Title = "Lunar Lander"; pb = GlobalValues.PrimitiveBatch; #region Lander Calls lander = new Lander(StateManager.game); lander.Initialize(); if (isFirstLoad) { ResetValues(); isFirstLoad = false; } #endregion }
void Awake() { instance = this; generation = 1; timer = 0.0f; landerPos = new Vector3(Random.Range(-16, 17), 0, Random.Range(10, 16)); for (int i = 0; i < lunarsNum; i++) { GameObject obj = Instantiate(landerPrefab, landerPos, Quaternion.Euler(90, 0, 0)); Lander lan = obj.GetComponent <Lander>(); lan.SetBrain(inputs, outputs, numHiddenLayers, numNeuronPerHiddenLayer, bias, sigmoidPending); lan.SetLimits(maxHeight, maxWidth); if (i == 0) { ga = new GeneticAlg(elitesNum, lunarsNum, lan.GetNumberOfWeights(), mutation); } landers.Add(lan); } plataform = Instantiate(plataformPrefab, new Vector3(Random.Range(-17, 18), 0, Random.Range(-15, -9)), Quaternion.Euler(90, 0, 0)); }
static void Main(string[] args) { string[] inputs; List <Point> pointsList = new List <Point>(); int surfaceN = int.Parse(Console.ReadLine()); // the number of points used to draw the surface of Mars. for (int i = 0; i < surfaceN; i++) { inputs = Console.ReadLine().Split(' '); int landX = int.Parse(inputs[0]); // X coordinate of a surface point. (0 to 6999) int landY = int.Parse(inputs[1]); // Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars. pointsList.Add(new Point(landX, landY)); } foreach (Point p in pointsList) { Console.Error.WriteLine("{0}, {1}", p.X, p.Y); } Lander lander = new Lander(); // game loop while (true) { inputs = Console.ReadLine().Split(' '); int X = int.Parse(inputs[0]); int Y = int.Parse(inputs[1]); int hSpeed = int.Parse(inputs[2]); // the horizontal speed (in m/s), can be negative. int vSpeed = int.Parse(inputs[3]); // the vertical speed (in m/s), can be negative. int fuel = int.Parse(inputs[4]); // the quantity of remaining fuel in liters. int rotate = int.Parse(inputs[5]); // the rotation angle in degrees (-90 to 90). int power = int.Parse(inputs[6]); // the thrust power (0 to 4). lander.update(X, Y, hSpeed, vSpeed, fuel, rotate, power); // Write an action using Console.WriteLine() // To debug: Console.Error.WriteLine("Debug messages..."); // 2 integers: rotate power. rotate is the desired rotation angle (should be 0 for level 1), power is the desired thrust power (0 to 4). //Console.WriteLine("0 3"); } }
public bool LanderCrashedThroughGround(Lander lander) { var previousSituation = lander.Situations .LastOrDefault(situation => Math.Abs(situation.X - lander.Situation.X) > 0.001 && Math.Abs(situation.Y - lander.Situation.Y) > 0.001); if (previousSituation == null) { return(false); } var enteredZones = _surfaceZones .Where(zone => zone.LeftX <= previousSituation.X && zone.RightX > previousSituation.X || zone.LeftX <= lander.Situation.X && zone.RightX > lander.Situation.X) .ToList(); foreach (var enteredZone in enteredZones) { if (enteredZone.LeftY < lander.Situation.Y && enteredZone.LeftY < previousSituation.Y && enteredZone.RightY < lander.Situation.Y && enteredZone.RightY < previousSituation.Y) { continue; } var landerVector = new Vector( new Point(previousSituation.X, previousSituation.Y), new Point(lander.Situation.X, lander.Situation.Y)); var zoneVector = new Vector( enteredZone.LeftX, enteredZone.LeftY, enteredZone.RightX, enteredZone.RightY); if (Trigonometry.GetIntersection(landerVector, zoneVector).IntersectionType != IntersectionType.None) { return(true); } } return(false); }
private List <Generation> GetBestLanding(LandRequest landRequest) { var environment = new MarsLanderEnvironment(landRequest.Map.SurfaceZones.ToList()); var lander = new Lander { Situation = new Situation { Fuel = landRequest.Map.InitialFuel, Power = landRequest.Map.InitialPower, Rotation = landRequest.Map.InitialRotation, X = landRequest.Map.InitialX, Y = landRequest.Map.InitialY, HorizontalSpeed = landRequest.Map.InitialHorizontalSpeed, VerticalSpeed = landRequest.Map.InitialVerticalSpeed } }; var evolution = new MarsLanderEvolution(environment, landRequest.AiWeight); if (landRequest.Parameters.Actions != null) { evolution.MaxActions = landRequest.Parameters.Actions <= 0 ? null : landRequest.Parameters.Actions; } var sw = Stopwatch.StartNew(); evolution.Run(landRequest.Parameters.Generations, landRequest.Parameters.Population, lander); sw.Stop(); var highestScore = evolution.Generations .SelectMany(generation => generation.Actors) .Select(actor => actor.Score) .OrderBy(score => score) .First(); _logger.LogInformation("{elapsed}", sw.Elapsed); _logger.LogInformation("Highest Score: {@score}", highestScore); return(evolution.Generations); }
private static void Main(string[] args) { string[] inputs; int surfaceN = int.Parse(Console.ReadLine()); // the number of points used to draw the surface of Mars. for (int i = 0; i < surfaceN; i++) { inputs = Console.ReadLine().Split(' '); int landX = int.Parse(inputs[0]); // X coordinate of a surface point. (0 to 6999) int landY = int.Parse(inputs[1]); // Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars. map.Add(new Point(landX, landY)); } double maxDistance = 0; //find landing zone for (int i = 0; i < surfaceN - 1; i++) { if (map[i].Y == map[i + 1].Y) //flat { var distance = map[i].Distance(map[i + 1]); if (distance > maxDistance) { landingZone[0] = map[i]; landingZone[1] = map[i + 1]; maxDistance = distance; } } } landingZoneCenter = new Point((landingZone[1].X - landingZone[0].X) * 0.5 + landingZone[0].X, landingZone[0].Y); Console.Error.WriteLine("Zone: {0}, {1}: {2}", landingZone[0], landingZone[1], landingZoneCenter); Lander lander = new Lander(0, 0); int t = -1; // game loop while (true) { t++; inputs = Console.ReadLine().Split(' '); int X = int.Parse(inputs[0]); int Y = int.Parse(inputs[1]); int hSpeed = int.Parse(inputs[2]); // the horizontal speed (in m/s), can be negative. int vSpeed = int.Parse(inputs[3]); // the vertical speed (in m/s), can be negative. int fuel = int.Parse(inputs[4]); // the quantity of remaining fuel in liters. int rotate = int.Parse(inputs[5]); // the rotation angle in degrees (-90 to 90). int power = int.Parse(inputs[6]); // the thrust power (0 to 4). if (t == 0) { initFuel = fuel; } lander.X = X; lander.Y = Y; lander.HorizontalVelocity = hSpeed; lander.VerticalVelocity = vSpeed; lander.Fuel = fuel; lander.Rotation = rotate; lander.Power = power; lander.Save(); stopwatch = Stopwatch.StartNew(); //lander.Solve(140, t > 0); lander.Solve(140, t > 0); //if (t == 0) //{ //Console.Error.WriteLine("Lander: {0} {1} {2} {3}", X, Y, rotate, power); //Console.Error.WriteLine("Solution: {0}\n{1}\nScore:{2}", string.Join(",", lander.sol.angles), string.Join(",", lander.sol.thrust), lander.sol.score); //for (int i = 0; i < Depth; i++) //{ // if (lander.CheckCollisions()) // { // Console.Error.WriteLine("Col"); // break; // } // lander.Move(lander.sol.angles[i], lander.sol.thrust[i]); // Console.Error.WriteLine("Lander Pos: {0} {1} V: {2} {3}", Math.Round(lander.X), Math.Round(lander.Y), Math.Round(lander.HorizontalVelocity), Math.Round(lander.VerticalVelocity)); //} Console.WriteLine((int)lander.sol.angles[0] + " " + lander.sol.thrust[0]); //for (int i = 0; i < lander.sol.Time; i++) //{ // lander.sol.angles[i] = Math.Max(-90, Math.Min(lander.sol.angles[i], 90)); // lander.sol.thrust[i] = Math.Max(0, Math.Min(lander.sol.thrust[i], 4)); // Console.WriteLine((int)lander.sol.angles[i] + " " + lander.sol.thrust[i]); //} //} Console.Error.WriteLine("Score:{0} {1}", lander.sol.score, lander.sol.Time); Console.Error.WriteLine("Speed {0} {1}", lander.VerticalVelocity, lander.HorizontalVelocity); if (t > 0) { Console.Error.WriteLine("Avg Sols: {0}, Avg Sims: {1}", solutionsTried / 1, solutionsTried * Depth / t); } //Console.WriteLine((int)lander.sol.angles[0] + " " + lander.sol.thrust[0]); /* * if (lander.X < landingZone[0].X) * { * //go right * if (lander.HorizontalVelocity < MaxHorizontalSpeed) * { * lander.Rotation = -21.9; * } * var distanceToDest = landingZone[0].X - lander.X; * * lander.Power = 4; * } * else if (lander.X > landingZone[1].X) * { * //go left * if (lander.HorizontalVelocity > -MaxHorizontalSpeed) * { * lander.Rotation = 21.9; * } * lander.Power = 4; * } * else * { * //zero out horizontal velocity * var deltaRot = lander.HorizontalVelocity; * var error = 5; * if (deltaRot < 0) * { * lander.Rotation *= 0.50; * } * else if (deltaRot > 0) * { * lander.Rotation *= 0.50; * } * * if (vSpeed < -40 && power < 4) * { * lander.Power += 1; * } * } * * // 2 integers: rotate power. rotate is the desired rotation angle, power is the * // desired thrust power (0 to 4). * lander.Rotation = Math.Max(-90, Math.Min(90, (int)lander.Rotation)); * Console.WriteLine(lander.Rotation + " " + lander.Power); * copy.Move(lander.Rotation, (int)lander.Power); * Console.Error.WriteLine("Lander (SIM): {0} {1} {2} {3}", copy.X, copy.Y, copy.Rotation, copy.Power); * */ } }
// Use this for initialization void Start() { lander = landerObj.GetComponent <Lander>(); RocketSource.clip = LanderStart; }
/// <summary> /// Updates the Fitness property by running a landing simulation. /// TODO implement running multiple simulations for varying environments. /// </summary> public void CalculateFitness() { List<double> inputs = new List<double>(); Model.Environment environment = new Model.Environment(); Lander lander = new Lander(environment, this.settings.StartingFuel, this.settings.StartingHorizontal, this.settings.StartingHeight); IList<double> output; for (int i = 0; i < 7; i++) { inputs.Add(0); } this.Fitness = 0; //for (double varWind = -1.0; varWind < 1.0; varWind += 0.1) //{ // this.settings.LanderEnvironment.WindSpeed = varWind; // lander.Enviroment.WindSpeed = varWind; for (double varGravity = 1; varGravity < 3; varGravity += 0.5) { //this.settings.LanderEnvironment.Gravity = varGravity; lander.Enviroment.Gravity = varGravity; lander.Reset(); do { inputs[0] = lander.PositionX; inputs[1] = lander.PositionY; inputs[2] = lander.VelocityX; inputs[3] = lander.VelocityY; inputs[4] = lander.Enviroment.WindSpeed; // this.settings.LanderEnvironment.WindSpeed; inputs[5] = lander.Enviroment.Gravity; // varGravity; // this.settings.LanderEnvironment.Gravity; inputs[6] = lander.Fuel; output = this.neuralNet.Run(inputs); lander.Burn = output[0]; lander.Thrust = output[1]; lander.Update(); //this.settings.LanderEnvironment.Update(); } while (lander.Status == LanderStatus.Flying); this.Fitness += lander.CalculateFitness(); } //} }
public void ApplyAction(string action) { var actionArray = action.Split(" "); Lander.Apply(int.Parse(actionArray[0]), int.Parse(actionArray[1]), _environment); }
public MarsLanderActor(Lander lander, MarsLanderEnvironment environment) { Original = lander.Clone(); Lander = lander.Clone(); _environment = environment; }
static void Main(string[] args) { string[] inputs; int surfaceN = int.Parse(Console.ReadLine()); // the number of points used to draw the surface of Mars. // find the landing site Point landingStart = new Point(0, 0), landingEnd = new Point(0, 0); int landX0 = 0, landY0 = 0; for (int i = 0; i < surfaceN; i++) { inputs = Console.ReadLine().Split(' '); int landX = int.Parse(inputs[0]); // X coordinate of a surface point. (0 to 6999) int landY = int.Parse(inputs[1]); // Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars. // if no change in Y then set as new landingzone if (landY0 == landY) { landingStart = new Point(landX0, landY0); landingEnd = new Point(landX, landY); } landX0 = landX; landY0 = landY; } Console.Error.WriteLine("Landing Area: {0} - {1}", landingStart.X, landingEnd.X); // game loop while (true) { inputs = Console.ReadLine().Split(' '); int X = int.Parse(inputs[0]); int Y = int.Parse(inputs[1]); int hSpeed = int.Parse(inputs[2]); // the horizontal speed (in m/s), can be negative. int vSpeed = int.Parse(inputs[3]); // the vertical speed (in m/s), can be negative. int fuel = int.Parse(inputs[4]); // the quantity of remaining fuel in liters. double rotatation = int.Parse(inputs[5]); // the rotation angle in degrees (-90 to 90). int thrust = int.Parse(inputs[6]); // the thrust power (0 to 4). // create the lander Lander lander = new Lander(X, Y, hSpeed, vSpeed, fuel, rotatation, thrust); Point landing = new Point((landingEnd.X - landingStart.X) / 2, landingStart.Y + 2000); // the ideal landing spot midway into the flat area double g = -3.711; int power = 0; double rotate = 0; double AccelV = 0; // allowable vertical accel if ((lander.Y - landingStart.Y) > 1000) { AccelV = -0.5; } // move lander to the landing position if (lander.X < landingStart.X) { if (lander.HSpeed < 50) { lander.goRight(AccelV); } else { lander.goLeft(AccelV); } } // move the lander to the starting position else if (lander.X > landingEnd.X) { if (lander.HSpeed > -50) { lander.goLeft(AccelV); } else { lander.goRight(AccelV); } } else { if (lander.HSpeed < -1) { lander.goRight(AccelV); } else if (lander.HSpeed > 1) { lander.goLeft(AccelV); } else { rotate = 0; if (lander.VSpeed <= -40) { power = 4; } else { power = 3; } Console.WriteLine("{0} {1}", rotate, power); } } /* * double bestRotate=0; * double bestPower=0; * double bestScore=100000; * * // all angles * for (int rotate=-90; rotate<=90; rotate=rotate+15) * { * // all powers * for(int power=0; power<=4; power++) * { * //find the landing area for each combination * int HSpeedMax=40; * int VSpeedMax=-20; * Point estimatedlanding = lander.calculateXY(rotate, power, HSpeedMax, VSpeedMax); * double score=Math.Sqrt(Math.Pow(landing.X-estimatedlanding.X,2) + Math.Pow(landing.Y-estimatedlanding.Y, 2)); * * // Console.Error.WriteLine("{0} {1} => {2}", estimatedlanding.X, estimatedlanding.Y, Math.Round(score,2)); * * * // compare the score and take the closest match * if(score < bestScore) * { * //Console.Error.WriteLine("{0} < {1}", score, bestScore); * // Console.Error.WriteLine("BEST: {0} {1} => {2}", rotate, power, Math.Round(score,2)); * bestRotate=rotate; * bestPower=power; * bestScore=score; * } * } * } * Console.WriteLine("{0} {1}", bestRotate, bestPower); * */ /* * // calculate ideal acceleration * // a=[(v)^2-(v0)^2]/2d * double HDistance, VDistance, HSpeedIdeal, VSpeedIdeal; * * // lander to the left of landing zone * if(lander.X < landingStart.X) * { * HDistance=landingStart.X-lander.X; * VDistance=lander.Y-landingStart.Y+500; * VSpeedIdeal=-39; * HSpeedIdeal=40; * Console.Error.WriteLine("1"); * * } * // lander to the right of the landing zone * else if(lander.X > landingEnd.X) * { * HDistance=landingEnd.X-lander.X; * VDistance=landingStart.Y-lander.Y; * VSpeedIdeal=0; * HSpeedIdeal=-40; * } * // lander within the landing zone * else * { * HDistance=1; * VDistance=1; * HSpeedIdeal=0; * VSpeedIdeal=0; * * if(lander.HSpeed<20){ * * HDistance=1; * VDistance=lander.Y-landingStart.Y; * VSpeedIdeal=-39; * HSpeedIdeal=0; * } * } * * * * double accelHIdeal=calculateAccel(HSpeedIdeal, lander.HSpeed, HDistance); * double accelVIdeal=calculateAccel(VSpeedIdeal, lander.VSpeed, VDistance); * * Console.Error.WriteLine("H:{0} V:{1}", accelHIdeal, accelVIdeal); * lander.findBestRoute(accelHIdeal, accelVIdeal); * * * * * /* * // hover the lander and move to the landing zone * if(lander.X < landingStart.X) * { * if(lander.VSpeed < -30) * { * rotate=0; * power=4; * } * else{ * rotate=lander.Rotate-15; * if(rotate<-90) rotate=-90; * power=4; * } * * } * // lander to the right of the landing zone * else if(lander.X > landingEnd.X) * { * * } * // lander within the landing zone * else * { * if(lander.Rotate==0 && Math.Abs(lander.HSpeed)<20) * { * rotate=0; * if(lander.VSpeed>=40) power=4; * else power=lander.Power-1; * } * else if(lander.HSpeed>20) * { * if(lander.VSpeed < -40) * { * rotate=0; * power=4; * } * else{ * rotate=lander.Rotate+15; * if (rotate>90) rotate=90; * power=4; * } * } * } * * Console.WriteLine("{0} {1}", rotate, power); * * */ } }