@@ -22,11 +22,11 @@ let moveActor state actor pos =
22
22
let performMove =
23
23
let actor = { actor with Pos = pos }
24
24
match actor.ActorKind with
25
- | Squirrel _ -> { world with Squirrel = actor }
26
- | Tree -> { world with Tree = actor }
27
- | Acorn -> { world with Acorn = actor }
28
- | Rabbit -> { world with Rabbit = actor }
29
- | Doggo -> { world with Doggo = actor }
25
+ | Squirrel _ -> { state with World ={ world with Squirrel = actor } }
26
+ | Tree -> { state with World ={ world with Tree = actor } }
27
+ | Acorn -> { state with World ={ world with Acorn = actor } }
28
+ | Rabbit -> { state with World ={ world with Rabbit = actor } }
29
+ | Doggo -> { state with World ={ world with Doggo = actor } }
30
30
31
31
let target = tryGetActor( pos.X, pos.Y) world
32
32
@@ -38,16 +38,24 @@ let moveActor state actor pos =
38
38
match actor.ActorKind with
39
39
| Squirrel hasAcorn ->
40
40
if not hasAcorn && otherActor.ActorKind = Acorn then
41
- {
42
- world with
43
- Squirrel = { ActorKind = Squirrel true ; Pos = pos; IsActive = true }
44
- Acorn = { world.Acorn with IsActive = false }
41
+ { state with World =
42
+ {
43
+ world with
44
+ Squirrel = { ActorKind = Squirrel true ; Pos = pos; IsActive = true }
45
+ Acorn = { world.Acorn with IsActive = false }
46
+ }
47
+ }
48
+ else if hasAcorn && otherActor.ActorKind = Tree then
49
+ {
50
+ state with SimState = Won; World = {
51
+ world with Squirrel = { ActorKind = Squirrel true ; Pos = pos; IsActive = true }
52
+ }
45
53
}
46
54
else
47
55
performMove
48
56
| _ -> performMove
49
57
else
50
- world
58
+ state
51
59
52
60
let getCandidates ( current : WorldPos , world : World , includeCenter : bool ): WorldPos seq =
53
61
let mutable candidates : WorldPos seq = Seq.empty
@@ -66,7 +74,7 @@ let moveRandomly state actor getRandomNumber =
66
74
|> Seq.sortBy( fun _ -> getRandomNumber 1000 )
67
75
|> Seq.head
68
76
69
- { state with World = moveActor state actor movedPos }
77
+ moveActor state actor movedPos
70
78
71
79
let simulateActors ( state : GameState ) getRandomNumber =
72
80
let mutable endState = state
@@ -91,7 +99,7 @@ let handlePlayerCommand state command =
91
99
let movedPos = { X= player.Pos.X + xDelta; Y= player.Pos.Y + yDelta}
92
100
93
101
if isValidPos movedPos state.World then
94
- { state with World = moveActor state player movedPos}
102
+ moveActor state player movedPos
95
103
else
96
104
state
97
105
@@ -100,5 +108,8 @@ let playTurn state getRandomNumber command =
100
108
match command with
101
109
| Restart -> { World = makeWorld world.MaxX world.MaxY getRandomNumber; SimState = Simulating }
102
110
| _ ->
103
- let newState = handlePlayerCommand state command
104
- simulateActors newState getRandomNumber
111
+ match state.SimState with
112
+ | Simulating ->
113
+ let newState = handlePlayerCommand state command
114
+ simulateActors newState getRandomNumber
115
+ | _ -> state
0 commit comments