Exemplo n.º 1
0
        // duplicated code?
        //public static bool IsDiagonal(int p1, int p2)
        //{
        //    var diff = Math.Abs(p1 - p2);
        //    var ltr = diff % 9 == 0;
        //    var rtl = diff % 7 == 0;
        //    if (!ltr && !rtl)
        //    {
        //        return false;
        //    }
        //    return true;
        //}

        public static bool IsOrthogonal(int p1, int p2)
        {
            var rank = GetEntireRank(NotationEngine.PositionToRankInt(p1));
            var file = GetEntireFile(p1);

            return(rank.Contains(p2) || file.Contains(p2));
        }
Exemplo n.º 2
0
        public static (int RookPos, int NewRookPos) GetRookPositionsForCastle(Color color, int piecePosition, int newPiecePosition)
        {
            //manage the castle
            var rookRank = color == Color.White ? 1 : 8; //intentionally not zero based
            var rookFile = NotationEngine.IntToFile(piecePosition - newPiecePosition > 0 ? 0 : 7);
            var rookPos  = NotationEngine.CoordinateToPosition(string.Concat(rookFile, rookRank.ToString()));

            var newRookFile = NotationEngine.IntToFile(piecePosition - newPiecePosition > 0 ? 3 : 5);
            var newRookPos  = NotationEngine.CoordinateToPosition(string.Concat(newRookFile, rookRank.ToString()));

            return(rookPos, newRookPos);
        }