checkpoint
This commit is contained in:
120
BoardRules/BoardRules.cs
Normal file
120
BoardRules/BoardRules.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
//using System.Drawing;
|
||||
//using System.Numerics;
|
||||
|
||||
//namespace BoardRules;
|
||||
|
||||
//public static class PieceMoves
|
||||
//{
|
||||
// public static readonly ICollection<Vector2> GoldGeneralMoves =
|
||||
// [
|
||||
// new(-1, 1),
|
||||
// new(0, 1),
|
||||
// new(1, 1),
|
||||
// new(-1, 0),
|
||||
// new(1, 0),
|
||||
// new(0, -1)
|
||||
// ];
|
||||
|
||||
// public static readonly ICollection<Vector2> PawnMoves = [new(0, 1)];
|
||||
|
||||
// public static readonly ICollection<Vector2> KnightMoves = [new(-1, 2), new(1, 2)];
|
||||
|
||||
// public static readonly ICollection<Vector2> BishopMoves =
|
||||
// [
|
||||
// new(float.NegativeInfinity, float.NegativeInfinity),
|
||||
// new(float.NegativeInfinity, float.PositiveInfinity),
|
||||
// new(float.PositiveInfinity, float.PositiveInfinity),
|
||||
// new(float.PositiveInfinity, float.NegativeInfinity),
|
||||
// ];
|
||||
//}
|
||||
|
||||
//public class BoardRules
|
||||
//{
|
||||
// private readonly Dictionary<string, IPiece> pieces = [];
|
||||
|
||||
// public BoardRules WithSize(int width, int height)
|
||||
// {
|
||||
// this.BoardSize = new Size(width, height);
|
||||
// return this;
|
||||
// }
|
||||
|
||||
// public Size BoardSize { get; private set; }
|
||||
|
||||
// public BoardRules AddPiece(IPiece piece)
|
||||
// {
|
||||
// pieces.Add(piece.Name, piece);
|
||||
// return this;
|
||||
// }
|
||||
//}
|
||||
|
||||
//public class BoardPieceRules(BoardRules rules, IPiece piece)
|
||||
//{
|
||||
// public IPiece Piece { get; } = piece;
|
||||
// public BoardRules WithStartingPositions(ICollection<Vector2> positions)
|
||||
// {
|
||||
// // Validate positions against board size
|
||||
// foreach (var pos in positions)
|
||||
// {
|
||||
// if (pos.X < 0 || pos.Y < 0 || pos.X >= rules.BoardSize.Width || pos.Y >= rules.BoardSize.Height)
|
||||
// {
|
||||
// throw new ArgumentOutOfRangeException(nameof(positions), $"Position {pos} is out of bounds for board size {rules.BoardSize}.");
|
||||
// }
|
||||
// }
|
||||
// // Assuming piece has a way to set starting positions, which it currently does not.
|
||||
// // This is just a placeholder to show intent.
|
||||
// // piece.SetStartingPositions(positions);
|
||||
// return rules;
|
||||
// }
|
||||
//}
|
||||
|
||||
//public interface IPiece
|
||||
//{
|
||||
// public string Name { get; }
|
||||
// public ICollection<Vector2> MoveSet { get; }
|
||||
// public ICollection<Vector2> PromotedMoveSet { get; }
|
||||
|
||||
// /// <summary>
|
||||
// /// The starting positions for this type of piece on the board. There could be one or many.
|
||||
// /// </summary>
|
||||
// public ICollection<Vector2> StartingPositions { get; }
|
||||
//}
|
||||
|
||||
//public class GoldGeneral : IPiece
|
||||
//{
|
||||
// public string Name => nameof(GoldGeneral);
|
||||
// public ICollection<Vector2> MoveSet => PieceMoves.GoldGeneralMoves;
|
||||
// public ICollection<Vector2> PromotedMoveSet => PieceMoves.GoldGeneralMoves;
|
||||
|
||||
// public ICollection<Vector2> StartingPositions => [new(3, 0), new(5, 0), new(4, 1)];
|
||||
//}
|
||||
|
||||
//public class Pawn : IPiece
|
||||
//{
|
||||
// public string Name => nameof(Pawn);
|
||||
// public ICollection<Vector2> MoveSet => PieceMoves.PawnMoves;
|
||||
// public ICollection<Vector2> PromotedMoveSet => PieceMoves.GoldGeneralMoves;
|
||||
//}
|
||||
|
||||
//public class Knight : IPiece
|
||||
//{
|
||||
// public string Name => nameof(Knight);
|
||||
// public ICollection<Vector2> MoveSet => PieceMoves.KnightMoves;
|
||||
// public ICollection<Vector2> PromotedMoveSet => PieceMoves.GoldGeneralMoves;
|
||||
//}
|
||||
|
||||
//public class Bishop : IPiece
|
||||
//{
|
||||
// public string Name => nameof(Bishop);
|
||||
// public ICollection<Vector2> MoveSet => PieceMoves.BishopMoves;
|
||||
// public ICollection<Vector2> PromotedMoveSet => PieceMoves.BishopMoves;
|
||||
//}
|
||||
|
||||
//public class Luke
|
||||
//{
|
||||
// public void Yep()
|
||||
// {
|
||||
// var board = new BoardRules()
|
||||
// .WithSize(9, 9)
|
||||
// .AddPiece(new Pawn())
|
||||
// }
|
||||
//}
|
||||
9
BoardRules/BoardRules.csproj
Normal file
9
BoardRules/BoardRules.csproj
Normal file
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -32,3 +32,9 @@ public enum WhichPiece
|
||||
Pawn,
|
||||
//PromotedPawn,
|
||||
}
|
||||
|
||||
public enum WhichPlayer
|
||||
{
|
||||
Player1,
|
||||
Player2
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Shogi.Domain.YetToBeAssimilatedIntoDDD.Pathing;
|
||||
namespace Shogi.Domain.ValueObjects;
|
||||
|
||||
public static class Direction
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Shogi.Domain.YetToBeAssimilatedIntoDDD.Pathing;
|
||||
namespace Shogi.Domain.ValueObjects;
|
||||
|
||||
public enum Distance
|
||||
{
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Shogi.Domain.YetToBeAssimilatedIntoDDD.Pathing;
|
||||
namespace Shogi.Domain.ValueObjects.Movement;
|
||||
|
||||
[DebuggerDisplay("{Step} - {Distance}")]
|
||||
public record Path
|
||||
@@ -17,7 +17,7 @@ public record Path
|
||||
public Path(Vector2 step, Distance distance = Distance.OneStep)
|
||||
{
|
||||
Step = step;
|
||||
this.Distance = distance;
|
||||
Distance = distance;
|
||||
}
|
||||
|
||||
public Path Invert() => new(Vector2.Negate(Step), Distance);
|
||||
@@ -1,4 +1,4 @@
|
||||
using Shogi.Domain.YetToBeAssimilatedIntoDDD.Pathing;
|
||||
using Shogi.Domain.ValueObjects.Movement;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Shogi.Domain.ValueObjects
|
||||
@@ -1,4 +1,4 @@
|
||||
using Shogi.Domain.YetToBeAssimilatedIntoDDD.Pathing;
|
||||
using Shogi.Domain.ValueObjects.Movement;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Shogi.Domain.ValueObjects;
|
||||
@@ -1,4 +1,4 @@
|
||||
using Shogi.Domain.YetToBeAssimilatedIntoDDD.Pathing;
|
||||
using Shogi.Domain.ValueObjects.Movement;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Shogi.Domain.ValueObjects;
|
||||
@@ -1,4 +1,4 @@
|
||||
using Shogi.Domain.YetToBeAssimilatedIntoDDD.Pathing;
|
||||
using Shogi.Domain.ValueObjects.Movement;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Shogi.Domain.ValueObjects
|
||||
@@ -1,4 +1,4 @@
|
||||
using Shogi.Domain.YetToBeAssimilatedIntoDDD.Pathing;
|
||||
using Shogi.Domain.ValueObjects.Movement;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Shogi.Domain.ValueObjects
|
||||
@@ -1,4 +1,4 @@
|
||||
using Shogi.Domain.YetToBeAssimilatedIntoDDD.Pathing;
|
||||
using Shogi.Domain.ValueObjects.Movement;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Shogi.Domain.ValueObjects
|
||||
@@ -1,4 +1,4 @@
|
||||
using Shogi.Domain.YetToBeAssimilatedIntoDDD.Pathing;
|
||||
using Shogi.Domain.ValueObjects.Movement;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Shogi.Domain.ValueObjects
|
||||
@@ -1,4 +1,4 @@
|
||||
using Shogi.Domain.YetToBeAssimilatedIntoDDD.Pathing;
|
||||
using Shogi.Domain.ValueObjects.Movement;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Shogi.Domain.ValueObjects;
|
||||
@@ -1,4 +1,4 @@
|
||||
using Shogi.Domain.YetToBeAssimilatedIntoDDD.Pathing;
|
||||
using Shogi.Domain.ValueObjects.Movement;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Shogi.Domain.ValueObjects
|
||||
@@ -1,4 +1,5 @@
|
||||
using Shogi.Domain.YetToBeAssimilatedIntoDDD;
|
||||
using Shogi.Domain.ValueObjects.Movement;
|
||||
using Shogi.Domain.YetToBeAssimilatedIntoDDD;
|
||||
namespace Shogi.Domain.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
@@ -247,7 +248,7 @@ public sealed class ShogiBoard(BoardState initialState)
|
||||
{
|
||||
var list = new List<Vector2>(10);
|
||||
var position = path.Step + piecePosition;
|
||||
if (path.Distance == YetToBeAssimilatedIntoDDD.Pathing.Distance.MultiStep)
|
||||
if (path.Distance == Distance.MultiStep)
|
||||
{
|
||||
|
||||
while (position.IsInsideBoardBoundary())
|
||||
@@ -340,7 +341,7 @@ public sealed class ShogiBoard(BoardState initialState)
|
||||
else
|
||||
{
|
||||
var multiStepPaths = matchingPaths
|
||||
.Where(path => path.Distance == YetToBeAssimilatedIntoDDD.Pathing.Distance.MultiStep)
|
||||
.Where(path => path.Distance == Distance.MultiStep)
|
||||
.ToArray();
|
||||
if (multiStepPaths.Length == 0)
|
||||
{
|
||||
@@ -371,7 +372,7 @@ public sealed class ShogiBoard(BoardState initialState)
|
||||
return new MoveResult(true);
|
||||
}
|
||||
|
||||
private static IEnumerable<Vector2> GetPositionsAlongPath(Vector2 from, Vector2 to, YetToBeAssimilatedIntoDDD.Pathing.Path path)
|
||||
private static IEnumerable<Vector2> GetPositionsAlongPath(Vector2 from, Vector2 to, Path path)
|
||||
{
|
||||
var next = from;
|
||||
while (next != to && next.X >= 0 && next.X < 9 && next.Y >= 0 && next.Y < 9)
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace Shogi.Domain.ValueObjects
|
||||
{
|
||||
public enum WhichPlayer
|
||||
{
|
||||
Player1,
|
||||
Player2
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shogi.Api", "Shogi.Api\Shog
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "E2ETests", "Tests\E2ETests\E2ETests.csproj", "{401120C3-45D6-4A23-8D87-C2BED29F4950}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BoardRules", "BoardRules\BoardRules.csproj", "{5B2F47A0-6AD5-4DA9-9CFE-9F52F634DD5E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -67,6 +69,10 @@ Global
|
||||
{401120C3-45D6-4A23-8D87-C2BED29F4950}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{401120C3-45D6-4A23-8D87-C2BED29F4950}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{401120C3-45D6-4A23-8D87-C2BED29F4950}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5B2F47A0-6AD5-4DA9-9CFE-9F52F634DD5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5B2F47A0-6AD5-4DA9-9CFE-9F52F634DD5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5B2F47A0-6AD5-4DA9-9CFE-9F52F634DD5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5B2F47A0-6AD5-4DA9-9CFE-9F52F634DD5E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using System.Numerics;
|
||||
using Shogi.Domain.YetToBeAssimilatedIntoDDD;
|
||||
using Shogi.Domain.YetToBeAssimilatedIntoDDD;
|
||||
using System.Numerics;
|
||||
|
||||
namespace UnitTests
|
||||
namespace UnitTests;
|
||||
|
||||
public class NotationShould
|
||||
{
|
||||
public class NotationShould
|
||||
{
|
||||
[Fact]
|
||||
public void ConvertFromNotationToVector()
|
||||
{
|
||||
@@ -22,5 +22,4 @@ namespace UnitTests
|
||||
Notation.ToBoardNotation(new Vector2(8, 8)).Should().Be("I9");
|
||||
Notation.ToBoardNotation(new Vector2(2, 2)).Should().Be("C3");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Shogi.Domain.ValueObjects;
|
||||
using Shogi.Domain.YetToBeAssimilatedIntoDDD.Pathing;
|
||||
using Shogi.Domain.ValueObjects.Movement;
|
||||
using System.Numerics;
|
||||
|
||||
namespace UnitTests;
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
using Shogi.Domain.ValueObjects;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace UnitTests
|
||||
namespace UnitTests;
|
||||
|
||||
public class ShogiShould
|
||||
{
|
||||
public class ShogiShould
|
||||
{
|
||||
private readonly ITestOutputHelper console;
|
||||
public ShogiShould(ITestOutputHelper console)
|
||||
{
|
||||
@@ -456,5 +454,4 @@ namespace UnitTests
|
||||
}
|
||||
|
||||
private static ShogiBoard MockShogiBoard() => new(BoardState.StandardStarting);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user