@@ -36,8 +36,22 @@ let moveActor state actor pos =
36
36
if otherActor <> actor && canEnterActorCell actor.ActorKind otherActor.ActorKind then
37
37
38
38
match actor.ActorKind with
39
+ | Doggo ->
40
+ if otherActor.ActorKind = Rabbit then
41
+ { state with World = { world with
42
+ Rabbit = { world.Rabbit with IsActive = false }
43
+ Doggo = { world.Doggo with Pos = pos}
44
+ }}
45
+ else
46
+ { state with SimState = Lost; World = { world with
47
+ Squirrel = { world.Squirrel with IsActive = false }
48
+ Doggo = { world.Doggo with Pos = pos}
49
+ }
50
+ }
51
+
39
52
| Squirrel hasAcorn ->
40
- if not hasAcorn && otherActor.ActorKind = Acorn then
53
+ if not hasAcorn && otherActor.ActorKind = Acorn && not otherActor.IsActive then
54
+ // Moving to the acorn for the first time should give the squirrel the acorn
41
55
{ state with World =
42
56
{
43
57
world with
@@ -46,6 +60,7 @@ let moveActor state actor pos =
46
60
}
47
61
}
48
62
else if hasAcorn && otherActor.ActorKind = Tree then
63
+ // Moving to the tree with the acorn - this should win the game
49
64
{
50
65
state with SimState = Won; World = {
51
66
world with Squirrel = { ActorKind = Squirrel true ; Pos = pos; IsActive = true }
@@ -76,12 +91,22 @@ let moveRandomly state actor getRandomNumber =
76
91
77
92
moveActor state actor movedPos
78
93
79
- let simulateActors ( state : GameState ) getRandomNumber =
80
- let mutable endState = state
94
+ let simulateDoggo ( state : GameState ) =
95
+ let doggo = state.World.Doggo
96
+ let rabbit = state.World.Rabbit
97
+ let squirrel = state.World.Squirrel
81
98
82
- endState <- moveRandomly endState endState.World.Rabbit getRandomNumber
99
+ // Eat any adjacent actor
100
+ if rabbit.IsActive && isAdjacentTo doggo.Pos rabbit.Pos then
101
+ moveActor state doggo rabbit.Pos
102
+ else if squirrel.IsActive && isAdjacentTo doggo.Pos squirrel.Pos then
103
+ moveActor state doggo squirrel.Pos
104
+ else
105
+ state
83
106
84
- endState
107
+ let simulateActors ( state : GameState ) getRandomNumber =
108
+ moveRandomly state state.World.Rabbit getRandomNumber
109
+ |> simulateDoggo
85
110
86
111
let handlePlayerCommand state command =
87
112
let player = state.World.Squirrel
0 commit comments