Пример #1
0
        /// <summary>
        /// créer une copie du roi de la couleur de joueur actif, si la pièce que l'on reçoit en paramètre est la même que la copie du roi que nous venons de faire nous modifions la position du roi cloner
        /// ensuite la méthode IsCheck(Game game) est appelée et revoit si le roi est en échec ou non
        /// </summary>
        /// <param name="piece"></param>
        /// <returns></returns>
        public bool IsKingCheck(string color)
        {
            King  k     = null;
            Piece piece = lstPlayer[0].LastPiece;
            Dictionary <string, Piece> dTemp;
            string Key;

            if (color == strColor1)
            {
                dTemp = dicWhitePiece;
                Key   = "KingWhite";
            }
            else
            {
                dTemp = dicBlackPiece;
                Key   = "KingBlack";
            }
            k = (King)dTemp[Key].Clone();
            if (k.GetType() == piece.GetType())
            {
                k.PositionX = piece.PositionX;
                k.PositionY = piece.PositionY;
            }
            return(k.IsCheck(this));
        }
Пример #2
0
        /// <summary>
        /// test si un grand rock est possible
        /// </summary>
        /// <param name="color"></param>
        /// <returns></returns>
        public bool IsSmallCastling(string color)
        {
            if (color == strColor1)
            {
                if (tabPiece[7][7] == null)
                {
                    return(false);
                }
                if (tabPiece[7][7].GetType() != typeof(Rook))
                {
                    return(false);
                }
                if (tabPiece[7][7].IsAlreadyMove)
                {
                    return(false);
                }

                if (tabPiece[7][6] != null || tabPiece[7][5] != null)
                {
                    return(false);
                }
                if (tabPiece[7][4] == null)
                {
                    return(false);
                }
                if (tabPiece[7][4].GetType() != typeof(King))
                {
                    return(false);
                }
                King k = (King)tabPiece[7][4].Clone();
                if (k.IsAlreadyMove)
                {
                    return(false);
                }
                k.PositionX = 5;
                if (k.IsCheck(this))
                {
                    return(false);
                }
                k.PositionX = 6;
                if (k.IsCheck(this))
                {
                    return(false);
                }
            }
            else
            {
                if (tabPiece[0][7] == null)
                {
                    return(false);
                }
                if (tabPiece[0][7].GetType() != typeof(Rook))
                {
                    return(false);
                }
                if (tabPiece[0][7].IsAlreadyMove)
                {
                    return(false);
                }
                if (tabPiece[0][6] != null || tabPiece[0][5] != null)
                {
                    return(false);
                }
                if (tabPiece[0][4] == null)
                {
                    return(false);
                }
                if (tabPiece[0][4].GetType() != typeof(King))
                {
                    return(false);
                }
                King k = (King)tabPiece[0][4].Clone();
                if (k.IsAlreadyMove)
                {
                    return(false);
                }
                k.PositionX = 5;
                if (k.IsCheck(this))
                {
                    return(false);
                }
                k.PositionX = 6;
                if (k.IsCheck(this))
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #3
0
        /// <summary>
        /// test si un petit rock est possible
        /// </summary>
        /// <param name="color"></param>
        /// <returns></returns>
        public bool IsBigCastling(string color)
        {
            //implémente une série de test
            if (color == strColor1)
            {
                try
                {
                    Rook r = (Rook)tabPiece[7][0];
                }
                catch
                {
                    return(false);
                }
                if (tabPiece[7][1] != null || tabPiece[7][2] != null || tabPiece[7][3] != null)
                {
                    return(false);
                }
                try
                {
                    King k = (King)tabPiece[7][4].Clone();
                    if (k.IsAlreadyMove)
                    {
                        return(false);
                    }



                    k.PositionX = 3;
                    if (k.IsCheck(this))
                    {
                        return(false);
                    }
                    k.PositionX = 2;
                    if (k.IsCheck(this))
                    {
                        return(false);
                    }
                }
                catch
                {
                    return(false);
                }
            }
            else
            {
                try
                {
                    Rook r = (Rook)tabPiece[0][0];
                }
                catch
                {
                    return(false);
                }
                if (tabPiece[0][1] != null || tabPiece[0][2] != null || tabPiece[0][3] != null)
                {
                    return(false);
                }
                try
                {
                    King k = (King)tabPiece[0][4].Clone();
                    if (k.IsAlreadyMove)
                    {
                        return(false);
                    }


                    k.PositionX = 3;
                    if (k.IsCheck(this))
                    {
                        return(false);
                    }
                    k.PositionX = 2;
                    if (k.IsCheck(this))
                    {
                        return(false);
                    }
                }
                catch
                {
                    return(false);
                }
            }
            return(true);
        }