import curses as c
from itertools import product
world_map = [
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000011111111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000011111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000011111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000111111111111111111110000000000000000000000000000000001111111111111111111111111000000000000000000000000000',
'00000000000000000111111111111111111111000000000000000000000000000001111111111111111111111111000000000000000000000000000',
'00000000000000000011111111111111111000000000000000000000000000000001111133333111111111111111000000000000000000000000000',
'00000000000000000000011111111111100000000000000000000000000000000001111133333111111111111111000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000001111133333111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000001111133333111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000001111133333111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000011111111111111111133333111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000011111111111111111133333111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000011111111111111111111111111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111000000000000000000000000000',
'00000000000000001111111111111111111111111000000000000011111111111110000000000000000000000000000000000000000000000000000',
'00000000000000001111111111111111111111111000000000000011111111111110000000000000000000000000000000000000000000000000000',
'00000000000000001114444411111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000001114444411111115555555111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000001114444411111115555555111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000001114444411111115555555111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000001111111111111115555555111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000001111111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
]
colors_for_initialising = ([
(255, 0n, 0x64*((i * 1000 // 0xff,) 0for i in rgb),)
(254for n, 0xff*rgb *in 1000(
// 0xff, 0xff * 1000 // 0xff (255, 0xff0, * 1000 // 0xff0x64, 0),
(253, 0x82 * 1000 //(254, 0xff, 0x8c0xff, *0xff),
1000 // 0xff, 0x51 * 1000 // 0xff(253, 0x82, 0x8c, 0x51),
(252, 0xff * 1000 //(252, 0xff, 0xe4 * 1000 // 0xff, 0xb5),
* 1000 // 0xff),
(251, 0xc0 * 1000 // 0xff, 0xc0 * 1000 // 0xff, 0xc0)
* 1000 // 0xff)
)]
RED, BLUE, GREEN = c.COLOR_RED, c.COLOR_BLUE, c.COLOR_GREEN
color_pairs = (
(1, RED, BLUE), # water
(2, RED, GREEN), # grass
(3, RED, 255), # trees
(4, RED, 254), # mountains
(5, RED, 253), # swamp
(6, RED, 252), # desert
(7, RED, 251) # village
)
def win(stdscr):
for color in colors_for_initialising:
c.init_color(*color)
for color_pair in color_pairs:
c.init_pair(*color_pair)
colors = [c.color_pair(i) for i in range(1, 8)]
while True:
for i, j in product(range(30), range(119)):
stdscr.addch(i, j, ' ', colors[int(world_map[i][j])])
stdscr.refresh()
def main():
c.wrapper(win)
if __name__ == '__main__':
main()
- Introduced an alias for
curses
(c
) to make the code more concise. You can debate whether this change makes the code more or less readable — when you're using a module heavily, such as in this example, I generally prefer to use a shorter alias rather than having to type out the whole module name each time. - Also introduced aliases for
curses.COLOR_RED
,curses.COLOR_BLUE
andcurses.COLOR_GREEN
later on in the code, for the same reason. Out of these three, onlycurses.COLOR_RED
was used more than once, but I introduced aliases for the other two as well so as to keep the naming of colors consistent. - In your
win
function, you were callingcurses.init_color
andcurses.init_pair
repeatedly, which led to some repetitive code. I took the arguments for these calls out ofwin
and put them into a tuple in the global namespace, then abstracted your series of calls toinit_color
andinit_pair
into two for-loops inwin
. - I changed your
colors
list inwin
from a list-literal to a list-comprehension, making the code less repetitive, more concise and more readable. - I took out your nested for-loop in
win
and replaced it with a call toitertools.product
, which does the same thing but is more concise and (arguably) more readable.
import curses as c
from itertools import product
world_map = [
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000011111111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000011111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000011111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000111111111111111111110000000000000000000000000000000001111111111111111111111111000000000000000000000000000',
'00000000000000000111111111111111111111000000000000000000000000000001111111111111111111111111000000000000000000000000000',
'00000000000000000011111111111111111000000000000000000000000000000001111133333111111111111111000000000000000000000000000',
'00000000000000000000011111111111100000000000000000000000000000000001111133333111111111111111000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000001111133333111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000001111133333111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000001111133333111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000011111111111111111133333111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000011111111111111111133333111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000011111111111111111111111111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111000000000000000000000000000',
'00000000000000001111111111111111111111111000000000000011111111111110000000000000000000000000000000000000000000000000000',
'00000000000000001111111111111111111111111000000000000011111111111110000000000000000000000000000000000000000000000000000',
'00000000000000001114444411111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000001114444411111115555555111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000001114444411111115555555111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000001114444411111115555555111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000001111111111111115555555111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000001111111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
]
colors_for_initialising = (
(255, 0, 0x64 * 1000 // 0xff, 0),
(254, 0xff * 1000 // 0xff, 0xff * 1000 // 0xff, 0xff * 1000 // 0xff),
(253, 0x82 * 1000 // 0xff, 0x8c * 1000 // 0xff, 0x51 * 1000 // 0xff),
(252, 0xff * 1000 // 0xff, 0xe4 * 1000 // 0xff, 0xb5 * 1000 // 0xff),
(251, 0xc0 * 1000 // 0xff, 0xc0 * 1000 // 0xff, 0xc0 * 1000 // 0xff)
)
RED, BLUE, GREEN = c.COLOR_RED, c.COLOR_BLUE, c.COLOR_GREEN
color_pairs = (
(1, RED, BLUE), # water
(2, RED, GREEN), # grass
(3, RED, 255), # trees
(4, RED, 254), # mountains
(5, RED, 253), # swamp
(6, RED, 252), # desert
(7, RED, 251) # village
)
def win(stdscr):
for color in colors_for_initialising:
c.init_color(*color)
for color_pair in color_pairs:
c.init_pair(*color_pair)
colors = [c.color_pair(i) for i in range(1, 8)]
while True:
for i, j in product(range(30), range(119)):
stdscr.addch(i, j, ' ', colors[int(world_map[i][j])])
stdscr.refresh()
def main():
c.wrapper(win)
if __name__ == '__main__':
main()
- Introduced an alias for
curses
(c
) to make the code more concise. You can debate whether this change makes the code more or less readable — when you're using a module heavily, such as in this example, I generally prefer to use a shorter alias rather than having to type out the whole module name each time. - Also introduced aliases for
curses.COLOR_RED
,curses.COLOR_BLUE
andcurses.COLOR_GREEN
later on in the code, for the same reason. Out of these three, onlycurses.COLOR_RED
was used more than once, but I introduced aliases for the other two as well so as to keep the naming of colors consistent. - In your
win
function, you were callingcurses.init_color
andcurses.init_pair
repeatedly, which led to some repetitive code. I took the arguments for these calls out ofwin
and put them into a tuple in the global namespace, then abstracted your series of calls toinit_color
andinit_pair
into two for-loops inwin
. - I changed your
colors
list inwin
from a list-literal to a list-comprehension, making the code less repetitive, more concise and more readable. - I took out your nested for-loop in
win
and replaced it with a call toitertools.product
, which does the same thing but is more concise and (arguably) more readable.
import curses as c
from itertools import product
world_map = [
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000011111111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000011111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000011111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000111111111111111111110000000000000000000000000000000001111111111111111111111111000000000000000000000000000',
'00000000000000000111111111111111111111000000000000000000000000000001111111111111111111111111000000000000000000000000000',
'00000000000000000011111111111111111000000000000000000000000000000001111133333111111111111111000000000000000000000000000',
'00000000000000000000011111111111100000000000000000000000000000000001111133333111111111111111000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000001111133333111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000001111133333111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000001111133333111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000011111111111111111133333111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000011111111111111111133333111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000011111111111111111111111111111111222211000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111000000000000000000000000000',
'00000000000000001111111111111111111111111000000000000011111111111110000000000000000000000000000000000000000000000000000',
'00000000000000001111111111111111111111111000000000000011111111111110000000000000000000000000000000000000000000000000000',
'00000000000000001114444411111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000001114444411111115555555111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000001114444411111115555555111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000001114444411111115555555111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000001111111111111115555555111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000001111111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
]
colors_for_initialising = [
(n, *((i * 1000 // 0xff) for i in rgb))
for n, *rgb in (
(255, 0, 0x64, 0),
(254, 0xff, 0xff, 0xff),
(253, 0x82, 0x8c, 0x51),
(252, 0xff, 0xe4, 0xb5),
(251, 0xc0, 0xc0, 0xc0)
)
]
RED, BLUE, GREEN = c.COLOR_RED, c.COLOR_BLUE, c.COLOR_GREEN
color_pairs = (
(1, RED, BLUE), # water
(2, RED, GREEN), # grass
(3, RED, 255), # trees
(4, RED, 254), # mountains
(5, RED, 253), # swamp
(6, RED, 252), # desert
(7, RED, 251) # village
)
def win(stdscr):
for color in colors_for_initialising:
c.init_color(*color)
for color_pair in color_pairs:
c.init_pair(*color_pair)
colors = [c.color_pair(i) for i in range(1, 8)]
while True:
for i, j in product(range(30), range(119)):
stdscr.addch(i, j, ' ', colors[int(world_map[i][j])])
stdscr.refresh()
def main():
c.wrapper(win)
if __name__ == '__main__':
main()
- Introduced an alias for
curses
(c
) to make the code more concise. You can debate whether this change makes the code more or less readable — when you're using a module heavily, such as in this example, I generally prefer to use a shorter alias rather than having to type out the whole module name each time. - Also introduced aliases for
curses.COLOR_RED
,curses.COLOR_BLUE
andcurses.COLOR_GREEN
later on in the code, for the same reason. Out of these three, onlycurses.COLOR_RED
was used more than once, but I introduced aliases for the other two as well so as to keep the naming of colors consistent. - In your
win
function, you were callingcurses.init_color
andcurses.init_pair
repeatedly, which led to some repetitive code. I took the arguments for these calls out ofwin
and put them into the global namespace, then abstracted your series of calls toinit_color
andinit_pair
into two for-loops inwin
. - I changed your
colors
list inwin
from a list-literal to a list-comprehension, making the code less repetitive, more concise and more readable. - I took out your nested for-loop in
win
and replaced it with a call toitertools.product
, which does the same thing but is more concise and (arguably) more readable.
- Introduced an alias for
curses
(c
) to make the code more concise. You can debate whether this change makes the code more or less readable — when you're using a module heavily, such as in this example, I generally prefer to use a shorter alias rather than having to type out the whole module name each time. - Also introduced aliases for
curses.COLOR_RED
,curses.COLOR_BLUE
andcurses.COLOR_GREEN
later on in the code, for the same reason. Out of these three, only RED iscurses.COLOR_RED
was used more than once, but I introduced aliases for the other two as well so as to keep the naming of colors consistent. - In your
win
function, you were callingcurses.init_color
andcurses.init_pair
repeatedly, which led to some repetitive code. I took the arguments for these calls out ofwin
and put them into a tuple in the global namespace, then abstracted your series of calls toinit_color
andinit_pair
into two for-loops inwin
. - I changed your
colors
list inwin
from a list-literal to a list-comprehension, making the code less repetitive, more concise and more readable. - I took out your nested for-loop in
win
and replaced it with a call toitertools.product
, which does the same thing but is more concise and (arguably) more readable.
- Introduced an alias for
curses
(c
) to make the code more concise. You can debate whether this change makes the code more or less readable — when you're using a module heavily, such as in this example, I generally prefer to use a shorter alias rather than having to type out the whole module name each time. - Also introduced aliases for
curses.COLOR_RED
,curses.COLOR_BLUE
andcurses.COLOR_GREEN
later on in the code, for the same reason. Out of these three, only RED is used more than once, but I introduced aliases for the other two as well so as to keep the naming of colors consistent. - In your
win
function, you were callingcurses.init_color
andcurses.init_pair
repeatedly, which led to some repetitive code. I took the arguments for these calls out ofwin
and put them into a tuple in the global namespace, then abstracted your series of calls toinit_color
andinit_pair
into two for-loops inwin
. - I changed your
colors
list inwin
from a list-literal to a list-comprehension, making the code less repetitive, more concise and more readable. - I took out your nested for-loop in
win
and replaced it with a call toitertools.product
, which does the same thing but is more concise and (arguably) more readable.
- Introduced an alias for
curses
(c
) to make the code more concise. You can debate whether this change makes the code more or less readable — when you're using a module heavily, such as in this example, I generally prefer to use a shorter alias rather than having to type out the whole module name each time. - Also introduced aliases for
curses.COLOR_RED
,curses.COLOR_BLUE
andcurses.COLOR_GREEN
later on in the code, for the same reason. Out of these three, onlycurses.COLOR_RED
was used more than once, but I introduced aliases for the other two as well so as to keep the naming of colors consistent. - In your
win
function, you were callingcurses.init_color
andcurses.init_pair
repeatedly, which led to some repetitive code. I took the arguments for these calls out ofwin
and put them into a tuple in the global namespace, then abstracted your series of calls toinit_color
andinit_pair
into two for-loops inwin
. - I changed your
colors
list inwin
from a list-literal to a list-comprehension, making the code less repetitive, more concise and more readable. - I took out your nested for-loop in
win
and replaced it with a call toitertools.product
, which does the same thing but is more concise and (arguably) more readable.
- Introduced an alias for
curses
(c
) to make the code more concise. You can debate whether this change makes the code more or less readable — when you're using a module heavily, such as in this example, I generally prefer to use a shorter alias rather than having to type out the whole module name each time. - Also introduced aliases for
CURSEScurses.COLOR_RED
,curses.COLOR_BLUE
andcurses.COLOR_GREEN
later on in the code, for the same reason. Out of these three, only RED is used more than once, but I introduced aliases for the other two as well so as to keep the naming of colors consistent. - In your
win
function, you were callingcurses.init_color
andcurses.init_pair
repeatedly, which led to some repetitive code. I took the arguments for these calls out ofwin
and put them into a tuple in the global namespace, then abstracted your series of calls toinit_color
andinit_pair
into two for-loops inwin
. - I changed your
colors
list inwin
from a list-literal to a list-comprehension, making the code less repetitive, more concise and more readable. - I took out your nested for-loop in
win
and replaced it with a call toitertools.product
, which does the same thing but is more concise and (arguably) more readable.
- Introduced an alias for
curses
(c
) to make the code more concise. You can debate whether this change makes the code more or less readable — when you're using a module heavily, such as in this example, I generally prefer to use a shorter alias rather than having to type out the whole module name each time. - Also introduced aliases for
CURSES.COLOR_RED
,curses.COLOR_BLUE
andcurses.COLOR_GREEN
later on in the code, for the same reason. Out of these three, only RED is used more than once, but I introduced aliases for the other two as well so as to keep the naming of colors consistent. - In your
win
function, you were callingcurses.init_color
andcurses.init_pair
repeatedly, which led to some repetitive code. I took the arguments for these calls out ofwin
and put them into a tuple in the global namespace, then abstracted your series of calls toinit_color
andinit_pair
into two for-loops inwin
. - I changed your
colors
list inwin
from a list-literal to a list-comprehension, making the code less repetitive, more concise and more readable. - I took out your nested for-loop in
win
and replaced it with a call toitertools.product
, which does the same thing but is more concise and (arguably) more readable.
- Introduced an alias for
curses
(c
) to make the code more concise. You can debate whether this change makes the code more or less readable — when you're using a module heavily, such as in this example, I generally prefer to use a shorter alias rather than having to type out the whole module name each time. - Also introduced aliases for
curses.COLOR_RED
,curses.COLOR_BLUE
andcurses.COLOR_GREEN
later on in the code, for the same reason. Out of these three, only RED is used more than once, but I introduced aliases for the other two as well so as to keep the naming of colors consistent. - In your
win
function, you were callingcurses.init_color
andcurses.init_pair
repeatedly, which led to some repetitive code. I took the arguments for these calls out ofwin
and put them into a tuple in the global namespace, then abstracted your series of calls toinit_color
andinit_pair
into two for-loops inwin
. - I changed your
colors
list inwin
from a list-literal to a list-comprehension, making the code less repetitive, more concise and more readable. - I took out your nested for-loop in
win
and replaced it with a call toitertools.product
, which does the same thing but is more concise and (arguably) more readable.
Loading
Loading
Loading
lang-py