public Map() { squareList = new List<Square>(columnNum * rowNum); for (int row = 0; row < rowNum; row++) { for (int col = 0; col < columnNum; col++) { Square s = new Square(row, col); squareList.Add(s); } } foreach (Square s in squareList) { s.Peers = squareList.FindAll(obj => (obj.Column == s.Column || obj.Row == s.Row || s.IsInOneUnit(obj))); s.Peers.Remove(s); } }
public bool IsInOneUnit(Square obj) { return (obj.Column * 3 / 9 == Column * 3 / 9 && obj.Row * 3 / 9 == Row * 3 / 9); }