-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGroup.cs
70 lines (63 loc) · 1.65 KB
/
Group.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sudoku
{
public abstract class Group
{
public List<Cell> Cells { get; } = new List<Cell>();
public abstract bool Contains(Cell cell);
public bool HasRepetitions
{
get
{
var values = Cells.Where(c => c.Value.HasValue).Select(c => c.Value.Value).ToArray();
return values.Count() > values.Distinct().Count();
}
}
}
public class Square : Group
{
public Game Game { get; set; }
public int StartRowId { get; set; }
public int StartColumnId { get; set; }
public int EndRowId
{
get
{
return StartRowId + Game.Config.OrderRoot;
}
}
public int EndColumnId
{
get
{
return StartColumnId + Game.Config.OrderRoot;
}
}
public override bool Contains(Cell cell)
{
return
cell.RowId >= this.StartRowId && cell.RowId < this.EndRowId &&
cell.ColumnId >= this.StartColumnId && cell.ColumnId < this.EndColumnId;
}
}
public class Row : Group
{
public int Id { get; set; }
public override bool Contains(Cell cell)
{
return cell.RowId == this.Id;
}
}
public class Column : Group
{
public int Id { get; set; }
public override bool Contains(Cell cell)
{
return cell.ColumnId == this.Id;
}
}
}