Function practice 9 (Village of the Sorcerer 5)


Submit solution

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

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

Finally, you are assembling the bits you've put together so that the player may move to different areas on the map, but also other maps all together!

Hint: please make sure you have completed csci125p014, csci125p015, csci125p016, csci125p017 before attempting this task.

Remember those houses on the map? Well they aren't just any houses, Mr Cleese wants them to be magical houses: upon entering, the player is transported to another map/level! And guess who is implementing it? You wouldn't believe it, it is you!

Input Specification

The first line will contain 3 integers \(K,N,M\) (\(3 < N,M < 30\), \(2 < K \ge 50\)), where \(N,M\) indicate the dimension size, and \(K\) indicates the number of levels/maps you will need to store.

For the next \(K \times (N + 1)\) lines, with the first \(N\) lines each containing \(M\) integers, each the item at that coordinate. And a single line containing integers, the same amount as the houses on that map, indicating the level/map each house leads to. The order matches the order you read in the houses.

It is guaranteed that the player (denoted by \(4\)) will appear on the every map, and only once on every map, indicating the entry point to that map.

The game starts at the first level/map.

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\). When the player moves to the original coordinate of the house, marked with the plus sign below:

 _
/_\
|+|

You immediately transport the player to the entry point of the corresponding map.

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

2 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
1
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 4 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 2 0 0 0 0 0 1
1 0 0 0 0 0 3 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1 1 1
0

12
1
1
4
1
2
2
2
2
4
4
4
1

Explanation of sample input

The two maps here, level/map 0:

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

Level/map 1:

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

The house in level 0 leads to level/map 1.

The house in level 1 leads to level/map 0.

Note, a house can lead to the same level, and upon moving the player there you should transport the player to the entry point on that map.

The first 4 movements moves the player to the house on level 0, which then transports the player to level 1.

1   // up
1   // up
4   // right
1   // up (arrives at the house, transports to level 1)

The next 8 movements moves the player to the house on level 1, which then transports the player back to level 0.

2
2
2
2
4
4
4
1

Sample Output

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

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

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

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

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

############
#    *     #
#   ***    #
#  ***_*   #
#    /_\   #
#    |_|   #
#          #
############

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

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

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

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

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

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

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

Comments


  • 0
    jetic  commented on June 24, 2020, 5:17 a.m.

    All in all, P018 is a lot more difficult for me since the test case designs are much more complicated. The actual solution is not that hard, and if you are me you are looking at around 30 more lines of code.


  • 0
    jetic  commented on June 24, 2020, 5:12 a.m.

    As the promised hint, this is what I used for the reference programme.

    #include <iostream>
    using namespace std;
    int maps[100][100][100];
    // maps[level][x_coordinate][y_coordinate]
    int start[100][2];
    // the starting position on every map
    int houses[100][100];
    // the level each house on every map points to.
    // houses[level][houseNumber]
    // alternatively, use houses[100][100][100] if it makes your life easier
    int k, n, m;
    int currentMap;
    // it is important to know which level/map you are currently on
    
    void drawTree(char a[][100], int x, int y);
    void drawHouse(char a[][100], int x, int y);
    void printMap(int map[][100], int x, int y);
    int checkMove(int map[][100], int x, int y);
    void movePlayer(int map[][100], int& x, int& y, int dir);