示例#1
0
        /// <summary>
        ///     Changes logic within each tile, helping to generate the environment and agent tiles
        ///     Loops until appropriate environment found, or throws an error
        /// </summary>
        private void ModifyTileLogic()
        {
            var flag  = true;
            var count = 0;

            while (flag)
            {
                var matrixProducerClone = (ITileMatrixProducer)_tileMatrixProducer.Clone();
                var tilesCopy           = matrixProducerClone.Tiles;
                var spyEnvTile          = _spyTileLogic.SetSpyTile(tilesCopy);
                _envTileLogic.SetEnvTiles(tilesCopy);
                _pathFinder.GetPath(spyEnvTile);
                _exitTileLogic.CheckMatrix(tilesCopy);
                _guardTileLogic.GetMaxExitCount(_exitTileLogic.ExitCount);
                _guardTileLogic.GetPotentialGuardPlaces(tilesCopy);
                if (_exitTileLogic.ExitsAreAvailable())
                {
                    _exitTileLogic.SetExitTiles();
                    if (_guardTileLogic.GuardPlacesAreAvailable())
                    {
                        _guardTileLogic.SetGuardTiles();
                        _tileMatrix = tilesCopy;

                        flag = false;
                    }
                    else
                    {
                        count += 1;
                        if (count > _mapCreationTolerance)
                        {
                            throw new MapCreationException("Not enough free tiles to place guards");
                        }
                    }
                }
                else
                {
                    count += 1;
                    _exitTileLogic.CanProceed = true;
                    if (count > _mapCreationTolerance)
                    {
                        throw new MapCreationException(
                                  "Exits cannot be created: \n either the map is too small for the number of exits, or the spy cannot reach enough exit tiles");
                    }
                }
            }
        }