public void Calculate() { try { var gameLogic = tbGameLogic.Text; var transitions = GameLogicParser.ParseMultipleTransitions(gameLogic); var solver = new GenericGrundyGame(transitions); var n = int.Parse(tbInputN.Text); var list = CalculateSpragueGrundyUpTo(n, solver); UpdateGrid(list); lblResult.Text = solver.SGValue(n) > 0 ? "Виграшна ситуація" : "Програшна ситуація"; if (!AvoidRepaintingGraph) { Graph g = solver.GetTransitionsGraph(n); gViewer.Graph = g; } } catch (ArgumentException ex) { MessageBox.Show("Неправильно введені параметри гри. " + ex.Message); } catch (Exception ex) { MessageBox.Show("Сталася невідома помилка: " + ex.Message); } }
private List<uint> CalculateSpragueGrundyUpTo(int key, GenericGrundyGame game) { var list = new List<uint>(); for (int i = 0; i <= key; i++) { var value = game.SGValue(i); list.Add(value); } return list; }