Skip to content

Commit

Permalink
create new
Browse files Browse the repository at this point in the history
  • Loading branch information
LovorDev committed Sep 21, 2023
1 parent 967a142 commit ae64b11
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CodinGameSolutions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SummerChallenge2023", "Summ
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Code vs Zombies", "Code vs Zombies\Code vs Zombies.csproj", "{7C31D204-C3B9-422F-818A-25463BF6835C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mars Lander", "Mars Lander\Mars Lander.csproj", "{5F313686-D3B9-4E6D-884D-D185F93364A5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -24,5 +26,9 @@ Global
{7C31D204-C3B9-422F-818A-25463BF6835C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C31D204-C3B9-422F-818A-25463BF6835C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7C31D204-C3B9-422F-818A-25463BF6835C}.Release|Any CPU.Build.0 = Release|Any CPU
{5F313686-D3B9-4E6D-884D-D185F93364A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5F313686-D3B9-4E6D-884D-D185F93364A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F313686-D3B9-4E6D-884D-D185F93364A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F313686-D3B9-4E6D-884D-D185F93364A5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
9 changes: 9 additions & 0 deletions Mars Lander/Mars Lander.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>Mars_Lander</RootNamespace>
</PropertyGroup>

</Project>
88 changes: 88 additions & 0 deletions Mars Lander/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

/**
* Save the Planet.
* Use less Fossil Fuel.
*/
class Player
{
public record FlatSurface(Vector2 Left, Vector2 Right, Vector2 Center, float Length)
{
public override string ToString()
{
return $"{{ Left = {Left}, Right = {Right}, Center = {Center}, Length = {Length} }}";
}
}

private static void Main(string[] args)
{
string[] inputs;
var N = int.Parse(Console.ReadLine()); // the number of points used to draw the surface of Mars.

var marsLandPoints = new List<Vector2>();
for (var i = 0; i < N; i++)
{
inputs = Console.ReadLine().Split(' ');
var landX = int.Parse(inputs[0]);
var landY = int.Parse(inputs[1]);
marsLandPoints.Add(new Vector2(landX, landY));
}

var flatSurface2 = marsLandPoints.Skip(1)
.Select((x, i) => new FlatSurface(marsLandPoints[i], x, (marsLandPoints[i] + x) / 2, x.X - marsLandPoints[i].X));
var flatSurface = flatSurface2
.FirstOrDefault(x => x.Left.Y == x.Right.Y);


// game loop
while (true)
{
inputs = Console.ReadLine().Split(' ');
var position = new Vector2(int.Parse(inputs[0]), int.Parse(inputs[1]));
var speed = new Vector2(int.Parse(inputs[2]), int.Parse(inputs[3]));

var F = int.Parse(inputs[4]); // the quantity of remaining fuel in liters.
var R = int.Parse(inputs[5]); // the rotation angle in degrees (-90 to 90).
var P = int.Parse(inputs[6]); // the thrust power (0 to 4).

// Write an action using Console.WriteLine()
// To debug: Console.Error.WriteLine("Debug messages...");
SetPositionAboveLand(flatSurface, position, speed);
}
}

private static void SetPositionAboveLand(FlatSurface flatSurface, Vector2 position, Vector2 speed)
{
var directionToSurface = -1;


var direction = (flatSurface.Center - position).X;
var rotation = -20 * (direction / 4000) - (speed.X / 50);
Console.Error.WriteLine($"Direction%: {direction / 4000}. speed%{speed.X / 50}");

// if (direction < -flatSurface.Length / 2)
// {
// rotation *= 1;
// }
// else if (direction > flatSurface.Length / 2)
// {
// rotation *= -1;
// }

int trust = 0;
if (position.Y < 2500)
{
trust = 4;
}
else
{
trust = 3;
}

// R P. R is the desired rotation angle. P is the desired thrust power.
Console.WriteLine($"{(int)rotation} {trust}");
}
}

0 comments on commit ae64b11

Please sign in to comment.