示例#1
0
        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);
                }
            }
        }
示例#2
0
        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();
        }
示例#3
0
 public bool MovementRational(IChinesePiece chessman, Point from, Point to, Chessboard chessboard)
 {
     throw new System.NotImplementedException();
 }
示例#4
0
 private static bool NotEmptyPiece(this IChinesePiece piece)
 {
     return(piece.ChessmanType != PieceType.None);
 }
示例#5
0
 public static bool FatalMovement(this IChinesePiece piece, IChinesePiece another, Chessboard chessboard)
 {
 }
示例#6
0
 public static bool CollisionWith(this IChinesePiece piece, IChinesePiece another)
 {
     return(piece.ChessmanType != PieceType.None &&
            another.ChessmanType != PieceType.None &&
            piece.ChessmanType != another.ChessmanType);
 }