Skip to content

Commit

Permalink
Impl other moves
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyasantoss committed Nov 1, 2021
1 parent e29de38 commit 00b6030
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 29 deletions.
11 changes: 6 additions & 5 deletions src/RubiksCube.Cli/RubiksCube.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp5.0</TargetFramework>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ReadLine" Version="2.0.1"/>
<PackageReference Include="ReadLine" Version="2.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\RubiksCube.Core\RubiksCube.Core.csproj"/>
<ProjectReference Include="..\RubiksCube.Expressions\RubiksCube.Expressions.csproj"/>
<ProjectReference Include="..\RubiksCube.Formatting.Console\RubiksCube.Formatting.Console.csproj"/>
<ProjectReference Include="..\RubiksCube.Core\RubiksCube.Core.csproj" />
<ProjectReference Include="..\RubiksCube.Expressions\RubiksCube.Expressions.csproj" />
<ProjectReference Include="..\RubiksCube.Formatting.Console\RubiksCube.Formatting.Console.csproj" />
</ItemGroup>
</Project>
103 changes: 90 additions & 13 deletions src/RubiksCube.Core/RubiksCube.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@ public RubiksCube(ushort size)
: this(
new[]
{
new CubeFace(CubeColor.Orange, size)
, new CubeFace(CubeColor.Green, size)
, new CubeFace(CubeColor.White, size)
, new CubeFace(CubeColor.Blue, size)
, new CubeFace(CubeColor.Red, size)
, new CubeFace(CubeColor.Yellow, size)
new CubeFace(CubeColor.Orange, size), new CubeFace(CubeColor.Green, size),
new CubeFace(CubeColor.White, size), new CubeFace(CubeColor.Blue, size),
new CubeFace(CubeColor.Red, size), new CubeFace(CubeColor.Yellow, size)
}
)
{
Expand All @@ -50,7 +47,7 @@ public RubiksCube(ushort size)

public ushort Size { get; }

public ushort Middle => (ushort)(Math.Round(Size / 2D) - 1D);
public ushort Middle => (ushort) (Math.Round(Size / 2D) - 1D);

public CubeFace[] Faces => _faces;

Expand Down Expand Up @@ -93,11 +90,10 @@ private void SanityCheck()

public void Turn(SimpleDirectionTurn turn)
{
var maxIndex = (ushort)(Size - 1);
var maxIndex = (ushort) (Size - 1);

switch (turn)
{
//TODO: Spin the cube on front and back moves
case SimpleDirectionTurn.Front:
Turn(TurnType.Line, maxIndex, TurnDirection.Normal);
break;
Expand Down Expand Up @@ -158,7 +154,8 @@ public void Turn(TurnType type, ushort indexer, TurnDirection direction)
TurnLine(ref indexer, ref direction);
break;
case TurnType.Column:
throw new NotImplementedException();
TurnColumn(ref indexer, ref direction);
break;
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
Expand All @@ -175,19 +172,99 @@ ref ushort indexer
TurnLineNormal(ref indexer);
break;
case TurnDirection.Reverse:
throw new NotImplementedException();
TurnLineReversed(ref indexer);
break;
default:
throw new ArgumentOutOfRangeException(nameof(direction), direction, null);
}
}

private void TurnColumn(
ref ushort indexer
, ref TurnDirection direction
)
{
switch (direction)
{
case TurnDirection.Normal:
TurnColumnNormal(ref indexer);
break;
case TurnDirection.Reverse:
TurnColumnReversed(ref indexer);
break;
default:
throw new ArgumentOutOfRangeException(nameof(direction), direction, null);
}
}

private void TurnColumnNormal(ref ushort indexer)
{
var faces = new[]
{
TopFace, FrontFace, BottomFace, BackFace, TopFace
};

var temp = new CubeSlot[Size];

foreach (var currentFace in faces)
{
for (var i = 0; i < currentFace.Size; i++)
{
//swap
var currentTemp = currentFace.Slots[i, indexer];
currentFace.Slots[i, indexer] = temp[i];
temp[i] = currentTemp;
}
}
}

private void TurnColumnReversed(ref ushort indexer)
{
var faces = new[]
{
TopFace, BackFace, BottomFace, FrontFace, TopFace
};

var temp = new CubeSlot[Size];

foreach (var currentFace in faces)
{
for (var i = 0; i < currentFace.Size; i++)
{
//swap
var currentTemp = currentFace.Slots[i, indexer];
currentFace.Slots[i, indexer] = temp[i];
temp[i] = currentTemp;
}
}
}

private void TurnLineNormal(ref ushort indexer)
{
var frontFace = FrontFace;
var faces = new[]
{
FrontFace, LeftFace, BackFace, RightFace, FrontFace
};

var temp = new CubeSlot[Size];

foreach (var currentFace in faces)
{
for (var i = 0; i < currentFace.Size; i++)
{
//swap
var currentTemp = currentFace.Slots[indexer, i];
currentFace.Slots[indexer, i] = temp[i];
temp[i] = currentTemp;
}
}
}

private void TurnLineReversed(ref ushort indexer)
{
var faces = new[]
{
frontFace, LeftFace, BackFace, RightFace, frontFace
FrontFace, RightFace, BackFace, LeftFace, FrontFace
};

var temp = new CubeSlot[Size];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0"/>
<PackageReference Include="xunit" Version="2.4.1"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\RubiksCube.Core\RubiksCube.Core.csproj"/>
<ProjectReference Include="..\..\src\RubiksCube.Core\RubiksCube.Core.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0"/>
<PackageReference Include="xunit" Version="2.4.1"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\RubiksCube.Expressions\RubiksCube.Expressions.csproj"/>
<ProjectReference Include="..\..\src\RubiksCube.Expressions\RubiksCube.Expressions.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ public void ShouldBeAbleParseMultipleExpressions(string expression)
}

[Theory]
[InlineData("RL'TB", "rltb")]
public void ShouldBeAbleParseMultipleExpressionsInACorrectOrder(string expected, string expression)
[InlineData("RL'TB")]
[InlineData("RLTB")]
public void ShouldBeAbleParseMultipleExpressionsInACorrectOrder(string expression)
{
var result = _parser.Parse(expression);

//TODO: assertion
Assert.True(result.Success);
Assert.True(result.Movements.Count() == 4);
}
}
}

0 comments on commit 00b6030

Please sign in to comment.