コード例 #1
0
ファイル: Solver.cs プロジェクト: lucidBrot/mineDeeper
        private bool ConsiderTheRule(IRule rule, BoardCell cell, bool modifyBoard)
        {
            ICollection <ConsiderationReportForCell> report = new List <ConsiderationReportForCell>();
            bool computationAdvanced = rule.Consider(this.board, cell, report);

            if (modifyBoard)
            {
                // todo: for paralellization, consider carefully how the unfoundBombs are updated! Best is only once, to avoid counting the same finding twice. Probably should compute it from the list instead and remove the out param.
                // todo: make this method static in the end.
                // reduce number of Unfound Bombs
                report.Where(c => c.TargetState == CellState.Suspect).Distinct()
                .ForAll(cc =>
                {
                    numUnfoundBombs--;
                    board[cc.PosX, cc.PosY, cc.PosZ].State = CellState.Suspect;
                });

                // reveal safe cells
                report.Where(c => c.TargetState == CellState.Revealed).Distinct()
                .ForAll(cc =>
                        board.Reveal(board[cc.PosX, cc.PosY, cc.PosZ]
                                     ));
            }

            // todo: check if some cell is in both sets (or is already set to Suspect but should be revealed according to some rule now) and generate according hint to the user.
            return(computationAdvanced);
        }