private void CheckGameStatus() { if (MapStatus == GameEnum.MapStat.Filling) { foreach (Square s in squareList) { if (s.SquareValue == "0" || !s.IsValidate) return; } MapStatus = GameEnum.MapStat.Completed; } }
public void Init() { List<List<string>> triedValue = new List<List<string>>(); for (int i = 0; i < this.squareList.Count; i++) { triedValue.Add(new List<string>()); } Random r = new Random(); for (int i = 0; i < this.squareList.Count; i++) { Square s = squareList[i]; List<string> plist = s.ValidateValue.FindAll(obj => (!triedValue[i].Exists(obj2 => (obj2 == obj)))); if (plist.Count > 0) { s.SquareValue = plist[r.Next(0, plist.Count)]; triedValue[i].Add(s.SquareValue); } else //trace back { s.SquareValue = "0"; //Once we trace a square back and fill it again with a new value, the following square's tried history should be cleared; for (int j = i + 1; j < this.squareList.Count; j++) { triedValue[j].Clear(); } i -= 2; } } MapStatus = GameEnum.MapStat.Init; }
public void EraseRandomSquare(int eraseCount = 40) { Random r = new Random(); List<Square> emptySquare = new List<Square>(); while (emptySquare.Count < eraseCount) { emptySquare = squareList.FindAll(obj => obj.SquareValue == "0"); Square s = squareList[r.Next(0, squareList.Count)]; if (s.SquareValue != "0") { string temp = s.SquareValue; s.SquareValue = "0"; if (!this.HasUniqueSolution()) { s.SquareValue = temp; continue; } DrawMap(); } } MapStatus = GameEnum.MapStat.Filling; }