public void AllSolverRulesCanGiveHints() { Board testBoard = new Board(3, 3, 3); testBoard.SetBombState(0, 0, 1, true); testBoard.SetBombState(0, 2, 1, true); testBoard[0, 1, 1].State = CellState.Revealed; testBoard[1, 1, 1].State = CellState.Revealed; Solver.Solver solver = new Solver.Solver(testBoard); (var a, var b) = solver.GetRuleListsForTesting(); List <Type> hintRuleTypes = new List <Type>(); foreach (IHintRule hintRule in b) { var tb = hintRule.GetType(); hintRuleTypes.Add(tb); } foreach (IRule rule in a) { var ta = rule.GetType(); bool okay = hintRuleTypes.Contains(ta); Assert.True(okay, "Every Solver Rule should be represented in the hint rules. If this is not the case, think again about whether this should be required. Look at the lists in Solver.cs"); } }
public void KevinExampleSolvable() { /* Solution: Given: Num bombs: 10 * x 5 x ? 5 ? * x x x ? ? ? * x 8 x ? 8 ? * x x x ? ? ? */ Board board = new Board(3, 4, 1); board.SetBombState(0, 0, 0, true); board.SetBombState(2, 0, 0, true); board.SetBombState(0, 1, 0, true); board.SetBombState(1, 1, 0, true); board.SetBombState(2, 1, 0, true); board.SetBombState(0, 2, 0, true); board.SetBombState(2, 2, 0, true); board.SetBombState(0, 3, 0, true); board.SetBombState(1, 3, 0, true); board.SetBombState(2, 3, 0, true); board[1, 0, 0].State = CellState.Revealed; board[1, 2, 0].State = CellState.Revealed; Assert.AreEqual(10, board.BombCount, "Wrong number of bombs!"); Solver.Solver solver = new Solver.Solver(board); Assert.AreEqual(true, solver.IsSolvable(), "Should be solvable using a simple rule: all neighbors are bombs"); }
public SolverDrawerPipe(OCAIS2D_InteractiveContext context2d, OCV2d_View view2d, Solver.Solver solver, SolverDrawer solverDrawer) : base(ActionNames.SolverDrawerPipe) { _solver = solver; _solverDrawer = solverDrawer; _context2d = context2d; _view2d = view2d; }
public void AbortReturnsFalseAndTrue() { // This should not be solvable (same Test as Gandalf) /* given: * x 2 x ? 2 ? * 1 2 1 ? 2 ? * 0 0 0 0 0 0 */ Board testBoard = new Board(3, 3, 3); testBoard.SetBombState(0, 0, 1, true); testBoard.SetBombState(0, 2, 1, true); testBoard[0, 1, 1].State = CellState.Revealed; testBoard[1, 1, 1].State = CellState.Revealed; Solver.Solver solver = new Solver.Solver(testBoard); var Blubb = Task.Run(() => { var res = solver.IsSolvable(); Debug.Log("solving done!"); return(res); }); solver.Abort(); Debug.Log("aborted."); bool solvable = Blubb.Result; Assert.AreEqual(false, solvable, "Gandalf 3D the white shall not pass."); Assert.AreEqual(true, solver.HasAborted, "Gandalf 3D the grey shall not pass."); }
public void JolandaTest() { Board board = new Board(2, 2, 2); board[0, 0, 0].State = CellState.Revealed; board.SetBombState(0, 0, 1, true); Solver.Solver solver = new Solver.Solver(board); Assert.False(solver.IsSolvable(), "This is not solvable without guesswork"); }
public void NoraTest() { // A cube with no bombs and one revealed Board board = new Board(4, 4, 4); board[3, 2, 2].State = CellState.Revealed; Solver.Solver solver = new Solver.Solver(board); Assert.True(solver.IsSolvable()); }
public void MinimalTest() { // A cube with no bombs and one revealed Board board = new Board(1, 1, 2); board[0, 0, 0].State = CellState.Revealed; board.SetBombState(0, 0, 1, true); Solver.Solver solver = new Solver.Solver(board); Assert.True(solver.IsSolvable()); }
// you can get this code after registration on the server with your email // http://server-ip:8080/codenjoy-contest/board/player/[email protected]?code=12345678901234567890 static void Main(string[] args) { Console.SetWindowSize(Console.LargestWindowWidth - 3, Console.LargestWindowHeight - 3); // creating custom Minesweeper's Ai client var tetrisPlayer = new Solver.Solver(ServerUrl); // starting thread with playing Minesweeper Thread thread = new Thread(tetrisPlayer.Play); thread.Start(); thread.Join(); }
public void Gandalf3DExampleNotSolvable() { // This should not be solvable /* given: * x 2 x ? 2 ? * 1 2 1 ? 2 ? * 0 0 0 0 0 0 */ Board testBoard = new Board(3, 3, 3); testBoard.SetBombState(0, 0, 1, true); testBoard.SetBombState(0, 2, 1, true); testBoard[0, 1, 1].State = CellState.Revealed; testBoard[1, 1, 1].State = CellState.Revealed; Solver.Solver solver = new Solver.Solver(testBoard); Assert.AreEqual(false, solver.IsSolvable(), "Gandalf 3D shall not pass."); }
public void TaelurExampleSolvable() { /* * Solution: Given (with num bombs = 3) * 0 1 1 ? ? 1 * 1 2 x ? ? ? * 1 x 2 1 ? 2 */ Board testBoard = new Board(3, 3, 1); testBoard.SetBombState(1, 2, 0, true); testBoard.SetBombState(2, 1, 0, true); testBoard[0, 2, 0].State = CellState.Revealed; testBoard[2, 2, 0].State = CellState.Revealed; testBoard[2, 0, 0].State = CellState.Revealed; Solver.Solver solver = new Solver.Solver(testBoard); Assert.AreEqual(true, solver.IsSolvable(), "TaelurExample should be solvable"); }
public override void Run() { Application.DoEvents(); attachedView = WorkItem.SmartParts.AddNew <SketcherView>(Constants.SmartPartNames.SketcherView); InitializeOpenCascade2D(); // Initialize the solver _solver = new Solver.Solver(); _solver.RuleSet = new RuleSet(); _solver.RuleSet.Rules.Add(new PointMatch()); _solverDrawer = new SolverDrawer(); InitializeInputs(); InitializeActions(); SwitchActionType(ActionType.Action2d_Nothing, null); }
public void TinaTest() { /* * ? ? ? ? * ? 7 7 ? * ? ? ? ? */ Board board = new Board(4, 3, 1); foreach (BoardCell cell in board.Cells) { board.SetBombState(cell.PosX, cell.PosY, cell.PosZ, true); } board.SetBombState(1, 1, 0, false); board.SetBombState(2, 1, 0, false); board[1, 1, 0].State = CellState.Revealed; board[2, 1, 0].State = CellState.Revealed; Solver.Solver solver = new Solver.Solver(board); Assert.True(solver.IsSolvable()); }
public void HerbertExampleSolvable() { /* * Solution: Given (with num bombs = 3) * x x 1 0 o o 1 o * x 3 1 0 o 3 1 o * 1 1 0 0 1 1 o o */ Board testBoard = new Board(4, 3, 1); testBoard.SetBombState(0, 0, 0, true); testBoard.SetBombState(0, 1, 0, true); testBoard.SetBombState(1, 0, 0, true); testBoard[0, 2, 0].State = CellState.Revealed; testBoard[1, 1, 0].State = CellState.Revealed; testBoard[2, 0, 0].State = CellState.Revealed; testBoard[2, 1, 0].State = CellState.Revealed; Solver.Solver solver = new Solver.Solver(testBoard); Assert.AreEqual(true, solver.IsSolvable(), "HerbertExample should be solvable but that functionality is not implemented yet. See " + "ConsiderAllOptionsForTwoBombsAndFindThatOnlyOneOptionIsLegal for inspiration"); }
private void OnSolve(object sender, RoutedEventArgs e) { var solution = new Solver.Solver().solve(SampleData.StarterPuzzles[0]); _theBoard.NewPuzzle(solution); }
public MainPageVM() { AvailableOperations = new List <AvailableOperationVM> { new AvailableOperationVM("Add +", vm => !vm.TryParseValue1(out var value1) ? null : new ArithmeticOperation(value1, ArithmeticOperationType.Add), () => new SingleItemView()), new AvailableOperationVM("Subtract -", vm => !vm.TryParseValue1(out var value1) ? null : new ArithmeticOperation(value1, ArithmeticOperationType.Subtract), () => new SingleItemView()), new AvailableOperationVM("Multiply x", vm => !vm.TryParseValue1(out var value1) ? null : new ArithmeticOperation(value1, ArithmeticOperationType.Multiply), () => new SingleItemView()), new AvailableOperationVM("Divide /", vm => !vm.TryParseValue1(out var value1) ? null : new ArithmeticOperation(value1, ArithmeticOperationType.Divide), () => new SingleItemView()), new AvailableOperationVM("Power x^n", vm => !vm.TryParseValue1(out var value1) ? null : new ArithmeticOperation(value1, ArithmeticOperationType.Pow), () => new SingleItemView()), new AvailableOperationVM("Append", vm => !vm.TryParseValue1(out var value1) ? null : new AppendOperation(value1), () => new SingleItemView()), new AvailableOperationVM("Replace =>", delegate(AvailableOperationVM vm) { if (!vm.TryParseValue1(out _)) { return(null); } if (!vm.TryParseValue2(out _)) { return(null); } return(new ReplaceOperation(vm.Value1, vm.Value2)); }, () => new ReplaceOperationView()), new AvailableOperationVM("Invert sign +/-", _ => new InvertSignOperation()), new AvailableOperationVM("Remove last <<", _ => new RemoveLastOperation()), new AvailableOperationVM("Reverse", _ => new ReverseOperation()), new AvailableOperationVM("Sum", _ => new SumOperation()), new AvailableOperationVM("< Shift", _ => new ShiftOperation(false)), new AvailableOperationVM("Shift >", _ => new ShiftOperation(true)), new AvailableOperationVM("Mirror", _ => new MirrorOperation()), new AvailableOperationVM("Changer [+]", vm => !vm.TryParseValue1(out var value1) ? null : new ChangerOperation(value1), () => new SingleItemView()), new AvailableOperationVM("Store", _ => new StoreOperation()), new AvailableOperationVM("Inv10", _ => new Inv10Operation()), }; Operations = new ObservableCollection <OperationVM>(); CommandAddOperation = new Command((Action) delegate { var operation = CurrentOperation?.CreateOperationFunc(CurrentOperation); if (operation != null) { Operations.Add(new OperationVM(operation)); } }); CommandClear = new Command((Action) delegate { Moves = null; Initial = null; Goal = null; Operations.Clear(); CurrentOperation = null; IsSolutionFound = false; PortalIn = null; PortalOut = null; }); CommandSolveIt = new Command((Action)async delegate { if (!int.TryParse(Moves, out var moves) || moves <= 0) { return; } if (!int.TryParse(Goal, out var goal)) { return; } if (!int.TryParse(Initial, out var current)) { return; } if (Operations.Count == 0) { return; } int portalIn = 0, portalOut = 0; if (!string.IsNullOrEmpty(PortalIn) && !int.TryParse(PortalIn, out portalIn)) { return; } if (!string.IsNullOrEmpty(PortalOut) && !int.TryParse(PortalOut, out portalOut)) { return; } Busy.IsBusy = true; var res = await Task.Run(delegate { var solver = new Solver.Solver(Operations.Select(_ => _.Operation).ToList(), goal, portalIn, portalOut); var result = solver.Solve(current, moves); return(result); }); if (res != null) { Operations.Clear(); foreach (var operation in res) { Operations.Add(new OperationVM(operation)); } IsSolutionFound = true; } else { DisplayAlert("Error", "Solution is not found!", "OK"); } Busy.IsBusy = false; });
/// <summary> /// Generates a board with an arbitrary initial guess. Tries to solve that board, and if that works, returns it. /// Returns <code>null</code> if it was abort()'ed. /// </summary> /// <param name="boardWidth"></param> /// <param name="boardHeight"></param> /// <param name="boardDepth"></param> /// <param name="numBombs"></param> /// <returns></returns> public Board Generate(uint boardWidth, uint boardHeight, uint boardDepth, uint numBombs, bool disableSolving = false) { // reset this.ShouldAbort just to safeguard against Generator reuse after abort() has been called. this.ShouldAbort = false; if (boardWidth * boardHeight * boardDepth < numBombs) { throw new ArgumentException("Number of bombs is larger than the Board"); } var board = new Board((int)boardWidth, (int)boardHeight, (int)boardDepth); (int, int, int)seedCoordTuple; for (uint bombCount = 0; bombCount < numBombs; bombCount++) { if (this.ShouldAbort) { return(ABORTED); } PlaceBombRandomlyOnBoard(board); } seedCoordTuple = SeedFirstNude(board); // return early for tests that are afraid of endless retries (i.e. tests that don't care about the solver) if (disableSolving) { return(board); } if (this.ShouldAbort) { return(ABORTED); } var solver = new Solver.Solver(board); var tries = 0; while (!solver.IsSolvable()) { tries++; if (tries > 20) { throw new EricException(); } if (this.ShouldAbort) { solver.Abort(); return(ABORTED); } /// Commented out because Unity.Engine is not threadsafe ///Debug.Log("Trying again, round " + tries); board.ResetBoard(); for (var i = 0u; i < numBombs; i++) { if (this.ShouldAbort) { solver.Abort(); return(ABORTED); } PlaceBombRandomlyOnBoard(board); } seedCoordTuple = SeedFirstNude(board); } if (this.ShouldAbort) { Debug.Log($"Aborted map generation after {tries} rounds."); solver.Abort(); return(ABORTED); } Debug.Log($"Generated new map in {tries} rounds."); board.ResetCellStates(); // board.Reveal(board[seedCoordTuple.Item1, seedCoordTuple.Item2, seedCoordTuple.Item3]); var(a, b, c) = seedCoordTuple; board[a, b, c].State = CellState.Revealed; return(board); }
public TableauSolutionService(Solver.Solver tableauSolver) { TableauSolver = tableauSolver; }
public EditDetectionPipe(OCAIS2D_InteractiveContext context2d, OCV2d_View view2d, Solver.Solver solver) : base(ActionNames.EditDetectionPipe) { _context2d = context2d; _solver = solver; _view2d = view2d; }
private async void Solve_Clicked(object sender, EventArgs e) { string Text = Number_Of_Move.Text; int Limit; if (int.TryParse(Text, out Limit)) { if (Limit > 0 && Limit <= 10) { if (BoxsToSolve.Count <= 0) { await DisplayAlert("Slover", "No Box in Puzzle", "OK"); return; } bool AllEmpty = true; foreach (var item in BoxsToSolve) { if (item.Value != BoxType.Empty) { AllEmpty = false; break; } } if (AllEmpty) { await DisplayAlert("Slover", "No Box in Puzzle", "OK"); return; } foreach (var item in BoxsToSolve.Where(x => x.Value != BoxType.Empty).GroupBy(x => x.Value)) { if (item.Count() < 3) { await DisplayAlert("Slover", "The number of each type of box must grater than 3", "OK"); return; } } Number_Of_Move.BackgroundColor = Color.Default; PuzzleTable puzzle = new PuzzleTable(7, 9); puzzle.CreatePuzzle(BoxsToSolve); Solver.Solver solver = new Solver.Solver(); if (!IsHasSolution) { try { IsLoading = true; Solution = await solver.SolveAsync(puzzle, Limit); } finally { IsLoading = false; } IsHasSolution = true; } if (Solution == null) { await DisplayAlert("Slover", "No Solution", "OK"); } else { await Navigation.PushModalAsync(new SolutionPage(Solution)); //DisplayAlert("Slover", SolutionText, "OK"); } } else { InvalidMoveText(); } } else { InvalidMoveText(); } }