public void CreateBoard() { SoundManager.S.PlayBoardMusic(); SoundManager.S.StopMainMusic(); Puzzle puzzle = PuzzleReader.GeneratePuzzle(); for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { Vector3 pos = new Vector3(j * 5, 2.5f, i * 5); GameObject gridCell = Instantiate(cell, pos, Quaternion.identity); gridCell.GetComponent <GridCellController> ().row = i; gridCell.GetComponent <GridCellController> ().col = j; gridCell.GetComponent <GridCellController> ().num = puzzle.unsolved[i, j]; gridCell.GetComponent <GridCellController> ().solution = puzzle.solved[i, j]; if (puzzle.unsolved [i, j] == 0) { gridCell.GetComponent <GridCellController> ().hidden = true; } else { gridCell.GetComponent <GridCellController> ().hidden = false; } board[i, j] = (GridCellController)gridCell.GetComponent <GridCellController>(); } } }
public SudokuSolver() { Puzzle = new SudokuPuzzle(); Engine = new PuzzleEngine <int>(Puzzle); PuzzleReader = new PuzzleReader(); Engine.SolverFinishedEvent += Engine_SolverFinishedEvent; }
public void ReadTest() { PuzzleReader target = new PuzzleReader(); string filename = @"..\..\..\TestSolverLib\puzzlefiles\puzzle4.txt"; IList <int> values = target.Read(filename); Assert.AreEqual(81, values.Count, "PuzzleReader didn't read all 81 values"); }
public void TestRead4x4Puzzle() { string[] expectedRows = "42-1\n-4-1\n1-2-\n-4-2".Split(); Puzzle testPuzzle = new Puzzle(4, "1234", expectedRows); Puzzle inputPuzzle = PuzzleReader.ReadPuzzle("testPuzzle.txt"); Assert.AreEqual(testPuzzle.PuzzleLength, inputPuzzle.PuzzleLength); }
public void Load(string filename) { PuzzleReader reader = new PuzzleReader(); IList <int> list = reader.Read(filename); ISpace <int> initialValues = new Space <int>(new Possible() { 1, 2, 3, 4, 5, 6, 7, 8, 9 }); reader.ConvertToInitialValues(list, initialValues); Engine.SetInitialValues(initialValues); }
public void TestSolve() { var id = 3; var puzzle = PuzzleReader.ReadFromFile(id); //puzzle.MinVertices = 3000; //puzzle.MaxVertices = puzzle.MinVertices + 100; var problem = new MstPuzzleSolver().Solve(puzzle); var path = Path.Combine(FileHelper.PatchDirectoryName("problems"), "puzzles", $"block{id:000}.desc"); File.WriteAllText(path, problem.ToString()); problem.IsValidForPuzzle(puzzle).Should().BeTrue(); }
// //You can use the following additional attributes as you write your tests: // //Use ClassInitialize to run code before running the first test in the class //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //Use ClassCleanup to run code after all tests in a class have run //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //Use TestInitialize to run code before running each test //[TestInitialize()] //public void MyTestInitialize() //{ //} // //Use TestCleanup to run code after each test has run //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion /// <summary> ///A test for Solve ///</summary> public void SolveTestHelper <TKey>() { SudokuPuzzle sudokuPuzzle = new SudokuPuzzle(); IPuzzleEngine <int> engine = new PuzzleEngine <int>(sudokuPuzzle); // Read values PuzzleReader reader = new PuzzleReader(); const string filename = "C:\\projects\\src\\2009\\Solver\\superfiend.txt"; IList <int> list = reader.Read(filename); ISpace <int> initialValues = new Space <int>(new Possible() { 1, 2, 3, 4, 5, 6, 7, 8, 9 }); reader.ConvertToInitialValues(list, initialValues); engine.SetInitialValues(initialValues); int remaining = sudokuPuzzle.Space.Unsolved(); Assert.AreEqual(53, remaining, "Did not read 28 values"); // debug handler foreach (KeyValuePair <int, IPossible> pair in engine.Puzzle.Space) { pair.Value.NoValuesLeft += new Possible.NoValuesLeftFunction(Value_NoValuesLeft); } //const bool expected = true; engine.Solve(false); remaining = sudokuPuzzle.Space.Unsolved(); SpaceAdapter <int> .WriteConsole(sudokuPuzzle.Space); string message = string.Format("Puzzle did not get solved. {0} spaces remaining.", remaining); Assert.AreEqual(0, engine.Count, "Not all tasks have completed"); Assert.AreEqual(0, remaining, message); }
public void ReadFromFile() { var puzzle = PuzzleReader.ReadFromFile(1); puzzle.ToString().Should().Be("1,1,150,400,1200,6,10,5,1,3,4#(73,61),(49,125),(73,110),(98,49),(126,89),(68,102),(51,132),(101,123),(22,132),(71,120),(97,129),(118,76),(85,100),(88,22),(84,144),(93,110),(96,93),(113,138),(91,52),(27,128),(84,140),(93,143),(83,17),(123,85),(50,74),(139,97),(101,110),(77,56),(86,23),(117,59),(133,126),(83,135),(76,90),(70,12),(12,141),(116,87),(102,76),(19,138),(86,129),(86,128),(83,60),(100,98),(60,105),(61,103),(94,99),(130,124),(141,132),(68,84),(86,143),(72,119)#(145,82),(20,65),(138,99),(38,137),(85,8),(125,104),(117,48),(57,48),(64,119),(3,25),(40,22),(82,54),(121,119),(1,34),(43,98),(97,120),(10,90),(15,32),(41,13),(86,40),(3,83),(2,127),(4,40),(139,18),(96,49),(53,22),(5,103),(112,33),(38,47),(16,121),(133,99),(113,45),(50,5),(94,144),(16,0),(93,113),(18,141),(36,25),(56,120),(3,126),(143,144),(99,62),(144,117),(48,97),(69,9),(0,9),(141,16),(55,68),(81,3),(47,53)"); }
public async Task ReadCurrentFromApi() { var puzzle = await PuzzleReader.ReadCurrentFromApiAsync(); puzzle.Should().NotBeNull(); }
public void TestParseFile() { string filePath = Path.Combine(_context.TestRunDirectory, "..", "..", "Readers", "Artifacts", "PuzzleReaderTestInput.txt"); Assert.AreEqual(4, PuzzleReader.GetInputLines(filePath).Count()); }
public static int Main(string[] args) { if (1 != args.Length) { Console.WriteLine("Arguments (1): puzzleDay"); return(-1); } if (!Int32.TryParse(args[0], out int day)) { Console.WriteLine("Could not parse puzzle day."); return(-1); } if (day <= 0 || day > MAX_DAY) { Console.WriteLine($"Please select a day between 1 and {MAX_DAY}"); return(-1); } string assemblyLocation = Assembly.GetAssembly(typeof(Program)).Location; string projectRootDirectory = Directory .GetParent(assemblyLocation) .Parent .Parent .Parent .FullName; string puzzleFileName = string.Format("Day{0:D2}.txt", day); string puzzleFilePath = Path.Combine(projectRootDirectory, "Puzzles", puzzleFileName); if (!File.Exists(puzzleFilePath)) { Console.WriteLine("Puzzle Input Not Found."); return(-1); } Solver solver = CreateSolver(day); if (solver is not Solver) { Console.WriteLine("Solver creation failed."); return(-1); } // Initialisation. TimeSpan ts; string solution; Stopwatch stopwatch = new Stopwatch(); List <string> input = PuzzleReader.GetInputLines(puzzleFilePath).ToList(); // Part 1. stopwatch.Start(); solution = solver.SolvePartA(input); stopwatch.Stop(); ts = stopwatch.Elapsed; Console.WriteLine($"Part 1: {solution}"); Console.WriteLine("Time 1: {0:D2}.{1:D3} seconds.", ts.Seconds, ts.Milliseconds); // Part 2. stopwatch.Restart(); solution = solver.SolvePartB(input); stopwatch.Stop(); ts = stopwatch.Elapsed; Console.WriteLine($"Part 2: {solution}"); Console.WriteLine("Time 2: {0:D2}.{1:D3} seconds.", ts.Seconds, ts.Milliseconds); return(0); }
public void TestReadPuzzleNull() { Puzzle testPuzzle = PuzzleReader.ReadPuzzle(null); Assert.AreEqual(testPuzzle, null); }
public void TestReadPuzzleDoesntExist() { Puzzle testPuzzle = PuzzleReader.ReadPuzzle("abc"); Assert.IsNull(testPuzzle); }