HW5: Move A Box with the Worker

  1. Extend the previous homework. This time we want to enable the worker to push a box.
  2. Define a function char nextNextToWorker(map, direction), which will return the next next cell of the worker in that direction. For example, in the following figure, nextToWorker(S_RIGHT) == 'B' and nextNextToWorker(S_RIGHT) == ' '.
  3. Define a function moveBox(map, direction).
  4. As we have done in the previous homework, in your main loop, when the user press the UP key ('K'), and nextToWorker(UP) == ' ', call moveWorker(d) to move the worker.
  5. If nextToWorker(UP) == 'B', but nextNextToWorker(UP) == ' ', call moveBox(d) together with moveWorker(d) to move the box and the worker concurrently.
  6. Handle S_DOWN, S_LEFT and S_RIGHT similarly.