@@ -10,6 +10,8 @@ open Avalonia.FuncUI.DSL
1010open Avalonia.FuncUI .Types
1111open Avalonia.Layout
1212open Avalonia.FuncUI
13+ open Avalonia.Media
14+ open Avalonia.Media .Immutable
1315open Examples.GeneticAlgorithm .Lib
1416
1517type StateStore =
@@ -203,10 +205,12 @@ type Views =
203205
204206 static member selectedGameStateView () =
205207 Component.create ( " selected-game-state" , fun ctx ->
208+ let squirrel = ctx.usePassedStateReadOnly StateStore.shared.SelectedSquirrel
206209 let gameState = ctx.usePassedStateReadOnly StateStore.shared.SelectedGameState
210+ let showHeatMap = ctx.usePassedStateReadOnly StateStore.shared.ShowHeatMap
207211
208- match gameState.Current with
209- | Some gameState ->
212+ match gameState.Current, squirrel.Current with
213+ | Some gameState, Some squirrel ->
210214 let world = gameState.World
211215
212216 UniformGrid.create [
@@ -220,16 +224,25 @@ type Views =
220224 world.Actors
221225 |> Array.tryFind ( fun actor -> actor.Pos.X = x && actor.Pos.Y = y)
222226
227+ let background =
228+ if showHeatMap.Current then
229+ let heat = Genes.evaluateTile squirrel.brain gameState.World ( WorldPos.newPos x y)
230+ ImmutableSolidColorBrush ( Colors.White, 1.0 - float heat)
231+
232+ else
233+ ImmutableSolidColorBrush ( Colors.Green, 1.0 )
234+
223235 match actor with
224236 | Some actor ->
225237 ContentControl.create [
226238 ContentControl.row y
227239 ContentControl.column x
228240 ContentControl.margin ( 2.0 , 2.0 )
229- ContentControl.background " #27ae60 "
241+
230242 ContentControl.fontSize 24.0
231243 ContentControl.verticalContentAlignment VerticalAlignment.Center
232244 ContentControl.horizontalContentAlignment HorizontalAlignment.Center
245+ ContentControl.background background
233246
234247 yield ! [
235248 match actor.ActorKind with
@@ -251,7 +264,7 @@ type Views =
251264 Rectangle.create [
252265 Rectangle.row y
253266 Rectangle.column x
254- Rectangle.fill " #27ae60 "
267+ Rectangle.fill background
255268 Rectangle.margin ( 2.0 , 2.0 )
256269 ]
257270
@@ -261,7 +274,7 @@ type Views =
261274 ]
262275 ]
263276 ] :> _
264- | None ->
277+ | _ ->
265278 TextBlock.create [
266279 TextBlock.text " No Game State Selected"
267280 ] :> _
0 commit comments