示例#1
0
        public static bool IsAnyPieceBetween(Board board, Square from, Square to)
        {
            //if
            var stepX = MoveProperty.SignX(from, to);
            var stepY = MoveProperty.SignY(from, to);

            var tempFrom = new Square(from.X, from.Y);

            while (true)
            {
                // beware: plus or minus step*
                tempFrom = new Square(tempFrom.X - stepX, tempFrom.Y - stepY);

                if (tempFrom == to)
                {
                    return(false);
                }
                if (board[tempFrom].IsNone())
                {
                    continue;
                }

                return(true);
            }
        }
示例#2
0
        // suppose that path from is vertical/horizontal/diagonal line
        public static bool CanMoveLine(Board board, Square from, Square to)
        {
            var stepX = MoveProperty.SignX(from, to);
            var stepY = MoveProperty.SignY(from, to);

            var tempFrom = new Square(from.X, from.Y);

            while (true)
            {
                tempFrom = new Square(tempFrom.X - stepX, tempFrom.Y - stepY);

                if (tempFrom == to)
                {
                    return(true);
                }
                if (board[tempFrom].IsNone())
                {
                    continue;
                }

                return(false);
            }
        }