Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace SudokuLibrary
- {
- public class Controller
- {
- private const int Length = 9;
- private int[,] arr;
- public int[,] Array
- {
- get
- {
- if (arr == null)
- arr = new int[Length, Length];
- return arr;
- }
- }
- public bool CheckCell(int i, int j, int num)
- {
- // if this numer was found returns false and whole function returns false
- if (CheckSquare(i, j, num) == false )
- return false;
- // if this numer was found returns false and whole function returns false
- if (CheckRow(i, num) == false)
- return false;
- // if this numer was found returns false and whole function returns false
- if (CheckColumn(j, num) == false)
- return false;
- // otherwise returns true
- return true;
- }
- /// <summary>
- /// returns true if no num in square around was found. Otherwise returns false
- /// </summary>
- /// <param name="i">x coordinate of input </param>
- /// <param name="j">y coordinate of input</param>
- /// <param name="num">the numer of input </param>
- /// <returns></returns>
- private bool CheckSquare(int i, int j, int num)
- {
- for (int x = i/3; x < i / 3 + 1; x++)
- {
- for (int y = j/3; y < 3 + 1; y++)
- {
- if (arr[x, y] == num)
- return false;
- }
- }
- return true;
- }
- /// <summary>
- /// returns true if no num was found in row. Otherwise false
- /// </summary>
- /// <param name="i"></param>
- /// <param name="num"></param>
- /// <returns></returns>
- private bool CheckRow(int i, int num)
- {
- for (int y = 0; y < Length; y++)
- {
- if (arr[i,y] == num)
- return false;
- }
- return true;
- }
- /// <summary>
- /// returns true if no num was found in column. Otherwise false
- /// </summary>
- /// <param name="j"></param>
- /// <param name="num"></param>
- /// <returns></returns>
- private bool CheckColumn(int j, int num)
- {
- for (int x = 0; x < Length; x++)
- {
- if (arr[x,j] == num)
- return false;
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement