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

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

Sample Input 3

16 16
0 0 0 3 0 0 0 0 0 1 0 0 0 3 0 0 
0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 1 2 0 3 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 1 0 0 0 0 3 0 0 0 0 0 
0 0 0 2 0 0 1 0 0 0 0 0 1 0 0 0 
0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 
0 0 0 2 0 3 0 0 0 0 0 0 0 0 0 3 
0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 
1 0 0 0 0 2 0 0 0 0 0 0 1 0 0 0 
2 0 0 0 3 0 0 1 0 0 3 0 0 1 0 0 
0 0 0 0 1 0 0 0 0 0 0 0 0 3 0 0

Sample Output 3

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

Sample Input 4

15 12
0 0 0 0 0 3 1 2 0 0 3 0 
0 0 0 0 0 0 0 0 0 0 0 0 
3 1 0 0 0 0 0 0 0 0 0 1 
0 0 0 0 1 0 0 0 0 0 1 0 
2 0 0 0 0 0 0 3 0 0 0 2 
0 0 0 2 0 0 0 0 0 0 0 0 
0 0 0 0 2 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 1 0 1 0 
0 0 3 0 0 0 0 0 3 0 0 0 
0 0 0 1 0 0 0 0 2 0 0 1 
0 0 0 0 0 0 0 0 3 0 0 0 
1 0 0 0 3 0 1 0 0 0 0 2 
1 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 3 0 0 0 3 0 0 0 0 
0 0 0 0 0 0 0 0 3 0 1 1

Sample Output 4

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

Sample Input 5

12 11
2 0 2 0 0 0 0 0 0 2 1 
0 0 3 0 0 0 0 0 0 0 0 
0 0 3 0 0 0 3 0 0 0 0 
0 0 0 0 1 0 0 3 3 3 0 
0 0 0 0 0 0 3 0 0 0 0 
0 3 0 0 0 0 0 0 0 2 3 
0 0 0 2 0 0 0 0 0 0 0 
0 0 0 3 1 0 0 1 0 3 0 
0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 
0 1 0 0 0 0 0 0 2 0 0 
0 0 0 0 0 0 0 0 0 0 0

Sample Output 5

|/_\  _  |#
 /_\ /____ 
 |_| |_//*\
 _ *#/_\**_
/_***|_**/_
|**_**   __
  /_\   /_\
  |_|  #*_|
       *** 
      *****
 #      |

Comments

There are no comments at the moment.