public void Clone() { Position position = new Position(); position.PutNumberAt(1, 0, 0); position.PutNumberAt(2, 1, 0); position.PutNumberAt(3, 2, 0); position.PutNumberAt(3, 3, 3); position.PutNumberAt(4, 4, 3); position.PutNumberAt(5, 5, 3); position.PutNumberAt(6, 6, 6); position.PutNumberAt(7, 7, 6); position.PutNumberAt(8, 8, 6); Position newposition = position.Clone(); Assert.AreEqual(position.Size, newposition.Size); Assert.AreEqual(position.Range, newposition.Range); for (int x = 0; x < position.Size; x++) for (int y = 0; y < position.Size; y++) Assert.AreEqual(newposition.GetNumberAt(x, y), position.GetNumberAt(x, y)); }
public void ValidMoves() { Position position = new Position(); position.PutNumberAt(5, 1, 1); Assert.IsFalse(position.CanPutNumberAt(5, 1, 1)); Assert.IsTrue(position.CanPutNumberAt(4, 0, 0)); Assert.IsTrue(position.CanPutNumberAt(4, 1, 8)); Assert.IsTrue(position.CanPutNumberAt(4, 8, 1)); Assert.IsTrue(position.CanPutNumberAt(4, 8, 8)); Assert.IsTrue(position.CanPutNumberAt(4, 2, 8)); Assert.IsTrue(position.CanPutNumberAt(4, 8, 2)); }
public void RaiseIfNumbersAreInARow() { Position position = new Position(); position.PutNumberAt(1, 0, 0); position.PutNumberAt(1, 5, 0); }
public void RaiseIfNumbersAreInAColumn() { Position position = new Position(); position.PutNumberAt(1, 5, 5); position.PutNumberAt(1, 5, 2); }
public void RaiseIfNumberIsZero() { Position position = new Position(); position.PutNumberAt(0, 0, 0); }
public void RaiseIfNumberIsTooLarge() { Position position = new Position(); position.PutNumberAt(10, 0, 0); }
public void RaiseIfNumberIsNegative() { Position position = new Position(); position.PutNumberAt(-1, 0, 0); }
public void RaiseIfNumberAreInSameSquare() { Position position = new Position(); position.PutNumberAt(1, 0, 0); position.PutNumberAt(1, 2, 2); }
public void RaiseIfCellIsNotEmpty() { Position position = new Position(); position.PutNumberAt(1, 0, 0); position.PutNumberAt(2, 0, 0); }
public void PutANumber() { Position position = new Position(); position.PutNumberAt(1, 0, 0); Assert.AreEqual(1, position.GetNumberAt(0, 0)); }
public void DetectColisions() { Position position = new Position(); position.PutNumberAt(5, 1, 1); Assert.IsFalse(position.CanPutNumberAt(5, 1, 1)); Assert.IsFalse(position.CanPutNumberAt(5, 0, 0)); Assert.IsFalse(position.CanPutNumberAt(5, 1, 8)); Assert.IsFalse(position.CanPutNumberAt(5, 8, 1)); }
public static void Main(string[] args) { string gametxt = args[0]; Position position = new Position(gametxt); positions.Push(position); while (positions.Count > 0) { position = positions.Pop(); DumpPosition(position); CellInfo ci = solver.Resolve(position); while (ci != null) { System.Console.WriteLine(String.Format("{0} at {1} {2}", ci.Number, ci.X + 1, ci.Y + 1)); position.PutNumberAt(ci.Number, ci.X, ci.Y); DumpPosition(position); ci = solver.Resolve(position); } if (position.Solved) break; List<List<CellInfo>> results = solver.GetPossibleMoves(position); if (results.Count == 0) { System.Console.WriteLine("No Branch"); continue; } bool hasbranches = false; foreach (List<CellInfo> cells in results) { if (cells.Count != 2) continue; foreach (CellInfo cell in cells) { System.Console.WriteLine(String.Format("Branch {0} at {1} {2}", cell.Number, cell.X + 1, cell.Y + 1)); Position newposition = position.Clone(); newposition.PutNumberAt(cell.Number, cell.X, cell.Y); DumpPosition(newposition); positions.Push(newposition); } hasbranches = true; break; } if (!hasbranches) System.Console.WriteLine("No Branch 2"); } System.Console.ReadLine(); }