Example #1
0
            public override List <Position> GetAvailableAtackPositons(Position currentPos, CoreMatrix matrix)
            {
                List <Position> available = new List <Position> ();

                //by X
                for (int i = currentPos.X + 1; i < 8; i++)
                {
                    if (matrix.FigureAt(i, currentPos.Y) == null)
                    {
                        available.Add(new Position(i, currentPos.Y));
                    }
                    else if (matrix.FigureAt(i, currentPos.Y).Color != this.Color)
                    {
                        available.Add(new Position(i, currentPos.Y));
                        break;
                    }
                    else if (matrix.FigureAt(i, currentPos.Y) is King && !IsMoved && !matrix.FigureAt(i, currentPos.Y).IsMoved)
                    {
                        CoreMatrix tmpMatrix;
                        bool       can = true;
                        for (int x = currentPos.X + 1; x <= i; x++)
                        {
                            tmpMatrix = (CoreMatrix)matrix.Clone();
                            Position kingPos = tmpMatrix.GetKing(color);
                            tmpMatrix.MoveFigure(kingPos, new Position(x, currentPos.Y));

                            if (King.IsCheckState(tmpMatrix, color))
                            {
                                can = false;
                                break;
                            }
                        }

                        //figure is not by atack
                        if (can)
                        {
                            available.Add(new Position(i, currentPos.Y));
                        }
                        break;
                    }
                    else
                    {
                        break;
                    }
                }

                //by X
                for (int i = currentPos.X - 1; i >= 0; i--)
                {
                    if (matrix.FigureAt(i, currentPos.Y) == null)
                    {
                        available.Add(new Position(i, currentPos.Y));
                    }
                    else if (matrix.FigureAt(i, currentPos.Y).Color != this.Color)
                    {
                        available.Add(new Position(i, currentPos.Y));
                        break;
                    }
                    else if (matrix.FigureAt(i, currentPos.Y) is King && !IsMoved && !matrix.FigureAt(i, currentPos.Y).IsMoved)
                    {
                        CoreMatrix tmpMatrix;
                        bool       can = true;
                        for (int x = currentPos.X - 1; x <= i; x--)
                        {
                            tmpMatrix = (CoreMatrix)matrix.Clone();
                            Position kingPos = tmpMatrix.GetKing(color);
                            tmpMatrix.MoveFigure(kingPos, new Position(x, currentPos.Y));

                            if (King.IsCheckState(tmpMatrix, color))
                            {
                                can = false;
                                break;
                            }
                        }

                        //figure is not by atack
                        if (can)
                        {
                            available.Add(new Position(i, currentPos.Y));
                        }
                        break;
                    }
                    else
                    {
                        break;
                    }
                }
                //by Y
                for (int j = currentPos.Y + 1; j < 8; j++)
                {
                    if (!matrix.HasFigureAt(new Position(currentPos.X, j)))
                    {
                        available.Add(new Position(currentPos.X, j));
                    }
                    else if (matrix.FigureAt(currentPos.X, j).Color != this.Color ||
                             (matrix.FigureAt(currentPos.X, j) is King && !IsMoved && !matrix.FigureAt(currentPos.X, j).IsMoved))
                    {
                        available.Add(new Position(currentPos.X, j));
                        break;
                    }
                    else
                    {
                        break;
                    }
                }
                //by Y
                for (int j = currentPos.Y - 1; j >= 0; j--)
                {
                    if (matrix.FigureAt(currentPos.X, j) == null)
                    {
                        available.Add(new Position(currentPos.X, j));
                    }
                    else if (matrix.FigureAt(currentPos.X, j).Color != this.Color ||
                             (matrix.FigureAt(currentPos.X, j) is King && !IsMoved && !matrix.FigureAt(currentPos.X, j).IsMoved))
                    {
                        available.Add(new Position(currentPos.X, j));
                        break;
                    }
                    else
                    {
                        break;
                    }
                }
                return(available);
            }
Example #2
0
        public CoreMatrix()
        {
			 sMatrix = new Figure[8, 8];
#if !TEST
            //WHITE          

            sMatrix[0, 7] = new Rock(FigureColor.WHITE);
            sMatrix[7, 7] = new Rock(FigureColor.WHITE);

            sMatrix[6, 7] = new Knight(FigureColor.WHITE);
            sMatrix[1, 7] = new Knight(FigureColor.WHITE);

            sMatrix[2, 7] = new Bishop(FigureColor.WHITE);
            sMatrix[5, 7] = new Bishop(FigureColor.WHITE);

            sMatrix[4, 7] = new King(FigureColor.WHITE);
            sMatrix[3, 7] = new Queen(FigureColor.WHITE);

            for (int i = 0; i < 8; i++)
            {
                sMatrix[i, 6] = new Pawn(FigureColor.WHITE);
            }

            //BLACK
            sMatrix[0, 0] = new Rock(FigureColor.BLACK);
            sMatrix[7, 0] = new Rock(FigureColor.BLACK);

            sMatrix[6, 0] = new Knight(FigureColor.BLACK);
            sMatrix[1, 0] = new Knight(FigureColor.BLACK);

            sMatrix[2, 0] = new Bishop(FigureColor.BLACK);
            sMatrix[5, 0] = new Bishop(FigureColor.BLACK);

            sMatrix[4, 0] = new King(FigureColor.BLACK);
            sMatrix[3, 0] = new Queen(FigureColor.BLACK);

            for (int i = 0; i < 8; i++)
            {
                sMatrix[i, 1] = new Pawn(FigureColor.BLACK);
            }
#endif 

#if TEST
             //WHITE          

             sMatrix[0, 7] = new Rock(FigureColor.WHITE);
             sMatrix[7, 7] = new Rock(FigureColor.WHITE);


             sMatrix[4, 7] = new King(FigureColor.WHITE);


             for (int i = 0; i < 8; i++)
             {
                 sMatrix[i, 6] = new Pawn(FigureColor.WHITE);
             }

             //BLACK
             sMatrix[0, 0] = new Rock(FigureColor.BLACK);
             sMatrix[7, 0] = new Rock(FigureColor.BLACK);

             sMatrix[6, 0] = new Knight(FigureColor.BLACK);
             sMatrix[1, 0] = new Knight(FigureColor.BLACK);

             sMatrix[2, 0] = new Bishop(FigureColor.BLACK);
             sMatrix[5, 0] = new Bishop(FigureColor.BLACK);

             sMatrix[4, 0] = new King(FigureColor.BLACK);
             sMatrix[3, 0] = new Queen(FigureColor.BLACK);

             for (int i = 0; i < 8; i++)
             {
                 sMatrix[i, 1] = new Pawn(FigureColor.BLACK);
             }
#endif

			KingBlack = new Position(4, 0);
			KingWhite = new Position( 4, 7);
        }