Turn on remaining shogi domain tests.

This commit is contained in:
2023-02-02 19:45:02 -06:00
parent 09b52eddff
commit dbdaaf8b30

View File

@@ -3,461 +3,453 @@ using System;
namespace Shogi.Domain.UnitTests namespace Shogi.Domain.UnitTests
{ {
public class ShogiShould public class ShogiShould
{ {
private readonly ITestOutputHelper console; private readonly ITestOutputHelper console;
public ShogiShould(ITestOutputHelper console) public ShogiShould(ITestOutputHelper console)
{ {
this.console = console; this.console = console;
} }
[Fact] [Fact]
public void MoveAPieceToAnEmptyPosition() public void MoveAPieceToAnEmptyPosition()
{ {
// Arrange // Arrange
var shogi = MockShogiBoard(); var shogi = MockShogiBoard();
var board = shogi.BoardState; var board = shogi.BoardState;
board["A4"].Should().BeNull(); board["A4"].Should().BeNull();
var expectedPiece = board["A3"]; var expectedPiece = board["A3"];
expectedPiece.Should().NotBeNull(); expectedPiece.Should().NotBeNull();
// Act // Act
shogi.Move("A3", "A4", false); shogi.Move("A3", "A4", false);
// Assert // Assert
board["A3"].Should().BeNull(); board["A3"].Should().BeNull();
board["A4"].Should().Be(expectedPiece); board["A4"].Should().Be(expectedPiece);
} }
[Fact] [Fact]
public void AllowValidMoves_AfterCheck() public void AllowValidMoves_AfterCheck()
{ {
// Arrange // Arrange
var shogi = MockShogiBoard(); var shogi = MockShogiBoard();
var board = shogi.BoardState; var board = shogi.BoardState;
// P1 Pawn // P1 Pawn
shogi.Move("C3", "C4", false); shogi.Move("C3", "C4", false);
// P2 Pawn // P2 Pawn
shogi.Move("G7", "G6", false); shogi.Move("G7", "G6", false);
// P1 Bishop puts P2 in check // P1 Bishop puts P2 in check
shogi.Move("B2", "G7", false); shogi.Move("B2", "G7", false);
board.InCheck.Should().Be(WhichPlayer.Player2); board.InCheck.Should().Be(WhichPlayer.Player2);
// Act - P2 is able to un-check theirself. // Act - P2 is able to un-check theirself.
/// P2 King moves out of check /// P2 King moves out of check
shogi.Move("E9", "E8", false); shogi.Move("E9", "E8", false);
// Assert // Assert
using (new AssertionScope()) using (new AssertionScope())
{ {
board.InCheck.Should().BeNull(); board.InCheck.Should().BeNull();
} }
} }
[Fact] [Fact]
public void PreventInvalidMoves_MoveFromEmptyPosition() public void PreventInvalidMoves_MoveFromEmptyPosition()
{ {
// Arrange // Arrange
var shogi = MockShogiBoard(); var shogi = MockShogiBoard();
var board = shogi.BoardState; var board = shogi.BoardState;
board["D5"].Should().BeNull(); board["D5"].Should().BeNull();
// Act // Act
var act = () => shogi.Move("D5", "D6", false); var act = () => shogi.Move("D5", "D6", false);
// Assert // Assert
act.Should().Throw<InvalidOperationException>(); act.Should().Throw<InvalidOperationException>();
board["D5"].Should().BeNull(); board["D5"].Should().BeNull();
board["D6"].Should().BeNull(); board["D6"].Should().BeNull();
board.Player1Hand.Should().BeEmpty(); board.Player1Hand.Should().BeEmpty();
board.Player2Hand.Should().BeEmpty(); board.Player2Hand.Should().BeEmpty();
} }
[Fact] [Fact]
public void PreventInvalidMoves_MoveToCurrentPosition() public void PreventInvalidMoves_MoveToCurrentPosition()
{ {
// Arrange // Arrange
var shogi = MockShogiBoard(); var shogi = MockShogiBoard();
var board = shogi.BoardState; var board = shogi.BoardState;
var expectedPiece = board["A3"]; var expectedPiece = board["A3"];
// Act - P1 "moves" pawn to the position it already exists at. // Act - P1 "moves" pawn to the position it already exists at.
var act = () => shogi.Move("A3", "A3", false); var act = () => shogi.Move("A3", "A3", false);
// Assert // Assert
using (new AssertionScope()) using (new AssertionScope())
{ {
act.Should().Throw<InvalidOperationException>(); act.Should().Throw<InvalidOperationException>();
board["A3"].Should().Be(expectedPiece); board["A3"].Should().Be(expectedPiece);
board.Player1Hand.Should().BeEmpty(); board.Player1Hand.Should().BeEmpty();
board.Player2Hand.Should().BeEmpty(); board.Player2Hand.Should().BeEmpty();
} }
} }
[Fact] [Fact]
public void PreventInvalidMoves_MoveSet() public void PreventInvalidMoves_MoveSet()
{ {
// Arrange // Arrange
var shogi = MockShogiBoard(); var shogi = MockShogiBoard();
var board = shogi.BoardState; var board = shogi.BoardState;
var expectedPiece = board["A1"]; var expectedPiece = board["A1"];
expectedPiece!.WhichPiece.Should().Be(WhichPiece.Lance); expectedPiece!.WhichPiece.Should().Be(WhichPiece.Lance);
// Act - Move Lance illegally // Act - Move Lance illegally
var act = () => shogi.Move("A1", "D5", false); var act = () => shogi.Move("A1", "D5", false);
// Assert // Assert
using (new AssertionScope()) using (new AssertionScope())
{ {
act.Should().Throw<InvalidOperationException>(); act.Should().Throw<InvalidOperationException>();
board["A1"].Should().Be(expectedPiece); board["A1"].Should().Be(expectedPiece);
board["A5"].Should().BeNull(); board["A5"].Should().BeNull();
board.Player1Hand.Should().BeEmpty(); board.Player1Hand.Should().BeEmpty();
board.Player2Hand.Should().BeEmpty(); board.Player2Hand.Should().BeEmpty();
} }
} }
[Fact] [Fact]
public void PreventInvalidMoves_Ownership() public void PreventInvalidMoves_Ownership()
{ {
// Arrange // Arrange
var shogi = MockShogiBoard(); var shogi = MockShogiBoard();
var board = shogi.BoardState; var board = shogi.BoardState;
var expectedPiece = board["A7"]; var expectedPiece = board["A7"];
expectedPiece!.Owner.Should().Be(WhichPlayer.Player2); expectedPiece!.Owner.Should().Be(WhichPlayer.Player2);
board.WhoseTurn.Should().Be(WhichPlayer.Player1); board.WhoseTurn.Should().Be(WhichPlayer.Player1);
// Act - Move Player2 Pawn when it is Player1 turn. // Act - Move Player2 Pawn when it is Player1 turn.
var act = () => shogi.Move("A7", "A6", false); var act = () => shogi.Move("A7", "A6", false);
// Assert // Assert
using (new AssertionScope()) using (new AssertionScope())
{ {
act.Should().Throw<InvalidOperationException>(); act.Should().Throw<InvalidOperationException>();
board["A7"].Should().Be(expectedPiece); board["A7"].Should().Be(expectedPiece);
board["A6"].Should().BeNull(); board["A6"].Should().BeNull();
} }
} }
[Fact] [Fact]
public void PreventInvalidMoves_MoveThroughAllies() public void PreventInvalidMoves_MoveThroughAllies()
{ {
// Arrange // Arrange
var shogi = MockShogiBoard(); var shogi = MockShogiBoard();
var board = shogi.BoardState; var board = shogi.BoardState;
var lance = board["A1"]; var lance = board["A1"];
var pawn = board["A3"]; var pawn = board["A3"];
lance!.Owner.Should().Be(pawn!.Owner); lance!.Owner.Should().Be(pawn!.Owner);
// Act - Move P1 Lance through P1 Pawn. // Act - Move P1 Lance through P1 Pawn.
var act = () => shogi.Move("A1", "A5", false); var act = () => shogi.Move("A1", "A5", false);
// Assert // Assert
using (new AssertionScope()) using (new AssertionScope())
{ {
act.Should().Throw<InvalidOperationException>(); act.Should().Throw<InvalidOperationException>();
board["A1"].Should().Be(lance); board["A1"].Should().Be(lance);
board["A3"].Should().Be(pawn); board["A3"].Should().Be(pawn);
board["A5"].Should().BeNull(); board["A5"].Should().BeNull();
} }
} }
[Fact] [Fact]
public void PreventInvalidMoves_CaptureAlly() public void PreventInvalidMoves_CaptureAlly()
{ {
// Arrange // Arrange
var shogi = MockShogiBoard(); var shogi = MockShogiBoard();
var board = shogi.BoardState; var board = shogi.BoardState;
var knight = board["B1"]; var knight = board["B1"];
var pawn = board["C3"]; var pawn = board["C3"];
knight!.Owner.Should().Be(pawn!.Owner); knight!.Owner.Should().Be(pawn!.Owner);
// Act - P1 Knight tries to capture P1 Pawn. // Act - P1 Knight tries to capture P1 Pawn.
var act = () => shogi.Move("B1", "C3", false); var act = () => shogi.Move("B1", "C3", false);
// Arrange // Arrange
using (new AssertionScope()) using (new AssertionScope())
{ {
act.Should().Throw<InvalidOperationException>(); act.Should().Throw<InvalidOperationException>();
board["B1"].Should().Be(knight); board["B1"].Should().Be(knight);
board["C3"].Should().Be(pawn); board["C3"].Should().Be(pawn);
board.Player1Hand.Should().BeEmpty(); board.Player1Hand.Should().BeEmpty();
board.Player2Hand.Should().BeEmpty(); board.Player2Hand.Should().BeEmpty();
} }
} }
[Fact] [Fact]
public void PreventInvalidMoves_Check() public void PreventInvalidMoves_Check()
{ {
// Arrange // Arrange
var shogi = MockShogiBoard(); var shogi = MockShogiBoard();
var board = shogi.BoardState; var board = shogi.BoardState;
// P1 Pawn // P1 Pawn
shogi.Move("C3", "C4", false); shogi.Move("C3", "C4", false);
// P2 Pawn // P2 Pawn
shogi.Move("G7", "G6", false); shogi.Move("G7", "G6", false);
// P1 Bishop puts P2 in check // P1 Bishop puts P2 in check
shogi.Move("B2", "G7", false); shogi.Move("B2", "G7", false);
board.InCheck.Should().Be(WhichPlayer.Player2); board.InCheck.Should().Be(WhichPlayer.Player2);
var lance = board["I9"]; var lance = board["I9"];
// Act - P2 moves Lance while in check. // Act - P2 moves Lance while in check.
var act = () => shogi.Move("I9", "I8", false); var act = () => shogi.Move("I9", "I8", false);
// Assert // Assert
using (new AssertionScope()) using (new AssertionScope())
{ {
act.Should().Throw<InvalidOperationException>(); act.Should().Throw<InvalidOperationException>();
board.InCheck.Should().Be(WhichPlayer.Player2); board.InCheck.Should().Be(WhichPlayer.Player2);
board["I9"].Should().Be(lance); board["I9"].Should().Be(lance);
board["I8"].Should().BeNull(); board["I8"].Should().BeNull();
} }
} }
[Fact] [Fact]
// TODO: Consider nesting classes to share this setup in a constructor but have act and assert as separate facts. public void PreventInvalidDrops_MoveSet()
public void PreventInvalidDrops_MoveSet() {
{ // Arrange
// Arrange var shogi = MockShogiBoard();
var shogi = MockShogiBoard(); var board = shogi.BoardState;
var board = shogi.BoardState; // P1 Pawn
// P1 Pawn shogi.Move("C3", "C4", false);
shogi.Move("C3", "C4", false); // P2 Pawn
// P2 Pawn shogi.Move("I7", "I6", false);
shogi.Move("I7", "I6", false); // P1 Bishop takes P2 Pawn.
// P1 Bishop takes P2 Pawn. shogi.Move("B2", "G7", false);
shogi.Move("B2", "G7", false); // P2 Gold, block check from P1 Bishop.
// P2 Gold, block check from P1 Bishop. shogi.Move("F9", "F8", false);
shogi.Move("F9", "F8", false); // P1 Bishop takes P2 Bishop, promotes so it can capture P2 Knight and P2 Lance
// P1 Bishop takes P2 Bishop, promotes so it can capture P2 Knight and P2 Lance shogi.Move("G7", "H8", true);
shogi.Move("G7", "H8", true); // P2 Pawn again
// P2 Pawn again shogi.Move("I6", "I5", false);
shogi.Move("I6", "I5", false); // P1 Bishop takes P2 Knight
// P1 Bishop takes P2 Knight shogi.Move("H8", "H9", false);
shogi.Move("H8", "H9", false); // P2 Pawn again
// P2 Pawn again shogi.Move("I5", "I4", false);
shogi.Move("I5", "I4", false); // P1 Bishop takes P2 Lance
// P1 Bishop takes P2 Lance shogi.Move("H9", "I9", false);
shogi.Move("H9", "I9", false); // P2 Pawn captures P1 Pawn
// P2 Pawn captures P1 Pawn shogi.Move("I4", "I3", false);
shogi.Move("I4", "I3", false); board.Player1Hand.Count.Should().Be(4);
board.Player1Hand.Count.Should().Be(4); board.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Knight);
board.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Knight); board.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Lance);
board.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Lance); board.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Pawn);
board.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Pawn); board.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Bishop);
board.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Bishop); board.WhoseTurn.Should().Be(WhichPlayer.Player1);
board.WhoseTurn.Should().Be(WhichPlayer.Player1);
// Act | Assert - Illegally placing Knight from the hand in farthest rank. // Act | Assert - Illegally placing Knight from the hand in farthest rank.
board["H9"].Should().BeNull(); board["H9"].Should().BeNull();
var act = () => shogi.Move(WhichPiece.Knight, "H9"); var act = () => shogi.Move(WhichPiece.Knight, "H9");
act.Should().Throw<InvalidOperationException>(); act.Should().Throw<InvalidOperationException>();
board["H9"].Should().BeNull(); board["H9"].Should().BeNull();
board.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Knight); board.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Knight);
// Act | Assert - Illegally placing Knight from the hand in second farthest row. // Act | Assert - Illegally placing Knight from the hand in second farthest row.
board["H8"].Should().BeNull(); board["H8"].Should().BeNull();
act = () => shogi.Move(WhichPiece.Knight, "H8"); act = () => shogi.Move(WhichPiece.Knight, "H8");
act.Should().Throw<InvalidOperationException>(); act.Should().Throw<InvalidOperationException>();
board["H8"].Should().BeNull(); board["H8"].Should().BeNull();
board.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Knight); board.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Knight);
// Act | Assert - Illegally place Lance from the hand. // Act | Assert - Illegally place Lance from the hand.
board["H9"].Should().BeNull(); board["H9"].Should().BeNull();
act = () => shogi.Move(WhichPiece.Knight, "H9"); act = () => shogi.Move(WhichPiece.Knight, "H9");
act.Should().Throw<InvalidOperationException>(); act.Should().Throw<InvalidOperationException>();
board["H9"].Should().BeNull(); board["H9"].Should().BeNull();
board.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Lance); board.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Lance);
// Act | Assert - Illegally place Pawn from the hand. // Act | Assert - Illegally place Pawn from the hand.
board["H9"].Should().BeNull(); board["H9"].Should().BeNull();
act = () => shogi.Move(WhichPiece.Pawn, "H9"); act = () => shogi.Move(WhichPiece.Pawn, "H9");
act.Should().Throw<InvalidOperationException>(); act.Should().Throw<InvalidOperationException>();
board["H9"].Should().BeNull(); board["H9"].Should().BeNull();
board.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Pawn); board.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Pawn);
// // Act | Assert - Illegally place Pawn from the hand in a row which already has an unpromoted Pawn. // // Act | Assert - Illegally place Pawn from the hand in a row which already has an unpromoted Pawn.
// // TODO // // TODO
} }
//[Fact] [Fact]
//public void PreventInvalidDrop_Check() public void PreventInvalidDrop_Check()
//{ {
// // Arrange // Arrange
// var moves = new[] var shogi = MockShogiBoard();
// { // P1 Pawn
// // P1 Pawn shogi.Move("C3", "C4", false);
// new Move("C3", "C4"), // P2 Pawn
// // P2 Pawn shogi.Move("G7", "G6", false);
// new Move("G7", "G6"), // P1 Pawn, arbitrary move.
// // P1 Pawn, arbitrary move. shogi.Move("A3", "A4", false);
// new Move("A3", "A4"), // P2 Bishop takes P1 Bishop
// // P2 Bishop takes P1 Bishop shogi.Move("H8", "B2", false);
// new Move("H8", "B2"), // P1 Silver takes P2 Bishop
// // P1 Silver takes P2 Bishop shogi.Move("C1", "B2", false);
// new Move("C1", "B2"), // P2 Pawn, arbtrary move
// // P2 Pawn, arbtrary move shogi.Move("A7", "A6", false);
// new Move("A7", "A6"), // P1 drop Bishop, place P2 in check
// // P1 drop Bishop, place P2 in check shogi.Move(WhichPiece.Bishop, "G7");
// new Move(WhichPiece.Bishop, "G7")
// };
// var shogi = new Shogi(moves);
// shogi.InCheck.Should().Be(WhichPlayer.Player2);
// shogi.Player2Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Bishop);
// board["E5"].Should().BeNull();
// // Act - P2 places a Bishop while in check. shogi.BoardState.InCheck.Should().Be(WhichPlayer.Player2);
// var dropSuccess = shogi.Move(new Move(WhichPiece.Bishop, "E5")); shogi.BoardState.Player2Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Bishop);
shogi.BoardState["E5"].Should().BeNull();
// // Assert // Act - P2 places a Bishop while in check.
// dropSuccess.Should().BeFalse(); shogi.Move(WhichPiece.Bishop, "E5");
// board["E5"].Should().BeNull();
// shogi.InCheck.Should().Be(WhichPlayer.Player2);
// shogi.Player2Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Bishop);
//}
//[Fact] // Assert
//public void PreventInvalidDrop_Capture() shogi.BoardState["E5"].Should().BeNull();
//{ shogi.BoardState.InCheck.Should().Be(WhichPlayer.Player2);
// // Arrange shogi.BoardState.Player2Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Bishop);
// var moves = new[] }
// {
// // P1 Pawn
// new Move("C3", "C4"),
// // P2 Pawn
// new Move("G7", "G6"),
// // P1 Bishop capture P2 Bishop
// new Move("B2", "H8"),
// // P2 Pawn
// new Move("G6", "G5")
// };
// var shogi = new Shogi(moves);
// using (new AssertionScope())
// {
// shogi.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Bishop);
// board["I9"].Should().NotBeNull();
// board["I9"].WhichPiece.Should().Be(WhichPiece.Lance);
// board["I9"].Owner.Should().Be(WhichPlayer.Player2);
// }
// // Act - P1 tries to place a piece where an opponent's piece resides. [Fact]
// var dropSuccess = shogi.Move(new Move(WhichPiece.Bishop, "I9")); public void PreventInvalidDrop_Capture()
{
// Arrange
var shogi = MockShogiBoard();
// P1 Pawn
shogi.Move("C3", "C4", false);
// P2 Pawn
shogi.Move("G7", "G6", false);
// P1 Bishop capture P2 Bishop
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);
}
// // Assert // Act - P1 tries to place a piece where an opponent's piece resides.
// using (new AssertionScope()) shogi.Move(WhichPiece.Bishop, "I9");
// {
// dropSuccess.Should().BeFalse();
// shogi.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Bishop);
// board["I9"].Should().NotBeNull();
// board["I9"].WhichPiece.Should().Be(WhichPiece.Lance);
// board["I9"].Owner.Should().Be(WhichPlayer.Player2);
// }
//}
[Fact] // Assert
public void Check() using (new AssertionScope())
{ {
// Arrange shogi.BoardState.Player1Hand.Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Bishop);
var shogi = MockShogiBoard(); shogi.BoardState["I9"].Should().NotBeNull();
var board = shogi.BoardState; shogi.BoardState["I9"]!.WhichPiece.Should().Be(WhichPiece.Lance);
// P1 Pawn shogi.BoardState["I9"]!.Owner.Should().Be(WhichPlayer.Player2);
shogi.Move("C3", "C4", false); }
// P2 Pawn }
shogi.Move("G7", "G6", false);
// Act - P1 Bishop, check [Fact]
shogi.Move("B2", "G7", false); public void Check()
{
// Arrange
var shogi = MockShogiBoard();
var board = shogi.BoardState;
// P1 Pawn
shogi.Move("C3", "C4", false);
// P2 Pawn
shogi.Move("G7", "G6", false);
// Assert // Act - P1 Bishop, check
board.InCheck.Should().Be(WhichPlayer.Player2); shogi.Move("B2", "G7", false);
}
[Fact] // Assert
public void Promote() board.InCheck.Should().Be(WhichPlayer.Player2);
{ }
// Arrange
var shogi = MockShogiBoard();
var board = shogi.BoardState;
// P1 Pawn
shogi.Move("C3", "C4", false);
// P2 Pawn
shogi.Move("G7", "G6", false);
// Act - P1 moves across promote threshold. [Fact]
shogi.Move("B2", "G7", true); public void Promote()
{
// Arrange
var shogi = MockShogiBoard();
var board = shogi.BoardState;
// P1 Pawn
shogi.Move("C3", "C4", false);
// P2 Pawn
shogi.Move("G7", "G6", false);
// Assert // Act - P1 moves across promote threshold.
using (new AssertionScope()) shogi.Move("B2", "G7", true);
{
board["B2"].Should().BeNull();
board["G7"].Should().NotBeNull();
board["G7"]!.WhichPiece.Should().Be(WhichPiece.Bishop);
board["G7"]!.Owner.Should().Be(WhichPlayer.Player1);
board["G7"]!.IsPromoted.Should().BeTrue();
}
}
[Fact] // Assert
public void Capture() using (new AssertionScope())
{ {
// Arrange board["B2"].Should().BeNull();
var shogi = MockShogiBoard(); board["G7"].Should().NotBeNull();
var board = shogi.BoardState; board["G7"]!.WhichPiece.Should().Be(WhichPiece.Bishop);
var p1Bishop = board["B2"]; board["G7"]!.Owner.Should().Be(WhichPlayer.Player1);
p1Bishop!.WhichPiece.Should().Be(WhichPiece.Bishop); board["G7"]!.IsPromoted.Should().BeTrue();
shogi.Move("C3", "C4", false); }
shogi.Move("G7", "G6", false); }
// Act - P1 Bishop captures P2 Bishop [Fact]
shogi.Move("B2", "H8", false); public void Capture()
{
// Arrange
var shogi = MockShogiBoard();
var board = shogi.BoardState;
var p1Bishop = board["B2"];
p1Bishop!.WhichPiece.Should().Be(WhichPiece.Bishop);
shogi.Move("C3", "C4", false);
shogi.Move("G7", "G6", false);
// Assert // Act - P1 Bishop captures P2 Bishop
board["B2"].Should().BeNull(); shogi.Move("B2", "H8", false);
board["H8"].Should().Be(p1Bishop);
board // Assert
.Player1Hand board["B2"].Should().BeNull();
.Should() board["H8"].Should().Be(p1Bishop);
.ContainSingle(p => p.WhichPiece == WhichPiece.Bishop && p.Owner == WhichPlayer.Player1);
}
[Fact] board
public void CheckMate() .Player1Hand
{ .Should()
// Arrange .ContainSingle(p => p.WhichPiece == WhichPiece.Bishop && p.Owner == WhichPlayer.Player1);
var shogi = MockShogiBoard(); }
var board = shogi.BoardState;
// P1 Rook
shogi.Move("H2", "E2", false);
// P2 Gold
shogi.Move("F9", "G8", false);
// P1 Pawn
shogi.Move("E3", "E4", false);
// P2 other Gold
shogi.Move("D9", "C8", false);
// P1 same Pawn
shogi.Move("E4", "E5", false);
// P2 Pawn
shogi.Move("E7", "E6", false);
// P1 Pawn takes P2 Pawn
shogi.Move("E5", "E6", false);
// P2 King
shogi.Move("E9", "E8", false);
// P1 Pawn promotes; threatens P2 King
shogi.Move("E6", "E7", true);
// P2 King retreat
shogi.Move("E8", "E9", false);
// Act - P1 Pawn wins by checkmate. [Fact]
shogi.Move("E7", "E8", false); public void CheckMate()
{
// Arrange
var shogi = MockShogiBoard();
var board = shogi.BoardState;
// P1 Rook
shogi.Move("H2", "E2", false);
// P2 Gold
shogi.Move("F9", "G8", false);
// P1 Pawn
shogi.Move("E3", "E4", false);
// P2 other Gold
shogi.Move("D9", "C8", false);
// P1 same Pawn
shogi.Move("E4", "E5", false);
// P2 Pawn
shogi.Move("E7", "E6", false);
// P1 Pawn takes P2 Pawn
shogi.Move("E5", "E6", false);
// P2 King
shogi.Move("E9", "E8", false);
// P1 Pawn promotes; threatens P2 King
shogi.Move("E6", "E7", true);
// P2 King retreat
shogi.Move("E8", "E9", false);
// Assert - checkmate // Act - P1 Pawn wins by checkmate.
console.WriteLine(shogi.ToStringStateAsAscii()); shogi.Move("E7", "E8", false);
board.IsCheckmate.Should().BeTrue();
board.InCheck.Should().Be(WhichPlayer.Player2);
}
private static ShogiBoard MockShogiBoard() => new(BoardState.StandardStarting); // Assert - checkmate
} console.WriteLine(shogi.ToStringStateAsAscii());
board.IsCheckmate.Should().BeTrue();
board.InCheck.Should().Be(WhichPlayer.Player2);
}
private static ShogiBoard MockShogiBoard() => new(BoardState.StandardStarting);
}
} }