Advertisement
Guest User

Untitled

a guest
May 28th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. private var itemonShelfs: mutable.HashMap[Point, Option[ItemType]] = mutable.HashMap[Point, Option[ItemType]]()
  2. private var consumerTagret: Point = _
  3.  
  4. createFreeMoveStack()
  5.  
  6. /** Robot progresses by moving according to the coordinates inside the movement stack. Movement stack contains
  7. * information about moving from one field to another in order to reach the final destination (eg. Producer, empty
  8. * shelf). If the stack is empty it means the destination is reached. Once this happens, robot performs some actions
  9. * (eg. picks up an item from the Producer), modifies it's state variable and calculates the new movement stack (see
  10. * [[BringerRobot.createNewMoveStack()]]).
  11. *
  12. * From time to time robot updates its level map, see: [[BringerRobot.updateLevelMap()]].
  13. * */
  14. override def progress(dt: Double): Unit = {
  15. timeLived += dt
  16. if (timeLived - lastCommunication > DelivererRobot.CommunicationInterval) {
  17. updateLevelMap()
  18. lastCommunication = timeLived
  19. }
  20.  
  21. if (movementStack.nonEmpty) {
  22. val destination = movementStack.top
  23. val diff = destination - position
  24. val delta = diff / diff.length * dt / 1000.0
  25.  
  26. if (delta.length >= diff.length) {
  27. position = destination
  28. movementStack.pop()
  29. log("is at " + position)
  30. } else {
  31. position += delta
  32. }
  33. } else {
  34. createNewMoveStack()
  35. }
  36. }
  37.  
  38. private def log(s: String): Unit = {
  39. println(name + ": " + s)
  40. }
  41.  
  42. private def updateLevelMap(): Unit = {
  43. val robotsNearby = warehouse.nearbyRobots(position, DelivererRobot.CommunicationRadius)
  44. val levels = robotsNearby map (robot => robot.level)
  45. level = levels.reduce(LevelMap.merge)
  46.  
  47. if (state == BringerState.Bring && level.hasItem(target)) {
  48. log("recreates bringing route!")
  49. //createBringMoveStack()
  50. }
  51. }
  52.  
  53. private def itemsPositions(item: Option[ItemType]): IndexedSeq[Point] = {
  54. var positions = IndexedSeq[Point]()
  55. log("zeskanowane" + itemonShelfs)
  56. itemonShelfs.foreach { case (k, v) => v match {
  57. case item => positions :+= k
  58. case _ =>
  59.  
  60. }}
  61. positions
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement