Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private var itemonShelfs: mutable.HashMap[Point, Option[ItemType]] = mutable.HashMap[Point, Option[ItemType]]()
- private var consumerTagret: Point = _
- createFreeMoveStack()
- /** Robot progresses by moving according to the coordinates inside the movement stack. Movement stack contains
- * information about moving from one field to another in order to reach the final destination (eg. Producer, empty
- * shelf). If the stack is empty it means the destination is reached. Once this happens, robot performs some actions
- * (eg. picks up an item from the Producer), modifies it's state variable and calculates the new movement stack (see
- * [[BringerRobot.createNewMoveStack()]]).
- *
- * From time to time robot updates its level map, see: [[BringerRobot.updateLevelMap()]].
- * */
- override def progress(dt: Double): Unit = {
- timeLived += dt
- if (timeLived - lastCommunication > DelivererRobot.CommunicationInterval) {
- updateLevelMap()
- lastCommunication = timeLived
- }
- if (movementStack.nonEmpty) {
- val destination = movementStack.top
- val diff = destination - position
- val delta = diff / diff.length * dt / 1000.0
- if (delta.length >= diff.length) {
- position = destination
- movementStack.pop()
- log("is at " + position)
- } else {
- position += delta
- }
- } else {
- createNewMoveStack()
- }
- }
- private def log(s: String): Unit = {
- println(name + ": " + s)
- }
- private def updateLevelMap(): Unit = {
- val robotsNearby = warehouse.nearbyRobots(position, DelivererRobot.CommunicationRadius)
- val levels = robotsNearby map (robot => robot.level)
- level = levels.reduce(LevelMap.merge)
- if (state == BringerState.Bring && level.hasItem(target)) {
- log("recreates bringing route!")
- //createBringMoveStack()
- }
- }
- private def itemsPositions(item: Option[ItemType]): IndexedSeq[Point] = {
- var positions = IndexedSeq[Point]()
- log("zeskanowane" + itemonShelfs)
- itemonShelfs.foreach { case (k, v) => v match {
- case item => positions :+= k
- case _ =>
- }}
- positions
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement