예제 #1
0
        protected void LoopOnCellsBySteps(int steps, MoveDirection direction, ref ICell[,] cells, ref List <Position> availableMoves, int srcX, int srcY, ICell exclude)
        {
            for (int i = 0; i < steps; i++)
            {
                switch (direction)
                {
                case MoveDirection.Up:
                    MoveCalculation.MoveDown(ref srcX, ref srcY);
                    CheckCell(ref cells, ref availableMoves, srcX, srcY, exclude);
                    break;

                case MoveDirection.Down:
                    MoveCalculation.MoveUp(ref srcX, ref srcY);
                    CheckCell(ref cells, ref availableMoves, srcX, srcY, exclude);
                    break;

                case MoveDirection.Left:
                    MoveCalculation.MoveLeft(ref srcX, ref srcY);
                    CheckCell(ref cells, ref availableMoves, srcX, srcY, exclude);
                    break;

                case MoveDirection.Right:
                    MoveCalculation.MoveRight(ref srcX, ref srcY);
                    CheckCell(ref cells, ref availableMoves, srcX, srcY, exclude);
                    break;

                case MoveDirection.UpLeft:
                    MoveCalculation.MoveLeftDown(ref srcX, ref srcY);
                    CheckCell(ref cells, ref availableMoves, srcX, srcY, exclude);
                    break;

                case MoveDirection.UpRight:
                    MoveCalculation.MoveRightDown(ref srcX, ref srcY);
                    CheckCell(ref cells, ref availableMoves, srcX, srcY, exclude);
                    break;

                case MoveDirection.DownLeft:
                    MoveCalculation.MoveLeftUp(ref srcX, ref srcY);
                    CheckCell(ref cells, ref availableMoves, srcX, srcY, exclude);
                    break;

                case MoveDirection.DownRight:
                    MoveCalculation.MoveRightUp(ref srcX, ref srcY);
                    CheckCell(ref cells, ref availableMoves, srcX, srcY, exclude);
                    break;

                default:
                    break;
                }
            }
        }
예제 #2
0
        protected void LoopOnCells(MoveDirection direction, ref ICell[,] cells, ref List <Position> availableMoves, int srcX, int srcY, ICell exclude)
        {
            int x = srcX;
            int y = srcY;

            switch (direction)
            {
            case MoveDirection.Up:
                while (MoveCalculation.MoveDown(ref x, ref y))
                {
                    if (CheckCell(ref cells, ref availableMoves, x, y, exclude))
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                break;

            case MoveDirection.Down:
                while (MoveCalculation.MoveUp(ref x, ref y))
                {
                    if (CheckCell(ref cells, ref availableMoves, x, y, exclude))
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                break;

            case MoveDirection.Left:
                while (MoveCalculation.MoveLeft(ref x, ref y))
                {
                    if (CheckCell(ref cells, ref availableMoves, x, y, exclude))
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                break;

            case MoveDirection.Right:
                while (MoveCalculation.MoveRight(ref x, ref y))
                {
                    if (CheckCell(ref cells, ref availableMoves, x, y, exclude))
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                break;

            case MoveDirection.UpLeft:
                while (MoveCalculation.MoveLeftDown(ref x, ref y))
                {
                    if (CheckCell(ref cells, ref availableMoves, x, y, exclude))
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                break;

            case MoveDirection.UpRight:
                while (MoveCalculation.MoveRightDown(ref x, ref y))
                {
                    if (CheckCell(ref cells, ref availableMoves, x, y, exclude))
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                break;

            case MoveDirection.DownLeft:
                while (MoveCalculation.MoveLeftUp(ref x, ref y))
                {
                    if (CheckCell(ref cells, ref availableMoves, x, y, exclude))
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                break;

            case MoveDirection.DownRight:
                while (MoveCalculation.MoveRightUp(ref x, ref y))
                {
                    if (CheckCell(ref cells, ref availableMoves, x, y, exclude))
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                break;

            default:
                break;
            }
        }
예제 #3
0
        public override List <Position> GetAvailableMoves(ref ICell[,] cells, int srcX, int srcY, ICell exclude = null)
        {
            List <Position> availableMoves = new List <Position>();
            int             x = srcX;
            int             y = srcY;

            if (cells[srcX, srcY].Piece.Color == Board.ImBlackOrWhite)
            {
                if (isFirstMove)
                {
                    MoveCalculation.MoveDown(ref x, ref y);
                    if (!cells[x, y].IsEmpty)
                    {
                        goto line1;
                    }

                    CheckCell(ref cells, ref availableMoves, x, y, exclude);
                }

                MoveCalculation.MoveDown(ref x, ref y);
                if (x < 8 && x > -1 && y < 8 && y > -1)
                {
                    if (cells[x, y].IsEmpty)
                    {
                        CheckCell(ref cells, ref availableMoves, x, y, exclude);
                    }
                }

                //move ma2asat
line1:
                x = srcX;
                y = srcY;

                MoveCalculation.MoveLeftDown(ref x, ref y);
                if (x < 8 && x > -1 && y < 8 && y > -1)
                {
                    if (!cells[x, y].IsEmpty)
                    {
                        if (cells[x, y].Piece.Color != cells[srcX, srcY].Piece.Color)
                        {
                            CheckCell(ref cells, ref availableMoves, x, y, exclude);
                        }
                    }
                }

                x = srcX;
                y = srcY;

                MoveCalculation.MoveRightDown(ref x, ref y);

                if (x < 8 && x > -1 && y < 8 && y > -1)
                {
                    if (!cells[x, y].IsEmpty)
                    {
                        if (cells[x, y].Piece.Color != cells[srcX, srcY].Piece.Color)
                        {
                            CheckCell(ref cells, ref availableMoves, x, y, exclude);
                        }
                    }
                }
            }

            else
            {
                if (isFirstMove)
                {
                    MoveCalculation.MoveUp(ref x, ref y);
                    if (!cells[x, y].IsEmpty)
                    {
                        return(availableMoves);
                    }

                    CheckCell(ref cells, ref availableMoves, x, y, exclude);
                }

                MoveCalculation.MoveUp(ref x, ref y);
                if (x < 8 && x > -1 && y < 8 && y > -1)
                {
                    if (cells[x, y].IsEmpty)
                    {
                        CheckCell(ref cells, ref availableMoves, x, y, exclude);
                    }
                }


                x = srcX;
                y = srcY;

                MoveCalculation.MoveLeftUp(ref x, ref y);
                if (x < 8 && x > -1 && y < 8 && y > -1)
                {
                    if (!cells[x, y].IsEmpty)
                    {
                        if (cells[x, y].Piece.Color != cells[srcX, srcY].Piece.Color)
                        {
                            CheckCell(ref cells, ref availableMoves, x, y, exclude);
                        }
                    }
                }


                x = srcX;
                y = srcY;

                MoveCalculation.MoveRightUp(ref x, ref y);

                if (x < 8 && x > -1 && y < 8 && y > -1)
                {
                    if (!cells[x, y].IsEmpty)
                    {
                        if (cells[x, y].Piece.Color != cells[srcX, srcY].Piece.Color)
                        {
                            CheckCell(ref cells, ref availableMoves, x, y, exclude);
                        }
                    }
                }
            }



            return(availableMoves);
        }