-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd5a1db
commit 5fa1ad8
Showing
41 changed files
with
1,701 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace SicTransit.Woodpusher.Engine | ||
{ | ||
public class Engine | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<RootNamespace>SicTransit.Woodpusher.Engine</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Model\Model.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
| ||
using SicTransit.Woodpusher.Model; | ||
|
||
namespace SicTransit.Woodpusher.Engine.Movement | ||
{ | ||
public static class BishopMovement | ||
{ | ||
public static IEnumerable<IEnumerable<Move>> GetTargetVectors(Square square) | ||
{ | ||
var topRight = Math.Max(square.File, square.Rank); | ||
|
||
if (topRight < 7) | ||
{ | ||
yield return Enumerable.Range(1, 7 - topRight).Select(d => new Move(square.AddFileAndRank(d, d))); | ||
} | ||
|
||
var bottomRight = Math.Max(square.File, 7 - square.Rank); | ||
|
||
if (bottomRight < 7) | ||
{ | ||
yield return Enumerable.Range(1, 7 - bottomRight).Select(d => new Move(square.AddFileAndRank(d, -d))); | ||
} | ||
|
||
var bottomLeft = Math.Min(square.File, square.Rank); | ||
|
||
if (bottomLeft > 0) | ||
{ | ||
yield return Enumerable.Range(1, bottomLeft).Select(d => new Move(square.AddFileAndRank(-d, -d))); | ||
} | ||
|
||
var topLeft = Math.Min(7 - square.File, square.Rank); | ||
|
||
if (topLeft > 0) | ||
{ | ||
yield return Enumerable.Range(1, topLeft).Select(d => new Move(square.AddFileAndRank(-d, d))); | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using SicTransit.Woodpusher.Model; | ||
using SicTransit.Woodpusher.Model.Enums; | ||
|
||
namespace SicTransit.Woodpusher.Engine.Movement | ||
{ | ||
public static class KingMovement | ||
{ | ||
private static Square WhiteStartPosition = Square.FromAlgebraicNotation("e1"); | ||
private static Square BlackStartPosition = Square.FromAlgebraicNotation("e8"); | ||
|
||
public static IEnumerable<IEnumerable<Move>> GetTargetVectors(Square square, Piece pieceColour) | ||
{ | ||
var r = square.Rank; | ||
var f = square.File; | ||
|
||
if (r < 7) | ||
{ | ||
yield return new[] { new Move(square.NewRank(r + 1)) }; | ||
|
||
if (f < 7) | ||
{ | ||
yield return new[] { new Move(square.AddFileAndRank(1, 1)) }; | ||
} | ||
} | ||
|
||
if (f < 7) | ||
{ | ||
yield return new[] { new Move(square.NewFile(f + 1)) }; | ||
|
||
if (r > 0) | ||
{ | ||
yield return new[] { new Move(square.AddFileAndRank(1, -1)) }; | ||
} | ||
} | ||
|
||
if (r > 0) | ||
{ | ||
yield return new[] { new Move(square.NewRank(r - 1)) }; | ||
|
||
if (f > 0) | ||
{ | ||
yield return new[] { new Move(square.AddFileAndRank(-1, -1)) }; | ||
} | ||
} | ||
|
||
if (f > 0) | ||
{ | ||
yield return new[] { new Move(square.NewFile(f - 1)) }; | ||
|
||
if (r < 7) | ||
{ | ||
yield return new[] { new Move(square.AddFileAndRank(-1, 1)) }; | ||
} | ||
} | ||
|
||
if (pieceColour == Piece.White) | ||
{ | ||
if (square.Equals(WhiteStartPosition)) | ||
{ | ||
yield return new[] { new Move(new Square(6, 0), MovementFlags.CastleKing) }; | ||
yield return new[] { new Move(new Square(2, 0), MovementFlags.CastleQueen) }; | ||
} | ||
} | ||
else | ||
{ | ||
if (square.Equals(BlackStartPosition)) | ||
{ | ||
yield return new[] { new Move(new Square(6, 7), MovementFlags.CastleKing) }; | ||
yield return new[] { new Move(new Square(2, 7), MovementFlags.CastleQueen) }; | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using SicTransit.Woodpusher.Model; | ||
|
||
namespace SicTransit.Woodpusher.Engine.Movement | ||
{ | ||
public static class KnightMovement | ||
{ | ||
public static IEnumerable<IEnumerable<Move>> GetTargetVectors(Square square) | ||
{ | ||
var f = square.File; | ||
var r = square.Rank; | ||
|
||
Square s; | ||
|
||
if (Square.TryCreate(f + 1, r + 2, out s)) | ||
{ | ||
yield return new[] { new Move(s) }; | ||
} | ||
|
||
if (Square.TryCreate(f + 2, r + 1, out s)) | ||
{ | ||
yield return new[] { new Move(s) }; | ||
} | ||
|
||
if (Square.TryCreate(f + 2, r - 1, out s)) | ||
{ | ||
yield return new[] { new Move(s) }; | ||
} | ||
|
||
if (Square.TryCreate(f + 1, r - 2, out s)) | ||
{ | ||
yield return new[] { new Move(s) }; | ||
} | ||
|
||
if (Square.TryCreate(f - 1, r - 2, out s)) | ||
{ | ||
yield return new[] { new Move(s) }; | ||
} | ||
|
||
if (Square.TryCreate(f - 2, r - 1, out s)) | ||
{ | ||
yield return new[] { new Move(s) }; | ||
} | ||
|
||
if (Square.TryCreate(f - 2, r + 1, out s)) | ||
{ | ||
yield return new[] { new Move(s) }; | ||
} | ||
|
||
if (Square.TryCreate(f - 1, r + 2, out s)) | ||
{ | ||
yield return new[] { new Move(s) }; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
| ||
using SicTransit.Woodpusher.Model; | ||
using SicTransit.Woodpusher.Model.Enums; | ||
|
||
namespace SicTransit.Woodpusher.Engine.Movement | ||
{ | ||
public static class PawnMovement | ||
{ | ||
public static IEnumerable<IEnumerable<Move>> GetTargetVectors(Square square, Piece colour) | ||
{ | ||
var rank = square.Rank; | ||
|
||
if (rank is 7 or 0) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(square), $"A pawn shouldn't be here: {square}"); | ||
} | ||
|
||
var file = square.File; | ||
|
||
if (colour == Piece.White) | ||
{ | ||
var forward = new List<Move>() { new Move(square.NewRank(rank + 1), rank == 6 ? MovementFlags.Promote : MovementFlags.None) }; | ||
|
||
if (rank == 1) | ||
{ | ||
forward.Add(new Move(square.NewRank(rank + 2))); | ||
} | ||
|
||
yield return forward; | ||
|
||
if (Square.TryCreate(file - 1, rank + 1, out var takeLeft)) | ||
{ | ||
yield return new[] { new Move(takeLeft, rank == 6 ? MovementFlags.MustTake | MovementFlags.Promote : MovementFlags.MustTake) }; | ||
|
||
if (rank == 4) | ||
{ | ||
yield return new[] { new Move(takeLeft, MovementFlags.EnPassant) }; | ||
} | ||
} | ||
|
||
if (Square.TryCreate(file + 1, rank + 1, out var takeRight)) | ||
{ | ||
yield return new[] { new Move(takeRight, rank == 6 ? MovementFlags.MustTake | MovementFlags.Promote : MovementFlags.MustTake) }; | ||
|
||
if (rank == 4) | ||
{ | ||
yield return new[] { new Move(takeRight, MovementFlags.EnPassant) }; | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
var forward = new List<Move>() { new Move(square.NewRank(rank - 1), rank == 1 ? MovementFlags.Promote : MovementFlags.None) }; | ||
|
||
if (rank == 6) | ||
{ | ||
forward.Add(new Move(square.NewRank(rank - 2))); | ||
} | ||
|
||
yield return forward; | ||
|
||
if (Square.TryCreate(file - 1, rank - 1, out var takeLeft)) | ||
{ | ||
yield return new[] { new Move(takeLeft, rank == 1 ? MovementFlags.MustTake | MovementFlags.Promote : MovementFlags.MustTake) }; | ||
|
||
if (rank == 3) | ||
{ | ||
yield return new[] { new Move(takeLeft, MovementFlags.EnPassant) }; | ||
} | ||
} | ||
|
||
if (Square.TryCreate(file + 1, rank - 1, out var takeRight)) | ||
{ | ||
yield return new[] { new Move(takeRight, rank == 1 ? MovementFlags.MustTake | MovementFlags.Promote : MovementFlags.MustTake) }; | ||
|
||
if (rank == 3) | ||
{ | ||
yield return new[] { new Move(takeRight, MovementFlags.EnPassant) }; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
| ||
using SicTransit.Woodpusher.Model; | ||
|
||
namespace SicTransit.Woodpusher.Engine.Movement | ||
{ | ||
public static class QueenMovement | ||
{ | ||
public static IEnumerable<IEnumerable<Move>> GetTargetVectors(Square square) | ||
{ | ||
return BishopMovement.GetTargetVectors(square).Concat(RookMovement.GetTargetVectors(square)); | ||
} | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using SicTransit.Woodpusher.Model; | ||
|
||
namespace SicTransit.Woodpusher.Engine.Movement | ||
{ | ||
public static class RookMovement | ||
{ | ||
public static IEnumerable<IEnumerable<Move>> GetTargetVectors(Square square) | ||
{ | ||
if (square.Rank < 7) | ||
{ | ||
yield return Enumerable.Range(square.Rank + 1, 7 - square.Rank).Select(r => new Move(square.NewRank(r))); | ||
} | ||
|
||
if (square.File < 7) | ||
{ | ||
yield return Enumerable.Range(square.File + 1, 7 - square.File).Select(f => new Move(square.NewFile(f))); | ||
} | ||
|
||
if (square.Rank > 0) | ||
{ | ||
yield return Enumerable.Range(0, square.Rank).Reverse().Select(r => new Move(square.NewRank(r))); | ||
} | ||
|
||
if (square.File > 0) | ||
{ | ||
yield return Enumerable.Range(0, square.File).Reverse().Select(f => new Move(square.NewFile(f))); | ||
} | ||
|
||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" /> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Engine\Engine.csproj" /> | ||
<ProjectReference Include="..\Model\Model.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.