Пример #1
0
        private bool PlaceFiture(Figure figure, int row, int col)
        {
            row -= figure.Center.Row;
            col -= figure.Center.Col;

            for (int figureRow = 0; figureRow < figure.Form.GetLength(0); figureRow++)
            {
                for (int figureCol = 0; figureCol < figure.Form.GetLength(1); figureCol++)
                {
                    bool figureCondition = figure.Form[figureRow, figureCol] != 0;

                    if (figureCondition)
                    {
                        bool fieldRowCondition = row + figureRow < 0 || row + figureCol > this.Field.GetLength(0) - 1;
                        bool fieldColCondition = col + figureCol < 0 || col + figureCol > this.Field.GetLength(1) - 1;

                        if (fieldRowCondition || fieldColCondition || this.Field[this.Field.GetLength(0) - 1 - (row + figureRow), col + figureCol] != 0)
                        {
                            return false;
                        }
                    }
                }
            }

            for (int fieldRow = row; fieldRow < row + figure.Form.GetLength(0); fieldRow++)
            {
                for (int fieldCol = col; fieldCol < col + figure.Form.GetLength(1); fieldCol++)
                {
                    if (figure.Form[fieldRow - row, fieldCol - col] != 0)
                    {
                        this.Field[this.Field.GetLength(0) - fieldRow - 1, fieldCol] = figure.Form[fieldRow - row, fieldCol - col];
                    }
                }
            }

            //this.PrintField();
            return true;
        }
Пример #2
0
        private void FindShortestDistanceToPlaceFigure(Figure figure, ref int tryRow, ref int tryCol, ref int tryDistance)
        {
            if (this.PlaceFiture(figure, tryRow, tryCol))
            {
                return;
            }

            while (true)
            {
                tryDistance++;

                tryRow += tryDistance;
                if (this.PlaceFiture(figure, tryRow, tryCol))
                {
                    return;
                }

                for (int i = 0; i < tryDistance; i++)
                {
                    tryCol += 1;
                    tryRow -= 1;

                    if (this.PlaceFiture(figure, tryRow, tryCol))
                    {
                        return;
                    }
                }

                for (int i = 0; i < tryDistance; i++)
                {
                    tryCol -= 1;
                    tryRow -= 1;

                    if (this.PlaceFiture(figure, tryRow, tryCol))
                    {
                        return;
                    }
                }

                for (int i = 0; i < tryDistance; i++)
                {
                    tryCol -= 1;
                    tryRow += 1;

                    if (this.PlaceFiture(figure, tryRow, tryCol))
                    {
                        return;
                    }
                }

                for (int i = 0; i < tryDistance; i++)
                {
                    tryCol += 1;
                    tryRow += 1;

                    if (this.PlaceFiture(figure, tryRow, tryCol))
                    {
                        return;
                    }
                }

                tryRow -= tryDistance;
            }
        }
Пример #3
0
 public Placer(Figure[] figures, int[,] coordinates, int size)
 {
     this.Figures = figures;
     this.Coordinates = coordinates;
     this.Field = new int[size, size];
 }