Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ausführung der beiden Coding Katas #28

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions katas/LangtonAnt/solutions/UmlauteUeberall/Langton/Langton.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33205.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LangtonWholeInOne", "Langton\LangtonWholeInOne.csproj", "{500A2445-E4BF-48A7-900C-CFA0BB244AA4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LangtonFrontend", "LangtonFrontend\LangtonFrontend.csproj", "{623833F8-B936-4AEA-9BE0-2DB62C298C01}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LangtonBackend", "LangtonBackend\LangtonBackend.csproj", "{AD301928-3F49-4A34-9F1F-8336097DAE65}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{500A2445-E4BF-48A7-900C-CFA0BB244AA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{500A2445-E4BF-48A7-900C-CFA0BB244AA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{500A2445-E4BF-48A7-900C-CFA0BB244AA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{500A2445-E4BF-48A7-900C-CFA0BB244AA4}.Release|Any CPU.Build.0 = Release|Any CPU
{623833F8-B936-4AEA-9BE0-2DB62C298C01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{623833F8-B936-4AEA-9BE0-2DB62C298C01}.Debug|Any CPU.Build.0 = Debug|Any CPU
{623833F8-B936-4AEA-9BE0-2DB62C298C01}.Release|Any CPU.ActiveCfg = Release|Any CPU
{623833F8-B936-4AEA-9BE0-2DB62C298C01}.Release|Any CPU.Build.0 = Release|Any CPU
{AD301928-3F49-4A34-9F1F-8336097DAE65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD301928-3F49-4A34-9F1F-8336097DAE65}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD301928-3F49-4A34-9F1F-8336097DAE65}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD301928-3F49-4A34-9F1F-8336097DAE65}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9F000889-483E-41AD-A737-6DAE337EAE6D}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Langton
{
public enum EDirection
{
LEFT,
UP,
RIGHT,
DOWN,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System.Threading;

using Console = System.Console;
using Math = System.Math;

namespace Langton
{
internal class CField
{
private static readonly int WORLD_SIZE = 11;
public static int SLEEP_TIME = 500;

private bool[,] mi_field;
private EDirection mi_dir = EDirection.LEFT;
private SVector2 mi_pos;

public CField()
{
mi_field = new bool[WORLD_SIZE, WORLD_SIZE];
mi_pos = new SVector2((int) Math.Ceiling(WORLD_SIZE / 2.0f), (int)Math.Ceiling(WORLD_SIZE / 2.0f));
}

public void fu_Run()
{
bool isRunning = true;

Thread inputThread = new Thread(() =>
{
if (Console.ReadKey(true).Key == System.ConsoleKey.Escape)
isRunning = false;
});
inputThread.Start();

while (isRunning)
{
fi_Draw();
Thread.Sleep(SLEEP_TIME);
fi_Calculate();
}
}

private void fi_Calculate()
{
// rotate
mi_dir += mi_field[mi_pos.X, mi_pos.Y] ? -1 : 1;
mi_dir = (EDirection) (((int)mi_dir + 4) % 4);

// color
mi_field[mi_pos.X, mi_pos.Y] = !mi_field[mi_pos.X, mi_pos.Y];

// move
mi_pos += mi_dir;
mi_pos = mi_pos.fu_DonutClamp(WORLD_SIZE);
}

private void fi_Draw()
{
Console.CursorVisible = false;
for(int y = 0; y < mi_field.GetLength(1); y++)
{
for(int x = 0; x < mi_field.GetLength(0); x++)
{
Console.SetCursorPosition(x, y);
Console.BackgroundColor = mi_field[x, y] ? System.ConsoleColor.Black : System.ConsoleColor.White;
if (mi_pos.X == x && mi_pos.Y == y)
{
Console.ForegroundColor = System.ConsoleColor.Red;
Console.Write(fi_CharForDir());
}
else
{
Console.Write(' ');
}
}
Console.SetCursorPosition(0, WORLD_SIZE);
Console.ResetColor();
}

Console.WriteLine("Press Escape for exiting");
}

private char fi_CharForDir()
{
switch (mi_dir)
{
case EDirection.LEFT:
return '←';
case EDirection.UP:
return '↑';
case EDirection.RIGHT:
return '→';
case EDirection.DOWN:
return '↓';
default:
throw new System.ArgumentException($"Direction {mi_dir} not valid");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{500A2445-E4BF-48A7-900C-CFA0BB244AA4}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Langton</RootNamespace>
<AssemblyName>Langton</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Direction.cs" />
<Compile Include="Field.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Vector2.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Disclaimer - Diese Lösung habe ich implementiert bevor ich die README.MD gelesen habe,
// nur anhand der mitgelieferten GIF und theoretischem Vorwissen zu Langtons Ameise
namespace Langton
{
internal class Program
{
static void Main(string[] args)
{
CField f = new CField();
f.fu_Run();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("Langton")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Langton")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
[assembly: ComVisible(false)]

// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("500a2445-e4bf-48a7-900c-cfa0bb244aa4")]

// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace Langton
{
internal struct SVector2
{
public int X;
public int Y;

public SVector2(int _x, int _y)
{
X = _x;
Y = _y;
}

public static SVector2 operator +(SVector2 _v1, SVector2 _v2)
{
return new SVector2(_v1.X + _v2.X, _v1.Y + _v2.Y);
}

public static SVector2 operator +(SVector2 _v1, EDirection _dir)
{
switch (_dir)
{
case EDirection.LEFT:
return _v1 + new SVector2(-1, 0);
case EDirection.UP:
return _v1 + new SVector2(0, -1);
case EDirection.RIGHT:
return _v1 + new SVector2(1, 0);
case EDirection.DOWN:
return _v1 + new SVector2(0, 1);
default:
throw new System.ArgumentException($"Direction {_dir} not valid");
}
}

public SVector2 fu_DonutClamp(int _worldSize)
{
return new SVector2((X + _worldSize) % _worldSize,
(Y + _worldSize) % _worldSize);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace LangtonBackend
{
public enum EDirection
{
LEFT,
UP,
RIGHT,
DOWN,
}
}
Loading