Skip to content

Commit 03e417a

Browse files
committed
Introduced SimulationResult, switching to tupled functions.
1 parent 71ba896 commit 03e417a

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

MattEland.FSharpGeneticAlgorithm.Logic/Simulator.fs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,21 @@ let buildStartingState (random: System.Random): GameState =
136136
let world = makeWorld 13 13 random.Next
137137
{ World = world; SimState = SimulationState.Simulating; TurnsLeft = 30}
138138

139-
let simulateGame (initialState: GameState, random: System.Random, brain: ActorChromosome): GameState[] =
139+
type SimulationResult = {
140+
score: float
141+
states: GameState[]
142+
}
143+
144+
let simulateGame random brain initialState =
140145
let states = ResizeArray<GameState>()
141146
states.Add(initialState)
142147
let mutable currentState = initialState
143148
while currentState.SimState = SimulationState.Simulating do
144149
currentState <- handleChromosomeMove(currentState, random, brain)
145150
states.Add(currentState)
146-
states.ToArray()
151+
{
152+
score = 0.0; // TODO: Actually score
153+
states = states.ToArray()
154+
}
147155

148-
let simulate (random: System.Random, brain: ActorChromosome): GameState[] =
149-
let state = buildStartingState random
150-
simulateGame(state, random, brain)
156+
let simulate random brain = buildStartingState random |> simulateGame random brain

MattEland.FSharpGeneticAlgorithm.WindowsClient/ViewModels/SimulationResultViewModel.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,23 @@ namespace MattEland.FSharpGeneticAlgorithm.WindowsClient.ViewModels
66
{
77
public class SimulationResultViewModel : NotifyPropertyChangedBase
88
{
9+
private readonly Simulator.SimulationResult _result;
910
private readonly ObservableCollection<GameStateViewModel> _states;
1011
private int _currentIndex;
1112

12-
public SimulationResultViewModel(IEnumerable<Simulator.GameState> states)
13+
public SimulationResultViewModel(Simulator.SimulationResult result)
1314
{
15+
_result = result;
1416
_states = new ObservableCollection<GameStateViewModel>();
15-
foreach (var state in states)
17+
foreach (var state in _result.states)
1618
{
1719
_states.Add(new GameStateViewModel(state));
1820
}
1921
}
2022

23+
public double Score => _result.score;
24+
public string ScoreText => $"Score: {Score:F1}";
25+
2126
public IEnumerable<GameStateViewModel> States => _states;
2227

2328
public GameStateViewModel SelectedState => _states[CurrentIndex];

0 commit comments

Comments
 (0)