public bool MovementRational(IChinesePiece chessman, Point from, Point to, Chessboard chessboard) { var fromPiece = chessboard.GetPiece(from); var toPiece = chessboard.GetPiece(to); if (fromPiece.CollisionWith(toPiece)) { if (fromPiece.GetBetween(toPiece, chessboard).Count == 1 && fromPiece.FatalMovement(toPiece, chessboard)) { return(true); } } }
public static List <IChinesePiece> GetBetween(this IChinesePiece piece, IChinesePiece another, Chessboard chessboard) { var pos1 = chessboard.FindPos(piece); var pos2 = chessboard.FindPos(another); var list = new List <IChinesePiece>(); if (pos1.Valid() && pos2.Valid()) { if (pos1 == pos2) { return(list); } if (pos1.X == pos2.X) { var x = pos1.X; for (var i = (pos1.Y > pos2.Y ? pos2 : pos1).Y + 1; i < (pos1.Y > pos2.Y ? pos1 : pos2).Y; i++) { var currentPiece = chessboard.GetPiece(new Point(x, i)); if (currentPiece.NotEmptyPiece()) { list.Add(currentPiece); } } } else if (pos1.Y == pos2.Y) { var y = pos1.Y; for (var i = (pos1.X > pos2.X ? pos2 : pos1).X; i < (pos1.X > pos2.X ? pos1 : pos2).X; i++) { var currentPiece = chessboard.GetPiece(new Point(i, y)); if (currentPiece.NotEmptyPiece()) { list.Add(currentPiece); } } } return(list); } throw new InvalidOperationException(); }
public bool MovementRational(IChinesePiece chessman, Point from, Point to, Chessboard chessboard) { throw new System.NotImplementedException(); }
private static bool NotEmptyPiece(this IChinesePiece piece) { return(piece.ChessmanType != PieceType.None); }
public static bool FatalMovement(this IChinesePiece piece, IChinesePiece another, Chessboard chessboard) { }
public static bool CollisionWith(this IChinesePiece piece, IChinesePiece another) { return(piece.ChessmanType != PieceType.None && another.ChessmanType != PieceType.None && piece.ChessmanType != another.ChessmanType); }