/// <summary> /// Method does one step of the simulation. /// </summary> private void SimulationStep() { var solver = AppState.Instance.Solver; var ret = solver.GetNextMoves(); if (ret.Count == 0) { if (_computing) { MessageBoxService.ShowInfo("Computation ended!"); _computing = false; } return; } for (int i = 0; i < ret.Count; i++) { var move = ret[i]; if (move.Board == i) { AppState.Instance.BoardBlocks[i].Add(move.Block); } else //draw using other board { AppState.Instance.BoardBlocks[i] = new List <IBoardBlock>(AppState.Instance.BoardBlocks[move.Board]); if (move.Board < i) //it means that the move on that board was already done, so remove it and redo with new move { AppState.Instance.BoardBlocks[i].RemoveAt(AppState.Instance.BoardBlocks[i].Count - 1); } AppState.Instance.BoardBlocks[i].Add(move.Block); } } _bestDensity = ret.Max(r => r.Density); this.InvokeEx(f => f.UpdateForm()); }
private void JumpSimulation(object sender, EventArgs e) { try { var steps = uint.Parse(tbJump.Text); this.UseWaitCursor = true; _computing = true; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < steps; i++) { SimulationStep(); } stopwatch.Stop(); MessageBoxService.ShowInfo("Elapsed: " + stopwatch.Elapsed); this.UseWaitCursor = false; _simulationState = SimulationState.Paused; _computing = false; EnableButtons(); } catch (Exception) { MessageBoxService.ShowError("Provide positive number!"); } }