@@ -1,41 +1,15 @@
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Shogi.Domain.UnitTests")]
|
||||
namespace Shogi.Domain
|
||||
{
|
||||
internal class StandardRules
|
||||
{
|
||||
/// <param name="element">Guaranteed to be non-null.</param>
|
||||
/// <param name="position"></param>
|
||||
public delegate void Callback(Piece collider, Vector2 position);
|
||||
private readonly ShogiBoardState boardState;
|
||||
|
||||
private readonly ShogiBoardState board;
|
||||
private Vector2 player1KingPosition;
|
||||
private Vector2 player2KingPosition;
|
||||
|
||||
public StandardRules(ShogiBoardState board)
|
||||
internal StandardRules(ShogiBoardState board)
|
||||
{
|
||||
this.board = board;
|
||||
CacheKingPositions();
|
||||
}
|
||||
|
||||
private void CacheKingPositions()
|
||||
{
|
||||
this.board.ForEachNotNull((tile, position) =>
|
||||
{
|
||||
if (tile.WhichPiece == WhichPiece.King)
|
||||
{
|
||||
if (tile.Owner == WhichPlayer.Player1)
|
||||
{
|
||||
player1KingPosition = position;
|
||||
}
|
||||
else if (tile.Owner == WhichPlayer.Player2)
|
||||
{
|
||||
player2KingPosition = position;
|
||||
}
|
||||
}
|
||||
});
|
||||
this.boardState = board;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -43,82 +17,64 @@ namespace Shogi.Domain
|
||||
/// </summary>
|
||||
/// <param name="fromNotation">The position of the piece being moved expressed in board notation.</param>
|
||||
/// <param name="toNotation">The target position expressed in board notation.</param>
|
||||
/// <param name="isPromotionRequested">True if a promotion is expected as a result of this move.</param>
|
||||
/// <returns>A <see cref="MoveResult" /> describing the success or failure of the move.</returns>
|
||||
public MoveResult Move(string fromNotation, string toNotation, bool isPromotion = false)
|
||||
internal MoveResult Move(string fromNotation, string toNotation, bool isPromotionRequested = false)
|
||||
{
|
||||
var from = ShogiBoardState.FromBoardNotation(fromNotation);
|
||||
var to = ShogiBoardState.FromBoardNotation(toNotation);
|
||||
var fromPiece = board[from];
|
||||
var fromPiece = boardState[from];
|
||||
if (fromPiece == null)
|
||||
{
|
||||
return new MoveResult(false, $"Tile [{fromNotation}] is empty. There is no piece to move.");
|
||||
}
|
||||
|
||||
if (fromPiece.Owner != board.WhoseTurn)
|
||||
if (fromPiece.Owner != boardState.WhoseTurn)
|
||||
{
|
||||
return new MoveResult(false, "Not allowed to move the opponents piece");
|
||||
}
|
||||
|
||||
if (ShogiIsPathable(from, to) == false)
|
||||
var path = fromPiece.GetPathFromStartToEnd(from, to);
|
||||
|
||||
if (boardState.IsPathBlocked(path))
|
||||
{
|
||||
return new MoveResult(false, $"Proposed move is not part of the move-set for piece {fromPiece.WhichPiece}.");
|
||||
return new MoveResult(false, "Another piece obstructs the desired move.");
|
||||
}
|
||||
|
||||
var captured = board[to];
|
||||
if (captured != null)
|
||||
if (boardState[to] != null)
|
||||
{
|
||||
if (captured.Owner == board.WhoseTurn)
|
||||
{
|
||||
return new MoveResult(false, "Capturing your own piece is not allowed.");
|
||||
}
|
||||
captured.Capture();
|
||||
board.Hand.Add(captured);
|
||||
boardState.Capture(to);
|
||||
}
|
||||
|
||||
//Mutate the board.
|
||||
if (isPromotion)
|
||||
if (isPromotionRequested && (boardState.IsWithinPromotionZone(to) || boardState.IsWithinPromotionZone(from)))
|
||||
{
|
||||
if (board.WhoseTurn == WhichPlayer.Player1 && (to.Y > 5 || from.Y > 5))
|
||||
{
|
||||
fromPiece.Promote();
|
||||
}
|
||||
else if (board.WhoseTurn == WhichPlayer.Player2 && (to.Y < 3 || from.Y < 3))
|
||||
{
|
||||
fromPiece.Promote();
|
||||
}
|
||||
fromPiece.Promote();
|
||||
}
|
||||
board[to] = fromPiece;
|
||||
board[from] = null;
|
||||
if (fromPiece.WhichPiece == WhichPiece.King)
|
||||
{
|
||||
if (fromPiece.Owner == WhichPlayer.Player1)
|
||||
{
|
||||
player1KingPosition = from;
|
||||
}
|
||||
else if (fromPiece.Owner == WhichPlayer.Player2)
|
||||
{
|
||||
player2KingPosition = from;
|
||||
}
|
||||
}
|
||||
//MoveHistory.Add(move);
|
||||
|
||||
boardState[to] = fromPiece;
|
||||
boardState[from] = null;
|
||||
|
||||
boardState.RememberAsMostRecentMove(from, to);
|
||||
var otherPlayer = boardState.WhoseTurn == WhichPlayer.Player1 ? WhichPlayer.Player2 : WhichPlayer.Player1;
|
||||
boardState.WhoseTurn = otherPlayer;
|
||||
|
||||
return new MoveResult(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move a piece from the hand to the board ignorant if check or check-mate.
|
||||
/// </summary>
|
||||
/// <param name="pieceInHand"></param>
|
||||
/// <param name="to">The target position expressed in board notation.</param>
|
||||
/// <returns>A <see cref="MoveResult" /> describing the success or failure of the simulation.</returns>
|
||||
public MoveResult Move(WhichPiece pieceInHand, string toNotation)
|
||||
internal MoveResult Move(WhichPiece pieceInHand, string toNotation)
|
||||
{
|
||||
var to = ShogiBoardState.FromBoardNotation(toNotation);
|
||||
var index = board.Hand.FindIndex(p => p.WhichPiece == pieceInHand);
|
||||
var index = boardState.ActivePlayerHand.FindIndex(p => p.WhichPiece == pieceInHand);
|
||||
if (index == -1)
|
||||
{
|
||||
return new MoveResult(false, $"{pieceInHand} does not exist in the hand.");
|
||||
}
|
||||
if (board[to] != null)
|
||||
if (boardState[to] != null)
|
||||
{
|
||||
return new MoveResult(false, $"Illegal move - attempting to capture while playing a piece from the hand.");
|
||||
}
|
||||
@@ -128,8 +84,8 @@ namespace Shogi.Domain
|
||||
case WhichPiece.Knight:
|
||||
{
|
||||
// Knight cannot be placed onto the farthest two ranks from the hand.
|
||||
if ((board.WhoseTurn == WhichPlayer.Player1 && to.Y > 6)
|
||||
|| (board.WhoseTurn == WhichPlayer.Player2 && to.Y < 2))
|
||||
if ((boardState.WhoseTurn == WhichPlayer.Player1 && to.Y > 6)
|
||||
|| (boardState.WhoseTurn == WhichPlayer.Player2 && to.Y < 2))
|
||||
{
|
||||
return new MoveResult(false, "Knight has no valid moves after placed.");
|
||||
}
|
||||
@@ -139,8 +95,8 @@ namespace Shogi.Domain
|
||||
case WhichPiece.Pawn:
|
||||
{
|
||||
// Lance and Pawn cannot be placed onto the farthest rank from the hand.
|
||||
if ((board.WhoseTurn == WhichPlayer.Player1 && to.Y == 8)
|
||||
|| (board.WhoseTurn == WhichPlayer.Player2 && to.Y == 0))
|
||||
if ((boardState.WhoseTurn == WhichPlayer.Player1 && to.Y == 8)
|
||||
|| (boardState.WhoseTurn == WhichPlayer.Player2 && to.Y == 0))
|
||||
{
|
||||
return new MoveResult(false, $"{pieceInHand} has no valid moves after placed.");
|
||||
}
|
||||
@@ -149,262 +105,180 @@ namespace Shogi.Domain
|
||||
}
|
||||
|
||||
// Mutate the board.
|
||||
board[to] = board.Hand[index];
|
||||
board.Hand.RemoveAt(index);
|
||||
boardState[to] = boardState.ActivePlayerHand[index];
|
||||
boardState.ActivePlayerHand.RemoveAt(index);
|
||||
//MoveHistory.Add(move);
|
||||
return new MoveResult(true);
|
||||
}
|
||||
|
||||
private bool ShogiIsPathable(Vector2 from, Vector2 to)
|
||||
/// <summary>
|
||||
/// Determines if the last move put the player who moved in check.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This strategy recognizes that a "discover check" could only occur from a subset of pieces: Rook, Bishop, Lance.
|
||||
/// In this way, only those pieces need to be considered when evaluating if a move placed the moving player in check.
|
||||
/// </remarks>
|
||||
internal bool IsPlayerInCheckAfterMove()
|
||||
{
|
||||
var piece = board[from];
|
||||
if (piece == null) return false;
|
||||
|
||||
var isObstructed = false;
|
||||
var isPathable = PathTo(from, to, (other, position) =>
|
||||
{
|
||||
if (other.Owner == piece.Owner) isObstructed = true;
|
||||
});
|
||||
return !isObstructed && isPathable;
|
||||
}
|
||||
|
||||
public bool EvaluateCheckAfterMove(WhichPiece pieceInHand, Vector2 to, WhichPlayer whichPlayer)
|
||||
{
|
||||
if (whichPlayer == board.InCheck) return true; // If we already know the player is in check, don't bother.
|
||||
var previousMovedPiece = boardState[boardState.PreviousMoveTo];
|
||||
if (previousMovedPiece == null) throw new ArgumentNullException(nameof(previousMovedPiece), $"No piece exists at position {boardState.PreviousMoveTo}.");
|
||||
var kingPosition = previousMovedPiece.Owner == WhichPlayer.Player1 ? boardState.Player1KingPosition : boardState.Player2KingPosition;
|
||||
|
||||
var isCheck = false;
|
||||
var kingPosition = whichPlayer == WhichPlayer.Player1 ? player1KingPosition : player2KingPosition;
|
||||
|
||||
// Check if the move put the king in check.
|
||||
if (PathTo(to, kingPosition)) return true;
|
||||
|
||||
// TODO: Check for illegal move from hand. It is illegal to place from the hand such that you check-mate your opponent.
|
||||
// Go read the shogi rules to be sure this is true.
|
||||
|
||||
return isCheck;
|
||||
}
|
||||
|
||||
public bool IsPlayerInCheckAfterMove(Vector2 from, Vector2 to, WhichPlayer whichPlayer)
|
||||
{
|
||||
if (whichPlayer == board.InCheck) return true; // If we already know the player is in check, don't bother.
|
||||
|
||||
var isCheck = false;
|
||||
var kingPosition = whichPlayer == WhichPlayer.Player1 ? player1KingPosition : player2KingPosition;
|
||||
|
||||
// Check if the move put the king in check.
|
||||
if (PathTo(to, kingPosition)) return true;
|
||||
|
||||
// Get line equation from king through the now-unoccupied location.
|
||||
var direction = Vector2.Subtract(kingPosition, from);
|
||||
var direction = Vector2.Subtract(kingPosition, boardState.PreviousMoveFrom);
|
||||
var slope = Math.Abs(direction.Y / direction.X);
|
||||
var path = ShogiBoardState.GetPathAlongDirectionFromStartToEdgeOfBoard(boardState.PreviousMoveFrom, Vector2.Normalize(direction));
|
||||
var threat = boardState.GetFirstPieceAlongPath(path);
|
||||
if (threat == null || threat.Owner == previousMovedPiece.Owner) return false;
|
||||
// If absolute slope is 45°, look for a bishop along the line.
|
||||
// If absolute slope is 0° or 90°, look for a rook along the line.
|
||||
// if absolute slope is 0°, look for lance along the line.
|
||||
if (float.IsInfinity(slope))
|
||||
{
|
||||
// if slope of the move is also infinity...can skip this?
|
||||
LinePathTo(kingPosition, direction, (piece, position) =>
|
||||
isCheck = threat.WhichPiece switch
|
||||
{
|
||||
if (piece.Owner != whichPlayer)
|
||||
{
|
||||
switch (piece.WhichPiece)
|
||||
{
|
||||
case WhichPiece.Rook:
|
||||
isCheck = true;
|
||||
break;
|
||||
case WhichPiece.Lance:
|
||||
if (!piece.IsPromoted) isCheck = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
WhichPiece.Lance => !threat.IsPromoted,
|
||||
WhichPiece.Rook => true,
|
||||
_ => false
|
||||
};
|
||||
}
|
||||
else if (slope == 1)
|
||||
{
|
||||
LinePathTo(kingPosition, direction, (piece, position) =>
|
||||
isCheck = threat.WhichPiece switch
|
||||
{
|
||||
if (piece.Owner != whichPlayer && piece.WhichPiece == WhichPiece.Bishop)
|
||||
{
|
||||
isCheck = true;
|
||||
}
|
||||
});
|
||||
WhichPiece.Bishop => true,
|
||||
_ => false
|
||||
};
|
||||
}
|
||||
else if (slope == 0)
|
||||
{
|
||||
LinePathTo(kingPosition, direction, (piece, position) =>
|
||||
isCheck = threat.WhichPiece switch
|
||||
{
|
||||
if (piece.Owner != whichPlayer && piece.WhichPiece == WhichPiece.Rook)
|
||||
{
|
||||
isCheck = true;
|
||||
}
|
||||
});
|
||||
WhichPiece.Rook => true,
|
||||
_ => false
|
||||
};
|
||||
}
|
||||
|
||||
return isCheck;
|
||||
}
|
||||
|
||||
public bool EvaluateCheckmate()
|
||||
internal bool IsOpponentInCheckAfterMove() => IsOpposingKingThreatenedByPosition(boardState.PreviousMoveTo);
|
||||
|
||||
internal bool IsOpposingKingThreatenedByPosition(Vector2 position)
|
||||
{
|
||||
if (!board.InCheck.HasValue) return false;
|
||||
var previousMovedPiece = boardState[position];
|
||||
if (previousMovedPiece == null) return false;
|
||||
|
||||
var kingPosition = previousMovedPiece.Owner == WhichPlayer.Player1 ? boardState.Player2KingPosition : boardState.Player1KingPosition;
|
||||
var path = previousMovedPiece.GetPathFromStartToEnd(position, kingPosition);
|
||||
var threatenedPiece = boardState.GetFirstPieceAlongPath(path);
|
||||
if (!path.Any() || threatenedPiece == null) return false;
|
||||
|
||||
return threatenedPiece.WhichPiece == WhichPiece.King;
|
||||
}
|
||||
|
||||
internal bool IsPlayerInCheckMate(WhichPlayer whichPlayer)
|
||||
{
|
||||
if (!boardState.InCheck.HasValue) return false;
|
||||
|
||||
|
||||
// Get all pieces from "other player" who threaten the king in question.
|
||||
var otherPlayer = whichPlayer == WhichPlayer.Player1 ? WhichPlayer.Player2 : WhichPlayer.Player1;
|
||||
var tilesOccupiedByOtherPlayer = boardState.GetTilesOccupiedBy(otherPlayer);
|
||||
|
||||
if (tilesOccupiedByOtherPlayer.SingleOrDefault() != default)
|
||||
{
|
||||
/* If there is exactly one threat it is possible to block the check.
|
||||
* Foreach piece owned by whichPlayer
|
||||
* if piece can intercept check, return false;
|
||||
*/
|
||||
var threat = tilesOccupiedByOtherPlayer.Single();
|
||||
var kingPosition = whichPlayer == WhichPlayer.Player1
|
||||
? boardState.Player1KingPosition
|
||||
: boardState.Player2KingPosition;
|
||||
var tiles = boardState.GetTilesOccupiedBy(whichPlayer);
|
||||
var line = Vector2.Subtract(kingPosition, threat.Position);
|
||||
var slope = line.Y / line.X;
|
||||
foreach (var tile in tiles)
|
||||
{
|
||||
// y = mx + b; slope intercept
|
||||
// b = -mx + y;
|
||||
var b = -slope * tile.Position.X + tile.Position.Y;
|
||||
//if (tile.Position.Y = slope * tile.Position.X + )
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* If no ability to block the check, maybe the king can evade check by moving.
|
||||
*
|
||||
* Foreach position the king can reach
|
||||
* Foreach piece owned by "other player", check if piece threatens king position.
|
||||
*/
|
||||
|
||||
//
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//foreach (var kvp in boardState)
|
||||
//{
|
||||
// if (kvp.Value == null) continue;
|
||||
// var position = ShogiBoardState.FromBoardNotation(kvp.Key);
|
||||
// var piece = kvp.Value;
|
||||
// foreach (var path in piece.MoveSet)
|
||||
// {
|
||||
// if (path.Distance == Distance.OneStep)
|
||||
// {
|
||||
// var move = path.Direction + position;
|
||||
// var simulationState = new ShogiBoardState(boardState);
|
||||
// var simulation = new Shogi(simulationState);
|
||||
// simulation.Move(position, move);
|
||||
// }
|
||||
// else if (path.Distance == Distance.MultiStep)
|
||||
// {
|
||||
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
public bool EvaluateCheckmate_Old()
|
||||
{
|
||||
if (!boardState.InCheck.HasValue) return false;
|
||||
|
||||
// Assume true and try to disprove.
|
||||
var isCheckmate = true;
|
||||
board.ForEachNotNull((piece, from) => // For each piece...
|
||||
boardState.ForEachNotNull((piece, from) => // For each piece...
|
||||
{
|
||||
// Short circuit
|
||||
if (!isCheckmate) return;
|
||||
|
||||
if (piece.Owner == board.InCheck) // ...owned by the player in check...
|
||||
if (piece.Owner == boardState.InCheck) // ...owned by the player in check...
|
||||
{
|
||||
// ...evaluate if any move gets the player out of check.
|
||||
PathEvery(from, (other, position) =>
|
||||
{
|
||||
var simulationBoard = new StandardRules(new ShogiBoardState(board));
|
||||
var fromNotation = ShogiBoardState.ToBoardNotation(from);
|
||||
var toNotation = ShogiBoardState.ToBoardNotation(position);
|
||||
var simulationResult = simulationBoard.Move(fromNotation, toNotation, false);
|
||||
if (simulationResult.Success)
|
||||
{
|
||||
if (!IsPlayerInCheckAfterMove(from, position, board.InCheck.Value))
|
||||
{
|
||||
isCheckmate = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
//PathEvery(from, (other, position) =>
|
||||
//{
|
||||
// var simulationBoard = new StandardRules(new ShogiBoardState(board));
|
||||
// var fromNotation = ShogiBoardState.ToBoardNotation(from);
|
||||
// var toNotation = ShogiBoardState.ToBoardNotation(position);
|
||||
// var simulationResult = simulationBoard.Move(fromNotation, toNotation, false);
|
||||
// if (simulationResult.Success)
|
||||
// {
|
||||
// //if (!IsPlayerInCheckAfterMove(from, position, board.InCheck.Value))
|
||||
// //{
|
||||
// // isCheckmate = false;
|
||||
// //}
|
||||
// }
|
||||
//});
|
||||
}
|
||||
// TODO: Assert that a player could not place a piece from their hand to avoid check.
|
||||
});
|
||||
return isCheckmate;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Navigate the collection such that each "step" is always towards the destination, respecting the Paths available to the element at origin.
|
||||
/// </summary>
|
||||
/// <param name="element">The pathing element.</param>
|
||||
/// <param name="origin">The starting location.</param>
|
||||
/// <param name="destination">The destination.</param>
|
||||
/// <param name="callback">Do cool stuff here.</param>
|
||||
/// <returns>True if the element reached the destination.</returns>
|
||||
public bool PathTo(Vector2 origin, Vector2 destination, Callback? callback = null)
|
||||
{
|
||||
if (destination.X > 8 || destination.Y > 8 || destination.X < 0 || destination.Y < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var piece = board[origin];
|
||||
if (piece == null) return false;
|
||||
|
||||
var path = FindDirectionTowardsDestination(GetMoveSet(piece.WhichPiece).GetMoves(piece.IsUpsideDown), origin, destination);
|
||||
if (!IsPathable(origin, destination, path.Direction))
|
||||
{
|
||||
// Assumption: if a single best-choice step towards the destination cannot happen, no pathing can happen.
|
||||
return false;
|
||||
}
|
||||
|
||||
var shouldPath = true;
|
||||
var next = origin;
|
||||
while (shouldPath && next != destination)
|
||||
{
|
||||
next = Vector2.Add(next, path.Direction);
|
||||
var collider = board[next];
|
||||
if (collider != null)
|
||||
{
|
||||
callback?.Invoke(collider, next);
|
||||
shouldPath = false;
|
||||
}
|
||||
else if (path.Distance == Distance.OneStep)
|
||||
{
|
||||
shouldPath = false;
|
||||
}
|
||||
}
|
||||
return next == destination;
|
||||
}
|
||||
|
||||
public void PathEvery(Vector2 from, Callback callback)
|
||||
{
|
||||
var piece = board[from];
|
||||
if (piece == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (var path in GetMoveSet(piece.WhichPiece).GetMoves(piece.IsUpsideDown))
|
||||
{
|
||||
var shouldPath = true;
|
||||
var next = Vector2.Add(from, path.Direction); ;
|
||||
while (shouldPath && next.X < 8 && next.Y < 8 && next.X >= 0 && next.Y >= 0)
|
||||
{
|
||||
var collider = board[(int)next.Y, (int)next.X];
|
||||
if (collider != null)
|
||||
{
|
||||
callback(collider, next);
|
||||
shouldPath = false;
|
||||
}
|
||||
if (path.Distance == Distance.OneStep)
|
||||
{
|
||||
shouldPath = false;
|
||||
}
|
||||
next = Vector2.Add(next, path.Direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsPathable(Vector2 origin, Vector2 destination, Vector2 direction)
|
||||
{
|
||||
var next = Vector2.Add(origin, direction);
|
||||
if (Vector2.Distance(next, destination) >= Vector2.Distance(origin, destination)) return false;
|
||||
|
||||
var slope = (destination.Y - origin.Y) / (destination.X - origin.X);
|
||||
if (float.IsInfinity(slope))
|
||||
{
|
||||
return next.X == destination.X;
|
||||
}
|
||||
else
|
||||
{
|
||||
// b = -mx + y
|
||||
var yIntercept = -slope * origin.X + origin.Y;
|
||||
// y = mx + b
|
||||
return next.Y == slope * next.X + yIntercept;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Path the line from origin to destination, ignoring any Paths defined by the element at origin.
|
||||
/// </summary>
|
||||
public void LinePathTo(Vector2 origin, Vector2 direction, Callback callback)
|
||||
{
|
||||
direction = Vector2.Normalize(direction);
|
||||
|
||||
var next = Vector2.Add(origin, direction);
|
||||
while (next.X >= 0 && next.X < 8 && next.Y >= 0 && next.Y < 8)
|
||||
{
|
||||
var element = board[next];
|
||||
if (element != null) callback(element, next);
|
||||
next = Vector2.Add(next, direction);
|
||||
}
|
||||
}
|
||||
|
||||
public static Move FindDirectionTowardsDestination(ICollection<Move> paths, Vector2 origin, Vector2 destination) =>
|
||||
paths.Aggregate((a, b) =>
|
||||
{
|
||||
var distanceA = Vector2.Distance(destination, Vector2.Add(origin, a.Direction));
|
||||
var distanceB = Vector2.Distance(destination, Vector2.Add(origin, b.Direction));
|
||||
return distanceA < distanceB ? a : b;
|
||||
});
|
||||
|
||||
public static MoveSet GetMoveSet(WhichPiece whichPiece)
|
||||
{
|
||||
return whichPiece switch
|
||||
{
|
||||
WhichPiece.King => MoveSet.King,
|
||||
WhichPiece.GoldGeneral => MoveSet.GoldGeneral,
|
||||
WhichPiece.SilverGeneral => MoveSet.SilverGeneral,
|
||||
WhichPiece.Bishop => MoveSet.Bishop,
|
||||
WhichPiece.Rook => MoveSet.Rook,
|
||||
WhichPiece.Knight => MoveSet.Knight,
|
||||
WhichPiece.Lance => MoveSet.Lance,
|
||||
WhichPiece.Pawn => MoveSet.Pawn,
|
||||
_ => throw new ArgumentException($"{nameof(WhichPiece)} not recognized."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user