Beispiel #1
0
            public static bool IsCheckState(CoreMatrix matrix, FigureColor color)
            {
                //get the king position
                Position kingPos = matrix.GetKing(color);

                //searching for unsafe enemy figure
                for (int i = 0; i < 8; i++)                             //y
                {
                    for (int j = 0; j < 8; j++)                         //x
                    {
                        Position currentPos = new Position(j, i);

                        if (matrix.HasFigureAt(currentPos))
                        {
                            Figure currentFigure = matrix.FigureAt(currentPos);
                            //current figure has same color
                            //continue cycle
                            if (currentFigure.Color == color)
                            {
                                continue;
                            }
                            //get the available atack posions for current enemy figure
                            List <Position> atack = currentFigure.GetAvailableAtackPositons(currentPos, matrix);
                            //if exist atack position same as king position
                            if (atack.Contains(kingPos))
                            {
                                return(true);
                            }
                        }
                    }
                }

                return(false);
            }