Finish logic around placing pieces from the hand.

This commit is contained in:
2023-02-03 18:22:05 -06:00
parent dbdaaf8b30
commit 6a600bf2f7
5 changed files with 289 additions and 265 deletions

View File

@@ -1,5 +1,6 @@
using Shogi.Domain.ValueObjects;
using System;
using System.Linq;
namespace Shogi.Domain.UnitTests
{
@@ -299,15 +300,16 @@ namespace Shogi.Domain.UnitTests
shogi.Move("A7", "A6", false);
// P1 drop Bishop, place P2 in check
shogi.Move(WhichPiece.Bishop, "G7");
shogi.BoardState.InCheck.Should().Be(WhichPlayer.Player2);
shogi.BoardState.Player2Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Bishop);
shogi.BoardState["E5"].Should().BeNull();
// Act - P2 places a Bishop while in check.
shogi.Move(WhichPiece.Bishop, "E5");
var act = () => shogi.Move(WhichPiece.Bishop, "E5");
// Assert
using var scope = new AssertionScope();
act.Should().Throw<InvalidOperationException>();
shogi.BoardState["E5"].Should().BeNull();
shogi.BoardState.InCheck.Should().Be(WhichPlayer.Player2);
shogi.BoardState.Player2Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Bishop);
@@ -326,25 +328,21 @@ namespace Shogi.Domain.UnitTests
shogi.Move("B2", "H8", false);
// P2 Pawn
shogi.Move("G6", "G5", false);
using (new AssertionScope())
{
shogi.BoardState.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Bishop);
shogi.BoardState["I9"].Should().NotBeNull();
shogi.BoardState["I9"]!.WhichPiece.Should().Be(WhichPiece.Lance);
shogi.BoardState["I9"]!.Owner.Should().Be(WhichPlayer.Player2);
}
shogi.BoardState.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Bishop);
shogi.BoardState["I9"].Should().NotBeNull();
shogi.BoardState["I9"]!.WhichPiece.Should().Be(WhichPiece.Lance);
shogi.BoardState["I9"]!.Owner.Should().Be(WhichPlayer.Player2);
// Act - P1 tries to place a piece where an opponent's piece resides.
shogi.Move(WhichPiece.Bishop, "I9");
var act = () => shogi.Move(WhichPiece.Bishop, "I9");
// Assert
using (new AssertionScope())
{
shogi.BoardState.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Bishop);
shogi.BoardState["I9"].Should().NotBeNull();
shogi.BoardState["I9"]!.WhichPiece.Should().Be(WhichPiece.Lance);
shogi.BoardState["I9"]!.Owner.Should().Be(WhichPlayer.Player2);
}
using var scope = new AssertionScope();
act.Should().Throw<InvalidOperationException>();
shogi.BoardState.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Bishop);
shogi.BoardState["I9"].Should().NotBeNull();
shogi.BoardState["I9"]!.WhichPiece.Should().Be(WhichPiece.Lance);
shogi.BoardState["I9"]!.Owner.Should().Be(WhichPlayer.Player2);
}
[Fact]
@@ -446,6 +444,7 @@ namespace Shogi.Domain.UnitTests
// Assert - checkmate
console.WriteLine(shogi.ToStringStateAsAscii());
console.WriteLine(string.Join(",", shogi.BoardState.Player1Hand.Select(p => p.WhichPiece.ToString())));
board.IsCheckmate.Should().BeTrue();
board.InCheck.Should().Be(WhichPlayer.Player2);
}