예제 #1
0
 public void setLastVisit(int step, MZPosition position)
 {
     if (position.x() >= 0 && position.y() >= 0 && position.x() < _visits.Count() && position.y() < _visits[0].Count())
     {
         _visits[(int)position.x()][(int)position.y()] = step;
     }
 }
예제 #2
0
 // вызврат клетки через позицию
 public MZCell cellAtPosition(MZPosition position)
 {
     if (position.x() >= 0 && position.y() >= 0 && position.x() < _cells.Count() && position.y() < _cells[0].Count())
     {
         return(_cells[(int)position.x()][(int)position.y()]);
     }
     return(new MZCell());
 }
예제 #3
0
 public int lastVisitAtPoisiton(MZPosition position)
 {
     if (position.x() >= 0 && position.y() >= 0 && position.x() < _visits.Count() && position.y() < _visits[0].Count())
     {
         return(_visits[(int)position.x()][(int)position.y()]);
     }
     return(-MZMacro.LAST_STEPS_VISIBLE);
 }
예제 #4
0
파일: MZGame.cs 프로젝트: GA239/robolabwp
        public MZMoveResultCode makeStepTo(MZDirection direction)
        {
            if (_isPaused)
            {
                return(MZMoveResultCode.GAME_PAUSED);
            }

            /*
             * List<MZFlow> flowList = _maze.flowList();
             * for (int i = 0; i < flowList.Count(); i++)
             * {
             *  if (flowList[i].isInFlow(_currentPosition))
             *  {
             *      if ((direction == flowList[i].direction()) || (direction == (flowList[i].direction() + 2) % 2))
             *      {
             *          return MZMoveResultCode.MOTION_IMPOSSIBLE;
             *      }
             *  }
             * }*/

            if (!_maze.cells().cellAtPosition(_currentPosition).hasWallAtDirection(direction))
            {
                _currentPosition.move(direction);
                _stepsCount++;
                visitPosition(_currentPosition);
                if ((_maze.winningPosition().x() == _currentPosition.x()) && (_maze.winningPosition().y() == _currentPosition.y()))
                {
                    _isEnded = true;
                    return(MZMoveResultCode.GAME_ENDED);
                }
                else
                {
                    return(MZMoveResultCode.MOTION_PERFORMED);
                }
            }
            return(MZMoveResultCode.MOTION_IMPOSSIBLE);
        }
예제 #5
0
파일: MZFlow.cs 프로젝트: GA239/robolabwp
        public bool isInFlow(MZPosition position)
        {
            switch (_direction)
            {
            case MZDirection.UP:
                if (_position.x() != position.x())
                {
                    return(false);
                }
                else
                {
                    if (_position.y() <= position.y() && position.y() < _position.y() + _length - 1)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

            case MZDirection.RIGHT:
                if (_position.y() != position.y())
                {
                    return(false);
                }
                else
                {
                    if (_position.x() <= position.x() && position.x() < _position.x() + _length - 1)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

            case MZDirection.DOWN:
                if (_position.x() != position.x())
                {
                    return(false);
                }
                else
                {
                    if (_position.y() >= position.y() && position.y() > _position.y() - _length + 1)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

            case MZDirection.LEFT:
                if (_position.y() != position.y())
                {
                    return(false);
                }
                else
                {
                    if (_position.x() >= position.x() && position.x() > _position.x() - _length + 1)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

            default:
                return(false);
            }
        }
예제 #6
0
파일: MZGame.cs 프로젝트: GA239/robolabwp
        public void visitPosition(MZPosition position)
        {
            _visitsMatrix.setLastVisit(_stepsCount, position);
            MZCellMatrix cellMatrix       = _maze.cells();
            MZPosition   iteratorPosition = new MZPosition(position.x(), position.y());

            while (iteratorPosition.x() > 0)
            {
                if (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.LEFT))
                {
                    break;
                }
                iteratorPosition.move(MZDirection.LEFT);
                _visitsMatrix.setLastVisit(_stepsCount, iteratorPosition);
            }

            iteratorPosition = new MZPosition(position.x(), position.y());

            while (iteratorPosition.y() > 0)
            {
                if (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.DOWN))
                {
                    break;
                }
                iteratorPosition.move(MZDirection.DOWN);
                _visitsMatrix.setLastVisit(_stepsCount, iteratorPosition);
            }

            iteratorPosition = new MZPosition(position.x(), position.y());

            while (iteratorPosition.x() < _maze.width() - 1)
            {
                if (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.RIGHT))
                {
                    break;
                }
                iteratorPosition.move(MZDirection.RIGHT);
                _visitsMatrix.setLastVisit(_stepsCount, iteratorPosition);
            }
            iteratorPosition = new MZPosition(position.x(), position.y());

            while (iteratorPosition.y() < _maze.height() - 1)
            {
                if (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.UP))
                {
                    break;
                }
                iteratorPosition.move(MZDirection.UP);
                _visitsMatrix.setLastVisit(_stepsCount, iteratorPosition);
            }

            if ((!cellMatrix.cellAtPosition(position).hasWallAtDirection(MZDirection.LEFT)) && (!cellMatrix.cellAtPosition(position).hasWallAtDirection(MZDirection.DOWN)))
            {
                iteratorPosition = new MZPosition(position.x(), position.y());
                iteratorPosition.move(MZDirection.LEFT);
                iteratorPosition.move(MZDirection.DOWN);

                while (iteratorPosition.x() >= 0)
                {
                    if ((cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.RIGHT)) || (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.UP)))
                    {
                        break;
                    }
                    MZPosition tempPosition = iteratorPosition;
                    while (iteratorPosition.y() >= 0)
                    {
                        if ((cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.RIGHT)) || (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.UP)))
                        {
                            break;
                        }
                        _visitsMatrix.setLastVisit(_stepsCount, iteratorPosition);
                        iteratorPosition.move(MZDirection.DOWN);
                    }
                    iteratorPosition = tempPosition;
                    iteratorPosition.move(MZDirection.LEFT);
                }
            }

            if ((!cellMatrix.cellAtPosition(position).hasWallAtDirection(MZDirection.LEFT)) && (!cellMatrix.cellAtPosition(position).hasWallAtDirection(MZDirection.UP)))
            {
                iteratorPosition = new MZPosition(position.x(), position.y());
                iteratorPosition.move(MZDirection.LEFT);
                iteratorPosition.move(MZDirection.UP);

                while (iteratorPosition.x() >= 0)
                {
                    if ((cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.RIGHT)) || (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.DOWN)))
                    {
                        break;
                    }
                    MZPosition tempPosition = iteratorPosition;
                    while (iteratorPosition.y() < _maze.height())
                    {
                        if ((cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.RIGHT)) || (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.DOWN)))
                        {
                            break;
                        }
                        _visitsMatrix.setLastVisit(_stepsCount, iteratorPosition);
                        iteratorPosition.move(MZDirection.UP);
                    }
                    iteratorPosition = tempPosition;
                    iteratorPosition.move(MZDirection.LEFT);
                }
            }

            if ((!cellMatrix.cellAtPosition(position).hasWallAtDirection(MZDirection.RIGHT)) && (!cellMatrix.cellAtPosition(position).hasWallAtDirection(MZDirection.DOWN)))
            {
                iteratorPosition = new MZPosition(position.x(), position.y());
                iteratorPosition.move(MZDirection.RIGHT);
                iteratorPosition.move(MZDirection.DOWN);

                while (iteratorPosition.x() < _maze.width())
                {
                    if ((cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.LEFT)) || (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.UP)))
                    {
                        break;
                    }
                    MZPosition tempPosition = iteratorPosition;
                    while (iteratorPosition.y() >= 0)
                    {
                        if ((cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.LEFT)) || (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.UP)))
                        {
                            break;
                        }
                        _visitsMatrix.setLastVisit(_stepsCount, iteratorPosition);
                        iteratorPosition.move(MZDirection.DOWN);
                    }
                    iteratorPosition = tempPosition;
                    iteratorPosition.move(MZDirection.RIGHT);
                }
            }

            if ((!cellMatrix.cellAtPosition(position).hasWallAtDirection(MZDirection.RIGHT)) && (!cellMatrix.cellAtPosition(position).hasWallAtDirection(MZDirection.UP)))
            {
                iteratorPosition = new MZPosition(position.x(), position.y());
                iteratorPosition.move(MZDirection.RIGHT);
                iteratorPosition.move(MZDirection.UP);

                while (iteratorPosition.x() < _maze.width())
                {
                    if ((cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.LEFT)) || (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.DOWN)))
                    {
                        break;
                    }
                    MZPosition tempPosition = iteratorPosition;
                    while (iteratorPosition.y() < _maze.height())
                    {
                        if ((cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.LEFT)) || (cellMatrix.cellAtPosition(iteratorPosition).hasWallAtDirection(MZDirection.DOWN)))
                        {
                            break;
                        }
                        _visitsMatrix.setLastVisit(_stepsCount, iteratorPosition);
                        iteratorPosition.move(MZDirection.UP);
                    }
                    iteratorPosition = tempPosition;
                    iteratorPosition.move(MZDirection.RIGHT);
                }
            }
        }