Exemple #1
0
        // sets the tile as a mine, stores it for future use and returns true if it is currently flagged
        public bool MineFound(SolverTile tile)
        {
            // if this is already known to be mine then nothing to do
            if (tile.IsMine())
            {
                return(tile.IsFlagged());
            }

            tilesLeft--;

            tile.SetAsMine(key);

            knownMines.Add(tile);

            if (tile.IsDead())
            {
                deadTiles.Remove(tile);  // remove the tile if it was on the dead list
            }
            //if (tile.IsExcluded()) {
            //    excludedTiles.Remove(tile); // remove the tile if it was excluded
            //   excludedMinesCount--;
            //}

            return(tile.IsFlagged());
        }
Exemple #2
0
        public void AddInformation(GameResult information)
        {
            //long start = DateTime.Now.Ticks;

            gameStatus = information.status;

            this.probabilityEngine = null; // previous probability engine invalidated

            newClears.Clear();

            // the game results tell us when a tile is cleared, flagged or unflagged
            foreach (ActionResult ar in information.actionResults)
            {
                if (ar.resultType == ResultType.Cleared)
                {
                    tilesLeft--;
                    tiles[ar.x, ar.y].SetValue(ar.value);

                    SolverTile tile = tiles[ar.x, ar.y];
                    newClears.Add(tile);
                    if (tile.IsDead())
                    {
                        deadTiles.Remove(tile);
                    }
                    //if (tile.IsExcluded()) {
                    //    excludedTiles.Remove(tile);
                    //}
                    //pendingClears.Remove(tile);
                }
                else if (ar.resultType == ResultType.Flagged)
                {
                    tiles[ar.x, ar.y].SetFlagged(true);
                }
                else if (ar.resultType == ResultType.Hidden)
                {
                    tiles[ar.x, ar.y].SetFlagged(false);
                }
                else if (ar.resultType == ResultType.Exploded)
                {
                    SolverTile tile = tiles[ar.x, ar.y];
                    tile.SetFlagged(false);
                    MineFound(tile);
                    this.bfa = null;   // can't walk the bfa tree if we've trodden on a mine
                }
            }

            // find and mark tiles as exhausted
            //int removed = 0;
            //if (newClears.Count > 0) {

            foreach (SolverTile tile in livingWitnesses)
            {
                if (AdjacentTileInfo(tile).hidden == 0)
                {
                    tile.SetExhausted();
                }
            }
            // remove all exhausted tiles from the list of witnesses
            livingWitnesses.RemoveWhere(x => x.IsExhausted());

            //}

            // add new witnesses which aren't exhausted
            foreach (SolverTile newTile in newClears)
            {
                AdjacentInfo adjInfo = AdjacentTileInfo(newTile);
                if (adjInfo.hidden != 0)
                {
                    if (adjInfo.excluded != adjInfo.hidden)
                    {
                        livingWitnesses.Add(newTile);
                    }
                    else
                    {
                        //excludedWitnesses.Add(newTile);
                    }
                }
            }

            //Write("There are " + livingWitnesses.Count + " living witnesses (" + removed + " deleted)");
            //Write("Adding Information to Solver took " + (DateTime.Now.Ticks - start) + " ticks");
        }
Exemple #3
0
        //public readonly bool isExcluded;

        public SolverAction(SolverTile tile, ActionType action, double safeprob) : base(tile.x, tile.y, action)
        {
            this.safeProbability = safeprob;
            this.isDead          = tile.IsDead();
            //this.isExcluded = tile.IsExcluded();
        }