12345678910111213141516171819202122232425262728293031323334353637383940 |
- using System.Collections.Generic;
- using System.Linq;
- using uqac_ia_sudoku_csp.Interfaces;
-
- namespace uqac_ia_sudoku_csp.Solver.NextValueChoosers
- {
- public class DhNextCellChooser : INextCellChooser
- {
- public void SelectVariable(Board board, out int x, out int y, IList<IConstraint> constraints)
- {
- var dict = new Dictionary<KeyValuePair<int, int>, int>();
- for (var yy = 0; yy < board.Size; ++yy)
- {
- for (var xx = 0; xx < board.Size; ++xx)
- {
- if (board.GetNumber(xx, yy) == null)
- {
- var k = new KeyValuePair<int, int>(xx, yy);
- if (!dict.ContainsKey(k))
- {
- dict.Add(k, 0);
- }
- ++dict[k];
- }
- }
- }
- if (!dict.Any())
- {
- x = -1;
- y = -1;
- }
- else
- {
- var k = dict.OrderByDescending(pair => pair.Value).First().Key;
- x = k.Key;
- y = k.Value;
- }
- }
- }
- }
|