Пример #1
0
        private void RefreshPlayGround()
        {
            if (_puzzleBoard == null)
            {
                _pbxPlayGround.Image = null;
                return;
            }

            int    width      = _puzzleBoard.Columns * _cellSize;
            int    height     = _puzzleBoard.Rows * _cellSize;
            Bitmap playGround = new Bitmap(width + 1, height + 1);
            Font   font       = new Font(Font.FontFamily, (int)Math.Round(_cellSize * 0.55));
            List <List <Point> > positionAreas = new List <List <Point> >();

            foreach (PuzzleArea area in _knownAreas)
            {
                positionAreas.Add(area.Positions);
            }
            using (Graphics graphics = Graphics.FromImage(playGround))
            {
                graphics.Clear(Color.Transparent);
                for (int y = 0; y <= _puzzleBoard.Rows; y++)
                {
                    graphics.DrawLine(new Pen(Color.Gray), 0, y * _cellSize, width, y * _cellSize);
                }
                for (int x = 0; x <= _puzzleBoard.Columns; x++)
                {
                    graphics.DrawLine(new Pen(Color.Gray), x * _cellSize, 0, x * _cellSize, height);
                }
                for (int y = 0; y < _puzzleBoard.Rows; y++)
                {
                    for (int x = 0; x < _puzzleBoard.Columns; x++)
                    {
                        Point cellPos = new Point(x, y);
                        int   number  = _puzzleBoard.GetValue(cellPos);
                        if (number >= 0 && number <= 9)
                        {
                            Brush fontBrush = _puzzleBoard.GetState(cellPos) == PuzzleCellStateTypes.Filled ? Brushes.White : Brushes.Black;
                            graphics.DrawString(number.ToString(), font, fontBrush, new Rectangle(x * _cellSize + 3, y * _cellSize + 1, _cellSize, _cellSize));
                        }
                    }
                }
            }
            _pbxPlayGround.Image = playGround;
            FitPlayGroundToPanel();
        }
Пример #2
0
        public void Experience(FieldOfVisionTypes fieldOfVisionType, PuzzleBoard partialBoard)
        {
            Point centerPos = new Point();

            switch (fieldOfVisionType)
            {
            case FieldOfVisionTypes.Single:
                centerPos = new Point(0, 0);
                break;

            case FieldOfVisionTypes.ThreeByThree:
                centerPos = new Point(1, 1);
                break;

            case FieldOfVisionTypes.FiveByFive:
                centerPos = new Point(2, 2);
                break;
            }

            List <ISensoryPattern> sensoryPatterns = new List <ISensoryPattern>();

            for (int y = 0; y < partialBoard.Rows; y++)
            {
                for (int x = 0; x < partialBoard.Columns; x++)
                {
                    Point                pos           = new Point(x, y);
                    DirectionTypes       directionType = PuzzleReferee.ConvertToDirectionType(new Point(pos.X - centerPos.X, pos.Y - centerPos.Y));
                    PuzzleCellStateTypes state         = partialBoard.GetState(pos);
                    int    value       = partialBoard.GetValue(pos);
                    string valueString = value >= 0 ? value.ToString() : " ";

                    if (state != PuzzleCellStateTypes.Undefined)
                    {
                        ISensoryUnit sensoryUnitState = GetOrCreateSensoryUnit(SensoryTypes.FieldState, state.ToString());
                        ISensoryUnit sensoryUnitValue = GetOrCreateSensoryUnit(SensoryTypes.FieldValue, valueString);

                        List <ISensoryUnit> sensoryUnits = new List <ISensoryUnit>();
                        sensoryUnits.Add(sensoryUnitState);
                        sensoryUnits.Add(sensoryUnitValue);

                        ISensoryPattern sensoryPattern = new SensoryPattern(directionType, sensoryUnits);

                        if (_kownSensoryPatterns.Contains(sensoryPattern))
                        {
                            sensoryPattern = _kownSensoryPatterns[_kownSensoryPatterns.IndexOf(sensoryPattern)];
                        }
                        else
                        {
                            _kownSensoryPatterns.Add(sensoryPattern);
                            _kownSensoryPatterns.Sort();
                        }

                        sensoryPatterns.Add(sensoryPattern);
                    }
                }
            }
            _lastSensationSnapshot = new SensationSnapshot(DirectionTypes.Center, fieldOfVisionType, sensoryPatterns, IS_SAVEABLE_SNAPSHOT);
        }
Пример #3
0
        public bool CheckAction(Point position, DirectionTypes directionType, ActionTypes actionType)
        {
            bool  result         = false;
            Point direction      = ConvertToPoint(directionType);
            Point actionPosition = new Point(position.X + direction.X, position.Y + direction.Y);

            switch (actionType)
            {
            case ActionTypes.Move:
                result = actionPosition.X >= 0 && actionPosition.X < _board.Columns && actionPosition.Y >= 0 && actionPosition.Y < _board.Rows;
                break;

            case ActionTypes.MarkAsEmpty:
            case ActionTypes.MarkAsFilled:
                result = _board.GetState(actionPosition) == PuzzleCellStateTypes.NotMarked;
                break;
            }
            return(result);
        }
Пример #4
0
        private void DrawFieldOfVision(FieldOfVisionTypes fieldOfVisionType, Point position)
        {
            PuzzleBoard partialBoard = CreatePartialBoard(fieldOfVisionType, position);

            if (partialBoard == null)
            {
                return;
            }

            int width             = partialBoard.Columns;
            int height            = partialBoard.Rows;
            int drawCellSize      = Math.Min(_pbxLookResult.Width, _pbxLookResult.Height);
            int maxFieldDimension = Math.Max(width, height);

            drawCellSize = drawCellSize / maxFieldDimension;

            int    drawWidth            = width * drawCellSize;
            int    drawHeight           = height * drawCellSize;
            Bitmap playGround           = new Bitmap(drawWidth + 1, drawHeight + 1);
            Bitmap playGroundBackground = new Bitmap(drawWidth + 1, drawHeight + 1);
            Font   font = new Font(Font.FontFamily, (int)Math.Round(drawCellSize * 0.55));

            using (Graphics graphics = Graphics.FromImage(playGround))
            {
                using (Graphics graphicsBackground = Graphics.FromImage(playGroundBackground))
                {
                    graphics.Clear(Color.Transparent);
                    graphicsBackground.Clear(Color.White);

                    for (int y = 0; y <= partialBoard.Rows; y++)
                    {
                        graphics.DrawLine(new Pen(Color.Gray), 0, y * drawCellSize, drawWidth, y * drawCellSize);
                    }
                    for (int x = 0; x <= partialBoard.Columns; x++)
                    {
                        graphics.DrawLine(new Pen(Color.Gray), x * drawCellSize, 0, x * drawCellSize, drawHeight);
                    }
                    for (int y = 0; y < partialBoard.Rows; y++)
                    {
                        for (int x = 0; x < partialBoard.Columns; x++)
                        {
                            Point cellPos = new Point(x, y);
                            int   drawX   = x * drawCellSize;
                            int   drawY   = y * drawCellSize;
                            int   number  = partialBoard.GetValue(cellPos);
                            if (number >= 0 && number <= 9)
                            {
                                Brush fontBrush = partialBoard.GetState(cellPos) == PuzzleCellStateTypes.Filled ? Brushes.White : Brushes.Black;
                                graphics.DrawString(number.ToString(), font, fontBrush, new Rectangle(drawX + (30 / maxFieldDimension), drawY + (10 / maxFieldDimension), drawCellSize, drawCellSize));
                            }
                            switch (partialBoard.GetState(cellPos))
                            {
                            case PuzzleCellStateTypes.Undefined:
                                graphicsBackground.FillRectangle(Brushes.Yellow, drawX, drawY, drawCellSize, drawCellSize);
                                break;

                            case PuzzleCellStateTypes.Filled:
                                graphicsBackground.FillRectangle(Brushes.Black, drawX, drawY, drawCellSize, drawCellSize);
                                break;

                            case PuzzleCellStateTypes.Empty:
                                graphicsBackground.FillRectangle(Brushes.Gainsboro, drawX, drawY, drawCellSize, drawCellSize);
                                graphicsBackground.DrawLine(new Pen(Color.Gray), drawX, drawY, drawX + drawCellSize, drawY + drawCellSize);
                                graphicsBackground.DrawLine(new Pen(Color.Gray), drawX, drawY + drawCellSize, drawX + drawCellSize, drawY);
                                break;

                            case PuzzleCellStateTypes.Outside:
                                graphicsBackground.FillRectangle(Brushes.DarkBlue, drawX, drawY, drawCellSize, drawCellSize);
                                graphicsBackground.DrawLine(new Pen(Color.White), drawX, drawY, drawX + drawCellSize, drawY + drawCellSize);
                                graphicsBackground.DrawLine(new Pen(Color.White), drawX, drawY + drawCellSize, drawX + drawCellSize, drawY);
                                break;
                            }
                        }
                    }
                }
            }
            _pbxLookResult.Image           = playGround;
            _pbxLookResult.BackgroundImage = playGroundBackground;
        }