예제 #1
0
        private List<int> GetEffectivePossibilities(List<CellState> cellStates, CellState cstate, List<Cell> cell)
        {
            cell.RemoveAll(x => x.Value != 0);
            var possibilities_within_group = new List<int>();

            foreach (var item in cell)
            {
                if (item.Column == cstate.Cell.Column && item.Row == cstate.Cell.Row)
                    continue;

                var itemstate = cellStates
                    .Where(c => c.Cell.Row == item.Row && c.Cell.Column == item.Column)
                    .Single();

                possibilities_within_group.AddRange(itemstate.Possibilities);
            }

            var effectivepossibilities = new List<int>();

            foreach (var item in cstate.Possibilities)
            {
                if (!possibilities_within_group.Contains(item))
                {
                    effectivepossibilities.Add(item);
                }
            }
            return effectivepossibilities.Count == 1 ?
                effectivepossibilities : cstate.Possibilities;
        }
예제 #2
0
        private List<CellState> GetCellState()
        {
            var cells = this.maze.GetEmptyCells();
            var needtoUpdateCellState = cells.Count > 0;

            List<CellState> cellStates = new List<CellState>();

            while (needtoUpdateCellState)
            {
                needtoUpdateCellState = false;
                var cstate = new List<CellState>();

                foreach (var cell in (cells = cells.Where(x => x.Value == 0).ToList()))
                {
                    var cs = new CellState()
                    {
                        Cell = cell,
                        Possibilities = GetPosibilities(cell),
                    };

                    if (needtoUpdateCellState = (cs.Possibilities.Count == 1))
                    {
                        cell.Value = cs.Possibilities.First();

                        if (needSteps)
                        {
                            Steps.Add(new StepInfo(
                                Step.SET,
                                cell.Row,
                                cell.Column,
                                cell.Value,
                                string.Format("Cell ({1},{2}) has only one possibility and that is {0}.", cell.Value, cell.Row, cell.Column)
                                ));
                        }

                        break;
                    }

                    if (cs.Possibilities.Count == 0)
                    {
                        HandleCellStateError(cs);
                        cells = this.maze.GetEmptyCells();
                        needtoUpdateCellState = true;
                        break;
                    }

                    cstate.Add(cs);
                }

                cellStates = cstate;
            }

            return cellStates;
        }
예제 #3
0
 private void HandleCellStateError(CellState cs)
 {
     if (SpeculationOn)
         HandleSpeculationError();
 }