This commit is contained in:
2021-03-03 07:33:12 -06:00
parent 2e976c01e9
commit e64f75e3cc
7 changed files with 90 additions and 12 deletions

View File

@@ -81,6 +81,24 @@ namespace Gameboard.ShogiUI.UnitTests.BoardState
shogi.Board[0, 3].WhichPiece.Should().Be(WhichPiece.Pawn);
}
[TestMethod]
public void PreventInvalidMoves_MoveFromEmptyPosition()
{
// Arrange
var shogi = new ShogiBoard();
// Prerequisit
shogi.Board[4, 4].Should().BeNull();
// Act
var moveSuccess = shogi.Move(new Move { From = new Vector2(4, 4), To = new Vector2(4, 5) });
// Assert
moveSuccess.Should().BeFalse();
shogi.Board[4, 4].Should().BeNull();
shogi.Board[4, 5].Should().BeNull();
}
[TestMethod]
public void PreventInvalidMoves_MoveToCurrentPosition()
{
@@ -193,6 +211,66 @@ namespace Gameboard.ShogiUI.UnitTests.BoardState
shogi.Board[8, 7].Should().BeNull();
}
[TestMethod]
public void PreventInvalidDrops_MoveSet()
{
// Arrange
var moves = new[]
{
// P1 Pawn
new Move { From = new Vector2(2, 2), To = new Vector2(2, 3) },
// P2 Pawn
new Move { From = new Vector2(0, 6), To = new Vector2(0, 5) },
// P1 Bishop takes P2 Pawn
new Move { From = new Vector2(1, 1), To = new Vector2(6, 6) },
// P2 Gold, block check from P1 Bishop.
new Move { From = new Vector2(5, 8), To = new Vector2(5, 7) },
// P1 Bishop takes P2 Bishop, promotes so it can capture P2 Knight and P2 Lance
new Move { From = new Vector2(6, 6), To = new Vector2(7, 7), IsPromotion = true },
// P2 Pawn again
new Move { From = new Vector2(0, 5), To = new Vector2(0, 4) },
// P1 Bishop takes P2 Knight
new Move { From = new Vector2(7, 7), To = new Vector2(7, 8) },
// P2 Pawn again
new Move { From = new Vector2(0, 4), To = new Vector2(0, 3) },
// P1 Bishop takes P2 Lance
new Move { From = new Vector2(7, 8), To = new Vector2(8, 8) },
// P2 Lance (move to make room for attempted P1 Pawn placement)
new Move { From = new Vector2(0, 8), To = new Vector2(0, 7) },
// P1 arbitrary move
new Move { From = new Vector2(4, 0), To = new Vector2(4, 1) },
// P2 Pawn again, takes P1 Pawn
new Move { From = new Vector2(0, 3), To = new Vector2(0, 2) },
};
var shogi = new ShogiBoard(moves);
shogi.PrintStateAsAscii();
// Prerequisite
shogi.Hands[WhichPlayer.Player1].Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Knight);
shogi.Hands[WhichPlayer.Player1].Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Lance);
shogi.Hands[WhichPlayer.Player1].Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Pawn);
// Act | Assert - It is P1 turn
// try illegally placing Knight from the hand.
shogi.Board[7, 8].Should().BeNull();
var moveSuccess = shogi.Move(new Move { PieceFromCaptured = WhichPiece.Knight, To = new Vector2(7, 8) });
shogi.PrintStateAsAscii();
moveSuccess.Should().BeFalse();
shogi.Hands[WhichPlayer.Player1].Should().ContainSingle(_ => _.WhichPiece == WhichPiece.Lance);
shogi.Board[7, 8].Should().BeNull();
// Assert
//var pawnDropSuccess = shogi.Move(new Move)
// Assert
}
[TestMethod]
public void PreventInvalidDrop_Check()
{
}
[TestMethod]
public void Check()
{
@@ -316,16 +394,10 @@ namespace Gameboard.ShogiUI.UnitTests.BoardState
// Act - P1 Pawn wins by checkmate.
var moveSuccess = shogi.Move(new Move { From = new Vector2(4, 6), To = new Vector2(4, 7) });
Console.WriteLine("Checkmate");
shogi.PrintStateAsAscii();
shogi.Move(new Move { From = new Vector2(4, 8), To = new Vector2(4, 7) });
shogi.PrintStateAsAscii();
// Assert
// Assert - checkmate
moveSuccess.Should().BeTrue();
shogi.IsCheckmate.Should().BeTrue();
}
}
}