diff --git a/Life/App.xaml b/Life/App.xaml index 0dc76a5..7acb8d2 100644 --- a/Life/App.xaml +++ b/Life/App.xaml @@ -13,5 +13,8 @@ + diff --git a/Life/Automaton/GameOfLife.cs b/Life/Automaton/GameOfLife.cs index ac5e891..57beb4b 100644 --- a/Life/Automaton/GameOfLife.cs +++ b/Life/Automaton/GameOfLife.cs @@ -40,6 +40,11 @@ namespace Life.Automaton return @new; } + + public override string ToString() + { + return $"{born}/{survive}"; + } } public GameOfLife(int width, int height) diff --git a/Life/Automaton/IAutomaton.cs b/Life/Automaton/IAutomaton.cs index 61790df..df23428 100644 --- a/Life/Automaton/IAutomaton.cs +++ b/Life/Automaton/IAutomaton.cs @@ -6,6 +6,7 @@ namespace Life.Automaton { int Iteration { get; } IField Field { get; } + IRule Rule { get; set; } void Advance(); diff --git a/Life/MainWindow.xaml b/Life/MainWindow.xaml index c306aba..0fd2741 100644 --- a/Life/MainWindow.xaml +++ b/Life/MainWindow.xaml @@ -30,13 +30,13 @@ - + Iteration - + Size @@ -47,10 +47,14 @@ change - + Cell Size + + Rule (born/survive) + + diff --git a/Life/ViewModel/AutomatonViewModel.cs b/Life/ViewModel/AutomatonViewModel.cs index 5e68e3e..26ea3e4 100644 --- a/Life/ViewModel/AutomatonViewModel.cs +++ b/Life/ViewModel/AutomatonViewModel.cs @@ -16,6 +16,8 @@ namespace Life.ViewModel private int _width; private int _height; private int _steps; + private string _rule = "3/23"; + private IAutomaton _automaton; private IFormatter _formatter = new BinaryFormatter(); @@ -31,6 +33,20 @@ namespace Life.ViewModel }; } + public string Rule + { + get => _rule; + set + { + _rule = value; + + var split = value.Split("/"); + + Automaton.Rule = new GameOfLife.StandardRule(split[0], split[1] ?? "23"); + OnPropertyChanged(nameof(Rule)); + } + } + public int Size { get => _size; @@ -79,6 +95,7 @@ namespace Life.ViewModel _automaton = value; OnPropertyChanged(nameof(Field)); OnPropertyChanged(nameof(Iteration)); + Rule = Automaton.Rule.ToString(); } }