123456789101112131415161718192021222324252627 |
- using System;
- using uqac_ia_sudoku_csp.Interfaces;
-
- namespace uqac_ia_sudoku_csp.Solver.Constraints
- {
- public class BlockConstraint : IConstraint
- {
- public bool Check(Board board, int x, int y)
- {
- var bs = Math.Sqrt(board.Size);
- var sx = x / 3 * 3;
- var sy = y / 3 * 3;
- var cell = board.GetNumber(x, y).Value;
- for (var xx = sx; xx < sx + bs; ++xx)
- {
- for (var yy = sy; yy < sy + bs; ++yy)
- {
- if (cell == board.GetNumber(xx, yy) && (xx != x || yy != y))
- {
- return false;
- }
- }
- }
- return true;
- }
- }
- }
|