HW5: Move A Box with the Worker
- Extend the previous homework. This time we want to enable the
worker to
push a box.
- 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) == ' '.
- Define a function moveBox(map, direction).
- 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.
- If nextToWorker(UP) == 'B', but nextNextToWorker(UP) == ' ',
call moveBox(d) together with moveWorker(d) to move the box and the worker
concurrently.
- Handle S_DOWN, S_LEFT and S_RIGHT similarly.