-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil_functions.py
78 lines (68 loc) · 2.57 KB
/
util_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from utils import MapTiles
from utils import Directions
import emoji as em
import numpy as np
MAP_TYPES = ['ascii', 'emoji']
def map_to_text(game_map, type='a'):
"""
Convert a map in the game format to something human-readable.
By default, prints an ASCII map, 'a' for ASCII, 'u' for Unicode,
'e' for emoji, 'c' for color-coded ASCII. ASCII should work for anything.
"""
ascii_dict = {MapTiles.PATH: 'P', MapTiles.SAND: 'S',
MapTiles.MOUNTAIN: 'M', MapTiles.WALL: 'W',
MapTiles.UNKNOWN: 'U'}
emoji_dict = {
MapTiles.UNKNOWN: em.emojize(':white_large_square:'),
MapTiles.MOUNTAIN: em.emojize(':mountain:'),
MapTiles.SAND: em.emojize(':palm_tree:'),
MapTiles.PATH: em.emojize(':motorway:'),
MapTiles.WALL: em.emojize(':construction:', use_aliases=True)}
printable_map = np.full((len(game_map), len(game_map[0])), "x")
assert type in MAP_TYPES
if type == 'ascii':
chosen_dict = ascii_dict
elif type == 'colorascii':
raise NotImplementedError(
'Color ASCII map display not yet implemented')
# chosen_dict = color_ascii_dict
elif type == 'unicode':
raise NotImplementedError('Unicode map display not yet implemented')
# chosen_dict = unicode_dict
elif type == 'emoji':
chosen_dict = emoji_dict
for i in range(len(game_map)):
for j in range(len(game_map[i])):
printable_map[i][j] = chosen_dict[game_map[i][j]]
return printable_map
#
# def print_map(game_map, type='ascii'):
# """
# Takes a game map populated with map values, prints that map to terminal.
# Can optionally take an argument specifying the type of character printed
# (ascii, emoji, colorascii, or unicode).
# """
# printable_map = map_to_text(game_map, type)
# for i in range(len(game_map)):
# row = ""
# for j in range(len(game_map[i])):
# row += printable_map[i][j]
# row += ' '
# print(row)
def print_map(game_map, type='ascii'):
"""
Takes a game map populated with map values, prints that map to terminal.
Can optionally take an argument specifying the type of character printed
(ascii, emoji, colorascii, or unicode).
"""
printable_map = map_to_text(game_map, type)
row =" "
for i in range(len(game_map)):
row+=str(i)+' '
print(row)
for i in range(len(game_map)):
row = str(i)+" "
for j in range(len(game_map[i])):
row += printable_map[i][j]
row += ' '
print(row)