Better fix
This commit is contained in:
@@ -330,12 +330,23 @@ public sealed class ShogiBoard(BoardState initialState)
|
|||||||
|
|
||||||
var clampedFromTo = Vector2.Clamp(to - from, -Vector2.One, Vector2.One);
|
var clampedFromTo = Vector2.Clamp(to - from, -Vector2.One, Vector2.One);
|
||||||
var matchingPaths = piece.MoveSet.Where(p => p.Step == clampedFromTo);
|
var matchingPaths = piece.MoveSet.Where(p => p.Step == clampedFromTo);
|
||||||
|
if (Vector2.Distance(to, from) < 2)
|
||||||
|
{
|
||||||
if (!matchingPaths.Any())
|
if (!matchingPaths.Any())
|
||||||
{
|
{
|
||||||
return new MoveResult(false, "Piece cannot move like that.");
|
return new MoveResult(false, "Piece cannot move like that.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var multiStepPaths = matchingPaths
|
||||||
|
.Where(path => path.Distance == YetToBeAssimilatedIntoDDD.Pathing.Distance.MultiStep)
|
||||||
|
.ToArray();
|
||||||
|
if (multiStepPaths.Length == 0)
|
||||||
|
{
|
||||||
|
return new MoveResult(false, "Piece cannot move like that");
|
||||||
|
}
|
||||||
|
|
||||||
var multiStepPaths = matchingPaths.Where(path => path.Distance == YetToBeAssimilatedIntoDDD.Pathing.Distance.MultiStep).ToArray();
|
|
||||||
foreach (var path in multiStepPaths)
|
foreach (var path in multiStepPaths)
|
||||||
{
|
{
|
||||||
// Assert that no pieces exist along the from -> to path.
|
// Assert that no pieces exist along the from -> to path.
|
||||||
@@ -348,6 +359,7 @@ public sealed class ShogiBoard(BoardState initialState)
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var pieceAtTo = BoardState[to];
|
var pieceAtTo = BoardState[to];
|
||||||
if (pieceAtTo?.Owner == piece.Owner)
|
if (pieceAtTo?.Owner == piece.Owner)
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
.MainLayout {
|
.MainLayout {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: auto 1fr;
|
grid-template-columns: auto 1fr;
|
||||||
|
grid-template-rows: 100vh;
|
||||||
place-items: stretch;
|
place-items: stretch;
|
||||||
height: 100vh;
|
}
|
||||||
|
|
||||||
|
@media all and (max-width: 600px) {
|
||||||
|
.MainLayout {
|
||||||
|
grid-template-columns: min-content max-content;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -103,18 +103,19 @@ namespace UnitTests
|
|||||||
// Arrange
|
// Arrange
|
||||||
var shogi = MockShogiBoard();
|
var shogi = MockShogiBoard();
|
||||||
var board = shogi.BoardState;
|
var board = shogi.BoardState;
|
||||||
var expectedPiece = board["A1"];
|
var expectedPiece = board["D1"];
|
||||||
expectedPiece!.WhichPiece.Should().Be(WhichPiece.Lance);
|
expectedPiece!.WhichPiece.Should().Be(WhichPiece.GoldGeneral);
|
||||||
|
|
||||||
// Act - Move Lance illegally
|
// Act - Move General illegally
|
||||||
var moveResult = shogi.Move("A1", "D5", false);
|
var moveResult = shogi.Move("D1", "D5", false);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
using (new AssertionScope())
|
using (new AssertionScope())
|
||||||
{
|
{
|
||||||
moveResult.Should().NotBeNull();
|
moveResult.Should().NotBeNull();
|
||||||
moveResult.IsSuccess.Should().BeFalse(); board["A1"].Should().Be(expectedPiece);
|
moveResult.IsSuccess.Should().BeFalse();
|
||||||
board["A5"].Should().BeNull();
|
board["D1"].Should().Be(expectedPiece);
|
||||||
|
board["D5"].Should().BeNull();
|
||||||
board.Player1Hand.Should().BeEmpty();
|
board.Player1Hand.Should().BeEmpty();
|
||||||
board.Player2Hand.Should().BeEmpty();
|
board.Player2Hand.Should().BeEmpty();
|
||||||
}
|
}
|
||||||
@@ -292,19 +293,19 @@ namespace UnitTests
|
|||||||
// Arrange
|
// Arrange
|
||||||
var shogi = MockShogiBoard();
|
var shogi = MockShogiBoard();
|
||||||
// P1 Pawn
|
// P1 Pawn
|
||||||
shogi.Move("C3", "C4", false);
|
shogi.Move("C3", "C4", false).IsSuccess.Should().BeTrue();
|
||||||
// P2 Pawn
|
// P2 Pawn
|
||||||
shogi.Move("G7", "G6", false);
|
shogi.Move("G7", "G6", false).IsSuccess.Should().BeTrue();
|
||||||
// P1 Pawn, arbitrary move.
|
// P1 Pawn, arbitrary move.
|
||||||
shogi.Move("A3", "A4", false);
|
shogi.Move("A3", "A4", false).IsSuccess.Should().BeTrue();
|
||||||
// P2 Bishop takes P1 Bishop
|
// P2 Bishop takes P1 Bishop
|
||||||
shogi.Move("H8", "B2", false);
|
shogi.Move("H8", "B2", false).IsSuccess.Should().BeTrue();
|
||||||
// P1 Silver takes P2 Bishop
|
// P1 Silver takes P2 Bishop
|
||||||
shogi.Move("C1", "B2", false);
|
shogi.Move("C1", "B2", false).IsSuccess.Should().BeTrue();
|
||||||
// P2 Pawn, arbtrary move
|
// P2 Pawn, arbtrary move
|
||||||
shogi.Move("A7", "A6", false);
|
shogi.Move("A7", "A6", false).IsSuccess.Should().BeTrue();
|
||||||
// P1 drop Bishop, place P2 in check
|
// P1 drop Bishop, place P2 in check
|
||||||
shogi.Move(WhichPiece.Bishop, "G7");
|
shogi.Move(WhichPiece.Bishop, "G7").IsSuccess.Should().BeTrue();
|
||||||
shogi.BoardState.InCheck.Should().Be(WhichPlayer.Player2);
|
shogi.BoardState.InCheck.Should().Be(WhichPlayer.Player2);
|
||||||
shogi.BoardState.Player2Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Bishop);
|
shogi.BoardState.Player2Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Bishop);
|
||||||
shogi.BoardState["E5"].Should().BeNull();
|
shogi.BoardState["E5"].Should().BeNull();
|
||||||
|
|||||||
Reference in New Issue
Block a user