Browse Source

AUTHORS; perf sensor; ui improvement

master
Robin Thoni 7 years ago
parent
commit
56592f7f5e

+ 3
- 0
AUTHORS View File

1
+8inf846
2
+THOR16119403 Robin Thoni <robin@rthoni.com>
3
+TIBP18039507 Pierre-Antoine Tible <zhajor@zhajor.com>

+ 1
- 0
README.md View File

71
 
71
 
72
 Agent logic is in `Agent/*.cs`  
72
 Agent logic is in `Agent/*.cs`  
73
 Agent sensors and effectors interfaces are in `Agent/Interfaces/*`  
73
 Agent sensors and effectors interfaces are in `Agent/Interfaces/*`  
74
+Agent sensors that do not directly rely on physical sensors are in `Agent/Sensors/*.cs`  
74
 Agent FakeEnv client implementation is in `Agent/FakeEnv/*`  
75
 Agent FakeEnv client implementation is in `Agent/FakeEnv/*`  
75
 FakeEnv client, server, protocol and configuration are defined in `Common/*.cs`  
76
 FakeEnv client, server, protocol and configuration are defined in `Common/*.cs`  
76
 FakeEnv server implementation is in `Environment/*.cs`  
77
 FakeEnv server implementation is in `Environment/*.cs`  

+ 5
- 2
uqac-ia-aspirobot/Agent/AgAgent.cs View File

9
 using uqac_ia_aspirobot.Agent.FakeEnv.Sensors;
9
 using uqac_ia_aspirobot.Agent.FakeEnv.Sensors;
10
 using uqac_ia_aspirobot.Agent.Interfaces.Effectors;
10
 using uqac_ia_aspirobot.Agent.Interfaces.Effectors;
11
 using uqac_ia_aspirobot.Agent.Interfaces.Sensors;
11
 using uqac_ia_aspirobot.Agent.Interfaces.Sensors;
12
+using uqac_ia_aspirobot.Agent.Sensors;
12
 using uqac_ia_aspirobot.Common;
13
 using uqac_ia_aspirobot.Common;
13
 using uqac_ia_aspirobot.Extensions;
14
 using uqac_ia_aspirobot.Extensions;
14
 using uqac_ia_aspirobot.Interfaces;
15
 using uqac_ia_aspirobot.Interfaces;
44
             agServices.AddSingleton<IAgBatterySensor, AgBatterySensor>();
45
             agServices.AddSingleton<IAgBatterySensor, AgBatterySensor>();
45
             agServices.AddSingleton<IAgVaccumSensor, AgVaccumSensor>();
46
             agServices.AddSingleton<IAgVaccumSensor, AgVaccumSensor>();
46
             agServices.AddSingleton<IAgPickedSensor, AgPickedSensor>();
47
             agServices.AddSingleton<IAgPickedSensor, AgPickedSensor>();
48
+            agServices.AddSingleton<IAgPerformanceSensor, AgPerformanceSensor>();
47
 
49
 
48
             agServices.AddSingleton<IAgVaccumEffector, AgVaccumEffector>();
50
             agServices.AddSingleton<IAgVaccumEffector, AgVaccumEffector>();
49
             agServices.AddSingleton<IAgEngineEffector, AgEngineEffector>();
51
             agServices.AddSingleton<IAgEngineEffector, AgEngineEffector>();
127
 
129
 
128
         public void Think()
130
         public void Think()
129
         {
131
         {
130
-            if (_state.LastThinkTime.AddMilliseconds(_state.ThinkTimeInterval) <= DateTime.Now)
132
+            var now = DateTime.Now;
133
+            if (_state.LastThinkTime.AddMilliseconds(_state.ThinkTimeInterval) <= now)
131
             {
134
             {
132
                 if (_state.Destination == null && _state.DustyRooms.Any())
135
                 if (_state.Destination == null && _state.DustyRooms.Any())
133
                 {
136
                 {
134
                     _state.Destination = _state.DustyRooms.OrderBy(room => room.Distance(_engineEffector)).First();
137
                     _state.Destination = _state.DustyRooms.OrderBy(room => room.Distance(_engineEffector)).First();
135
                 }
138
                 }
136
-                _state.LastThinkTime = DateTime.Now;
139
+                _state.LastThinkTime = now;
137
             }
140
             }
138
         }
141
         }
139
 
142
 

+ 13
- 10
uqac-ia-aspirobot/Agent/FakeEnv/AgEnvironment.cs View File

10
 {
10
 {
11
     public class AgEnvironment : IEnvironment
11
     public class AgEnvironment : IEnvironment
12
     {
12
     {
13
-        private readonly IAgDustSensor _agDustSensor;
14
-        private readonly IAgBatterySensor _agBatterySensor;
15
-        private readonly IAgPickedSensor _agPickedSensor;
16
-        private readonly IAgVaccumSensor _agVaccumSensor;
13
+        private IAgDustSensor _agDustSensor;
14
+        private IAgBatterySensor _agBatterySensor;
15
+        private IAgPickedSensor _agPickedSensor;
16
+        private IAgVaccumSensor _agVaccumSensor;
17
+        private IAgPerformanceSensor _agPerformanceSensor;
17
 
18
 
18
         private readonly IServiceProvider _serviceProvider;
19
         private readonly IServiceProvider _serviceProvider;
19
 
20
 
25
 
26
 
26
         private readonly IDictionary<string, IRoom> _rooms = new Dictionary<string, IRoom>();
27
         private readonly IDictionary<string, IRoom> _rooms = new Dictionary<string, IRoom>();
27
 
28
 
28
-        public AgEnvironment(IServiceProvider serviceProvider, ArClient arClient,
29
-            IAgDustSensor agDustSensor, IAgBatterySensor agBatterySensor, IAgPickedSensor agPickedSensor, IAgVaccumSensor agVaccumSensor)
29
+        public AgEnvironment(IServiceProvider serviceProvider, ArClient arClient)
30
         {
30
         {
31
             _serviceProvider = serviceProvider;
31
             _serviceProvider = serviceProvider;
32
             _arClient = arClient;
32
             _arClient = arClient;
33
-            _agDustSensor = agDustSensor;
34
-            _agBatterySensor = agBatterySensor;
35
-            _agPickedSensor = agPickedSensor;
36
-            _agVaccumSensor = agVaccumSensor;
37
         }
33
         }
38
 
34
 
39
         public void Setup()
35
         public void Setup()
40
         {
36
         {
37
+            _agDustSensor = _serviceProvider.GetService<IAgDustSensor>();
38
+            _agBatterySensor = _serviceProvider.GetService<IAgBatterySensor>();
39
+            _agPickedSensor = _serviceProvider.GetService<IAgPickedSensor>();
40
+            _agVaccumSensor = _serviceProvider.GetService<IAgVaccumSensor>();
41
+            _agPerformanceSensor = _serviceProvider.GetService<IAgPerformanceSensor>();
42
+
41
             _arClient.Setup();
43
             _arClient.Setup();
42
             _width = _arClient.GetEnvWidth();
44
             _width = _arClient.GetEnvWidth();
43
             _height = _arClient.GetEnvWidth();
45
             _height = _arClient.GetEnvWidth();
65
             _agBatterySensor.Update();
67
             _agBatterySensor.Update();
66
             _agPickedSensor.Update();
68
             _agPickedSensor.Update();
67
             _agVaccumSensor.Update();
69
             _agVaccumSensor.Update();
70
+            _agPerformanceSensor.Update();
68
         }
71
         }
69
 
72
 
70
         protected string GetKey(int x, int y)
73
         protected string GetKey(int x, int y)

+ 0
- 8
uqac-ia-aspirobot/Agent/FakeEnv/Sensors/AgDustSensor.cs View File

1
 using uqac_ia_aspirobot.Agent.Interfaces.Sensors;
1
 using uqac_ia_aspirobot.Agent.Interfaces.Sensors;
2
-using uqac_ia_aspirobot.Interfaces;
3
 
2
 
4
 namespace uqac_ia_aspirobot.Agent.FakeEnv.Sensors
3
 namespace uqac_ia_aspirobot.Agent.FakeEnv.Sensors
5
 {
4
 {
6
     public class AgDustSensor : IAgDustSensor
5
     public class AgDustSensor : IAgDustSensor
7
     {
6
     {
8
-        private readonly AgEnvironment _environment;
9
-
10
-        public AgDustSensor(IEnvironment environment)
11
-        {
12
-            _environment = environment as AgEnvironment;
13
-        }
14
-
15
         public void Update()
7
         public void Update()
16
         {
8
         {
17
         }
9
         }

+ 7
- 0
uqac-ia-aspirobot/Agent/Interfaces/Sensors/IAgPerformanceSensor.cs View File

1
+namespace uqac_ia_aspirobot.Agent.Interfaces.Sensors
2
+{
3
+    public interface IAgPerformanceSensor : ISensor
4
+    {
5
+        float Performance { get; }
6
+    }
7
+}

+ 34
- 0
uqac-ia-aspirobot/Agent/Sensors/AgPerformanceSensor.cs View File

1
+using uqac_ia_aspirobot.Agent.Interfaces.Sensors;
2
+using uqac_ia_aspirobot.Extensions;
3
+using uqac_ia_aspirobot.Interfaces;
4
+
5
+namespace uqac_ia_aspirobot.Agent.Sensors
6
+{
7
+    public class AgPerformanceSensor : IAgPerformanceSensor
8
+    {
9
+        private readonly IAgBatterySensor _agBatterySensor;
10
+
11
+        private readonly IAgPickedSensor _agPickedSensor;
12
+
13
+        private readonly IAgVaccumSensor _agVaccumSensor;
14
+        private readonly IEnvironment _environment;
15
+
16
+        public float Performance { get; protected set; }
17
+
18
+        public AgPerformanceSensor(IAgBatterySensor agBatterySensor, IAgPickedSensor agPickedSensor,
19
+            IAgVaccumSensor agVaccumSensor, IEnvironment environment)
20
+        {
21
+            _agBatterySensor = agBatterySensor;
22
+            _agPickedSensor = agPickedSensor;
23
+            _agVaccumSensor = agVaccumSensor;
24
+            _environment = environment;
25
+        }
26
+
27
+        public void Update()
28
+        {
29
+            var dustyCount = _environment.FindDustyRooms().Count;
30
+            var sum = _agPickedSensor.Picked + _agVaccumSensor.Vaccumed;
31
+            Performance = (_agBatterySensor.Spent == 0 ? 0 : (float)sum / _agBatterySensor.Spent) - dustyCount;
32
+        }
33
+    }
34
+}

+ 7
- 2
uqac-ia-aspirobot/UI/UiConsole.cs View File

16
         private readonly IAgBatterySensor _agBatterySensor;
16
         private readonly IAgBatterySensor _agBatterySensor;
17
         private readonly IAgVaccumSensor _agVaccumSensor;
17
         private readonly IAgVaccumSensor _agVaccumSensor;
18
         private readonly AgState _agState;
18
         private readonly AgState _agState;
19
+        private readonly IAgPerformanceSensor _agPerformanceSensor;
19
 
20
 
20
         public UiConsole(IEnvironment environment, IAgEngineEffector agEngineEffector, IAgPickedSensor agPickedSensor,
21
         public UiConsole(IEnvironment environment, IAgEngineEffector agEngineEffector, IAgPickedSensor agPickedSensor,
21
-            IAgBatterySensor agBatterySensor, IAgVaccumSensor agVaccumSensor, AgState agState)
22
+            IAgBatterySensor agBatterySensor, IAgVaccumSensor agVaccumSensor, AgState agState, IAgPerformanceSensor agPerformanceSensor)
22
         {
23
         {
23
             _environment = environment;
24
             _environment = environment;
24
             _agEngineEffector = agEngineEffector;
25
             _agEngineEffector = agEngineEffector;
26
             _agBatterySensor = agBatterySensor;
27
             _agBatterySensor = agBatterySensor;
27
             _agVaccumSensor = agVaccumSensor;
28
             _agVaccumSensor = agVaccumSensor;
28
             _agState = agState;
29
             _agState = agState;
30
+            _agPerformanceSensor = agPerformanceSensor;
29
         }
31
         }
30
 
32
 
31
         public void SetBackgroundColor(ConsoleColor? color)
33
         public void SetBackgroundColor(ConsoleColor? color)
186
                 Console.WriteLine("|");
188
                 Console.WriteLine("|");
187
             }
189
             }
188
             SetBackgroundColor(bgColor);
190
             SetBackgroundColor(bgColor);
191
+            var nextThink = Math.Max(0, (_agState.LastThinkTime.AddMilliseconds(_agState.ThinkTimeInterval) - DateTime.Now).TotalMilliseconds);
189
             Console.WriteLine($"Battery: {_agBatterySensor.Spent}");
192
             Console.WriteLine($"Battery: {_agBatterySensor.Spent}");
190
             Console.WriteLine($"Vaccumed: {_agVaccumSensor.Vaccumed}");
193
             Console.WriteLine($"Vaccumed: {_agVaccumSensor.Vaccumed}");
191
             Console.WriteLine($"Picked: {_agPickedSensor.Picked}");
194
             Console.WriteLine($"Picked: {_agPickedSensor.Picked}");
192
-            Console.WriteLine($"Think: {_agState.ThinkTimeInterval}ms");
195
+            Console.WriteLine($"Think Interval: {_agState.ThinkTimeInterval}ms");
196
+            Console.WriteLine($"Next Think: {nextThink}ms");
197
+            Console.WriteLine($"Performance: {_agPerformanceSensor.Performance}");
193
         }
198
         }
194
     }
199
     }
195
 }
200
 }

Loading…
Cancel
Save