File tree Expand file tree Collapse file tree 2 files changed +18
-7
lines changed
MattEland.FSharpGeneticAlgorithm.Logic
MattEland.FSharpGeneticAlgorithm.WindowsClient/ViewModels Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -136,15 +136,21 @@ let buildStartingState (random: System.Random): GameState =
136
136
let world = makeWorld 13 13 random.Next
137
137
{ World = world; SimState = SimulationState.Simulating; TurnsLeft = 30 }
138
138
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 =
140
145
let states = ResizeArray< GameState>()
141
146
states.Add( initialState)
142
147
let mutable currentState = initialState
143
148
while currentState.SimState = SimulationState.Simulating do
144
149
currentState <- handleChromosomeMove( currentState, random, brain)
145
150
states.Add( currentState)
146
- states.ToArray()
151
+ {
152
+ score = 0.0 ; // TODO: Actually score
153
+ states = states.ToArray()
154
+ }
147
155
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
Original file line number Diff line number Diff line change @@ -6,18 +6,23 @@ namespace MattEland.FSharpGeneticAlgorithm.WindowsClient.ViewModels
6
6
{
7
7
public class SimulationResultViewModel : NotifyPropertyChangedBase
8
8
{
9
+ private readonly Simulator . SimulationResult _result ;
9
10
private readonly ObservableCollection < GameStateViewModel > _states ;
10
11
private int _currentIndex ;
11
12
12
- public SimulationResultViewModel ( IEnumerable < Simulator . GameState > states )
13
+ public SimulationResultViewModel ( Simulator . SimulationResult result )
13
14
{
15
+ _result = result ;
14
16
_states = new ObservableCollection < GameStateViewModel > ( ) ;
15
- foreach ( var state in states )
17
+ foreach ( var state in _result . states )
16
18
{
17
19
_states . Add ( new GameStateViewModel ( state ) ) ;
18
20
}
19
21
}
20
22
23
+ public double Score => _result . score ;
24
+ public string ScoreText => $ "Score: { Score : F1} ";
25
+
21
26
public IEnumerable < GameStateViewModel > States => _states ;
22
27
23
28
public GameStateViewModel SelectedState => _states [ CurrentIndex ] ;
You can’t perform that action at this time.
0 commit comments