Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using uqac_ia_aspirobot.Agent.Interfaces.Sensors;
  5. using uqac_ia_aspirobot.Common;
  6. using uqac_ia_aspirobot.Extensions;
  7. using uqac_ia_aspirobot.Interfaces;
  8. namespace uqac_ia_aspirobot.Agent.FakeEnv
  9. {
  10. public class AgEnvironment : IEnvironment
  11. {
  12. private IAgDustSensor _agDustSensor;
  13. private IAgBatterySensor _agBatterySensor;
  14. private IAgPickedSensor _agPickedSensor;
  15. private IAgVaccumSensor _agVaccumSensor;
  16. private IAgPerformanceSensor _agPerformanceSensor;
  17. private readonly IServiceProvider _serviceProvider;
  18. private readonly ArClient _arClient;
  19. private int _width;
  20. private int _height;
  21. private readonly IDictionary<string, IRoom> _rooms = new Dictionary<string, IRoom>();
  22. public AgEnvironment(IServiceProvider serviceProvider, ArClient arClient)
  23. {
  24. _serviceProvider = serviceProvider;
  25. _arClient = arClient;
  26. }
  27. public void Setup()
  28. {
  29. _agDustSensor = _serviceProvider.GetService<IAgDustSensor>();
  30. _agBatterySensor = _serviceProvider.GetService<IAgBatterySensor>();
  31. _agPickedSensor = _serviceProvider.GetService<IAgPickedSensor>();
  32. _agVaccumSensor = _serviceProvider.GetService<IAgVaccumSensor>();
  33. _agPerformanceSensor = _serviceProvider.GetService<IAgPerformanceSensor>();
  34. _arClient.Setup();
  35. _width = _arClient.GetEnvWidth();
  36. _height = _arClient.GetEnvWidth();
  37. for (var x = 0; x < _width; ++x)
  38. {
  39. for (var y = 0; y < _height; ++y)
  40. {
  41. var room = _serviceProvider.GetService<IRoom>();
  42. room.X = x;
  43. room.Y = y;
  44. _rooms.Add(GetKey(x, y), room);
  45. }
  46. }
  47. }
  48. public void Update()
  49. {
  50. this.ForeachRoom<AgRoom>(room =>
  51. {
  52. room.Update();
  53. return true;
  54. });
  55. _agDustSensor.Update();
  56. _agBatterySensor.Update();
  57. _agPickedSensor.Update();
  58. _agVaccumSensor.Update();
  59. _agPerformanceSensor.Update();
  60. }
  61. protected string GetKey(int x, int y)
  62. {
  63. return $"{x},{y}";
  64. }
  65. public int GetWidth()
  66. {
  67. return _width;
  68. }
  69. public int GetHeight()
  70. {
  71. return _height;
  72. }
  73. public IRoom GetRoom(int x, int y)
  74. {
  75. return _rooms[GetKey(x, y)];
  76. }
  77. }
  78. }