Function practice 5 (Village of the Sorcerer 1)


Submit solution

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

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

This practice problem will require you to programme basic functions.

Mr Cleese is designing an RPG game, and he needs someone to help him with the interface.

He is going to provide you with a 2 dimensional array describing a map, and your job is to render the map using characters.

Each map is represented as a \(N \times M\) matrix, in which \(N\) is the height and \(M\) is the length. Each element in the matrix represents the items in that position. Here's a list of numerical values and their corresponding meanings

~0~ for nothing, output a single space.
~1~ for fence, output '#'.
~2~ for tree, output from the current coordinate upwards, the following bitmap, say the current coordinate is (a, b), then the '|' character should be at coordinate (a, b).
       *
      ***
     *****
       |

~3~ for house, output from the current coordinate upwards, the following bitmap, say the current coordinate is (a, b), then the bottom '_' character should be at coordinate (a, b).
     _
    /_\
    |_|

Another requirement is that objects do stand in front of each other. Any objects with greater \(x\) coordinate in \((x, y)\) should be in front of those with lesser \(x\). Houses and Trees with the same \(x\) coordinate but greater \(y\) coordinate in \((x, y)\) should be in front of those with lesser \(y\).
Under no circumstances should a fence block portions of a house or tree. Here's an example of a house in front of a tree.

    ############            111111111111
    #    *     #            100000000001
    #   ***    #            100000000001
    #  ***_*   #            100000000001
    #    /_\   #            100002000001
    #    |_|   #            100000300001
    #          #            100000000001
    ############            111111111111

Also, objects should not cover places where they shouldn't. Here's an example of a tree in front of a house.

    ############            111111111111
    #    _     #            100000000001
    #   /_*    #            100000000001
    #   |***   #            100003000001
    #   *****  #            100000000001
    #     |    #            100000200001
    #          #            100000000001
    ############            111111111111

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.

Output Specification

The output should contain \(N\) lines, \(M\) characters, the bitmap.

Sample Input 1

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 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1 1 1

Sample Output 1

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

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 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

Sample Output 2

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

Comments


  • 0
    admin  commented on June 18, 2020, 12:25 p.m.

    Hint2: this is the first 8 lines of the answer code, which includes all of the functions and variables I used (except for i and j in for loops):

    #include <iostream>
    using namespace std;
    int map[100][100];
    char a[100][100];
    int n, m;
    
    void drawTree(char a[][100], int x, int y);
    void drawHouse(char a[][100], int x, int y);

  • 0
    admin  commented on June 18, 2020, 12:02 p.m.

    Hint: to draw character \, you will need to do something like this:

    cout << '\\';

    This is because \ is a special character.