X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=naja%2Futils.py;h=d69cd4ad73f42dfc71a28912a9e751deb3de3129;hb=3e460450c1baa9af43f5391ba4673a599071656b;hp=a40b8412f0adaba2389533f25445b998a79761b3;hpb=0f233e6d450d863f06f5acddee3bd94f53594d08;p=naja.git diff --git a/naja/utils.py b/naja/utils.py index a40b841..d69cd4a 100644 --- a/naja/utils.py +++ b/naja/utils.py @@ -1,5 +1,7 @@ import pygame +from naja.constants import BITS + def convert_colour(colour): if isinstance(colour, pygame.Color): @@ -9,3 +11,17 @@ def convert_colour(colour): if isinstance(colour, basestring): return pygame.Color(colour) raise ValueError() + + +def bit_glyphs(bits): + bit_names = dict((v, k) for k, v in BITS.items()) + return '{%s}' % ','.join(bit_names[bit] for bit in reversed(range(8)) + if bit in bits) + + +def move_glyph(move_name): + return { + 'CASTLE': u'\u265c', + 'BISHOP': u'\u265d', + 'KNIGHT': u'\u265e', + }.get(move_name, move_name.lower())