forked from microsoft/coyote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMockRoutePlanner.cs
59 lines (50 loc) · 1.67 KB
/
MockRoutePlanner.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Collections.Generic;
using Microsoft.Coyote.Actors;
namespace Microsoft.Coyote.Samples.DrinksServingRobot
{
internal class GetRouteEvent : Event
{
public readonly ActorId ClientId;
public readonly Location Start;
public readonly Location End;
public GetRouteEvent(ActorId clientId, Location start, Location end)
{
this.ClientId = clientId;
this.Start = start;
this.End = end;
}
}
internal class DrivingInstructionsEvent : Event
{
public readonly List<Location> Route;
public DrivingInstructionsEvent(List<Location> route)
{
this.Route = route;
}
}
internal class MockRoutePlanner : StateMachine
{
[Start]
[OnEventDoAction(typeof(GetRouteEvent), nameof(GenerateRoute))]
internal class Active : State { }
private void GenerateRoute(Event e)
{
if (e is GetRouteEvent getRouteEvent)
{
var clientId = getRouteEvent.ClientId;
var start = getRouteEvent.Start;
var destination = getRouteEvent.End;
var hopsCount = this.RandomInteger(3) + 1;
var route = new List<Location> { };
for (var i = 1; i < hopsCount; i++)
{
route.Add(Utilities.GetRandomLocation(this.RandomInteger, 2, 2, 30, 30));
}
route.Add(destination);
this.SendEvent(clientId, new DrivingInstructionsEvent(route));
}
}
}
}