Function practice 7 (Village of the Sorcerer 3)


Submit solution

Points: 2
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
C, C++, Python3

New hints:

Here are 2 actual test cases: download Here.

Mr Cleese's other programmer is sick, and now he wants you to implement character movements on the map.

Hint: please make sure you have completed csci125p014 before attempting this task.

Mr Cleese's RPG game has 1 player character, and this player will need to be able to move on the map to explore. Since this chef character designer is still being hired, you can use + sign to denote the character on the map.

In addition to the map description in csci125p014, it now contains the
following elements as well:

~4~ for player, output a single plus sign.

For this task, you can assume that your character can always walk on other objects. The character has 4 movements:

~1~ up, from coordinate    ~(a,b)~ to ~(a-1,b)~
~2~ down, from coordinate  ~(a,b)~ to ~(a+1,b)~
~3~ left, from coordinate  ~(a,b)~ to ~(a,b-1)~
~4~ right, from coordinate ~(a,b)~ to ~(a,b+1)~

Every time the character moves, you will need to print the entire map with the player's new position on it.

There is however, one constraint: the player cannot move outside of the map. If the player tries to do so, you must not change its position.

Input Specification

The first line will contain two integers \(N,M\) (\(1 < N,M < 20\)), indicating the dimension size.

The following \(N\) lines will each contain \(M\) integers, each the item at that coordinate. It is guaranteed that the player (denoted by \(4\)) will appear on the map, and only once.

The next line will contain an integer \(Q\), the number of movements the player is attempting to make.

This is followed by \(Q\) lines of movements, each containing a single integer in the range of \(1\) to \(4\).

Output Specification

The output should contain \(Q+1\) maps, separated by an empty line.

The first map should be the original map: before any movement has taken place.

The next \(Q\) maps are the results of every step of movement.

Each map is represented by a bitmap of \(N\) lines, \(M\) characters.

You are strongly encouraged to design your own test cases as well.

Sample Input

8 12
1 1 1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 3 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 2 0 0 0 0 1
1 0 0 0 4 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1 1 1
6
2
2
1
1
1
1

Sample Output

############
#    _     #
#   /_*    #
#   |***   #
#   *****  #
#     |    #
#   +      #
############

############
#    _     #
#   /_*    #
#   |***   #
#   *****  #
#     |    #
#          #
####+#######

############
#    _     #
#   /_*    #
#   |***   #
#   *****  #
#     |    #
#          #
####+#######

############
#    _     #
#   /_*    #
#   |***   #
#   *****  #
#     |    #
#   +      #
############

############
#    _     #
#   /_*    #
#   |***   #
#   *****  #
#   + |    #
#          #
############

############
#    _     #
#   /_*    #
#   |***   #
#   +****  #
#     |    #
#          #
############

############
#    _     #
#   /_*    #
#   +***   #
#   *****  #
#     |    #
#          #
############

Comments

There are no comments at the moment.