Beispiel #1
0
        public WoodTravelerAgent(MainWindow appDisplayer, MagicWood environment)
        {
            _appDisplayer    = appDisplayer;
            _environment     = environment;
            _currentPosition = _environment.PlaceAgent();
            _rules           = RulesGenerator.Instance.GeneratedRules;

            _beliefs = new WoodSquare[environment.SqrtSize, environment.SqrtSize];
            for (int x = 0; x < environment.SqrtSize; x++)
            {
                for (int y = 0; y < environment.SqrtSize; y++)
                {
                    _beliefs[x, y] = new WoodSquare(new Vector2(x, y));
                    if (x == _currentPosition.X && y == _currentPosition.Y)
                    {
                        _beliefs[x, y].MarkedAsExplored(false);
                    }
                    if (((x == _currentPosition.X - 1 || x == _currentPosition.X + 1) && y == _currentPosition.Y) ||
                        ((y == _currentPosition.Y + 1 || y == _currentPosition.Y - 1) && x == _currentPosition.X))
                    {
                        _beliefs[x, y].Unblock();
                    }
                }
            }
        }
Beispiel #2
0
        private float RiftProbability(WoodSquare toCompute, List <List <WoodSquare> > coherentCombinations, int explorableTilesCount)
        {
            float sumIsRift    = 0;
            float sumIsNotRift = 0;

            foreach (List <WoodSquare> combination in coherentCombinations)
            {
                if (combination.Contains(toCompute))
                {
                    sumIsRift += (float)(Math.Pow(0.1, combination.Count) * Math.Pow(0.9, explorableTilesCount - combination.Count));
                }
                else
                {
                    sumIsNotRift += (float)(Math.Pow(0.1, combination.Count) * Math.Pow(0.9, explorableTilesCount - combination.Count));
                }
            }

            sumIsRift    *= 0.1f;
            sumIsNotRift *= 0.9f;

            return(sumIsRift / (sumIsRift + sumIsNotRift));
        }
Beispiel #3
0
        private List <WoodSquare> GetNeighbours(WoodSquare tile)
        {
            List <WoodSquare> neighbours = new List <WoodSquare>();
            Vector2           pos        = tile.Position;

            if (pos.X > 0)
            {
                neighbours.Add(_beliefs[pos.X - 1, pos.Y]);
            }
            if (pos.X < _environment.SqrtSize - 1)
            {
                neighbours.Add(_beliefs[pos.X + 1, pos.Y]);
            }
            if (pos.Y > 0)
            {
                neighbours.Add(_beliefs[pos.X, pos.Y - 1]);
            }
            if (pos.Y < _environment.SqrtSize - 1)
            {
                neighbours.Add(_beliefs[pos.X, pos.Y + 1]);
            }
            return(neighbours);
        }
Beispiel #4
0
        /// <summary>
        /// Planifie le prochain effecteur a execute
        /// </summary>
        void PlanNextMove()
        {
            if (_beliefs[_currentPosition.X, _currentPosition.Y].IsAnExit)
            {
                _queuedActions.Enqueue(new Leave(_currentPosition));
                return;
            }

            List <WoodSquare> explorableTiles = new List <WoodSquare>();
            List <WoodSquare> exploredTiles   = new List <WoodSquare>();

            for (int i = 0; i < _environment.SqrtSize; i++)
            {
                for (int j = 0; j < _environment.SqrtSize; j++)
                {
                    if (_beliefs[i, j].Explored)
                    {
                        exploredTiles.Add(_beliefs[i, j]);
                    }
                    else if (_beliefs[i, j].CanExplore)
                    {
                        explorableTiles.Add(_beliefs[i, j]);
                    }
                }
            }

            //sera utilisée si l'on ne trouve pas de case sûre
            List <WoodSquare> canOnlyHaveMonster = new List <WoodSquare>();

            //recherche d'une case sûre
            foreach (WoodSquare tile in explorableTiles)
            {
                if (tile.ShouldBeSafe)
                {
                    _queuedActions.Enqueue(new Move(tile.Position));
                    return;
                }
                else if (tile.MayHaveAMonster && !tile.MayBeARift)
                {
                    canOnlyHaveMonster.Add(tile);
                }
            }

            //pas de case sûre, on cherche donc une case ne pouvant pas contenir de crevasse
            if (canOnlyHaveMonster.Count != 0)
            {
                _queuedActions.Enqueue(new Throw(canOnlyHaveMonster[0].Position));
                _queuedActions.Enqueue(new Move(canOnlyHaveMonster[0].Position));
                return;
            }

            List <WoodSquare> windyTiles = new List <WoodSquare>();

            foreach (WoodSquare tile in exploredTiles)
            {
                if (tile.HasWind)
                {
                    windyTiles.Add(tile);
                }
            }

            List <WoodSquare> possibleRifts = new List <WoodSquare>();

            foreach (WoodSquare tile in explorableTiles)
            {
                if (tile.MayBeARift)
                {
                    possibleRifts.Add(tile);
                }
            }


            Debug.WriteLine("probability computation");
            List <List <WoodSquare> > coherentCombinations = GetAllCoherentCombinations(possibleRifts, windyTiles);

            float      minRiftProb = 2;
            WoodSquare toExplore   = new WoodSquare(new Vector2(-1, -1));

            foreach (WoodSquare tile in explorableTiles)
            {
                float riftProb = RiftProbability(tile, coherentCombinations, explorableTiles.Count);
                if (riftProb < minRiftProb && !tile.Deadly)
                {
                    minRiftProb = riftProb;
                    toExplore   = tile;
                }
            }

            if (toExplore.MayHaveAMonster)
            {
                _queuedActions.Enqueue(new Throw(toExplore.Position));
            }
            _queuedActions.Enqueue(new Move(toExplore.Position));
            return;
        }