<s> import sys <EOL> from game . settings import * <EOL> from game import color as clr <EOL> __author__ = '<STR_LIT>' <EOL> class Piece ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , x , y , colour ) : <EOL> self . x = x <EOL> self . y = y <EOL> self . state = '<STR_LIT>' <EOL> self . flipped = False <EOL> self . colour = colour <EOL> self . drawing = { <EOL> "<STR_LIT>" : self . draw_white , <EOL> "<STR_LIT>" : self . draw_black , <EOL> "<STR_LIT>" : self . draw_board , <EOL> "<STR_LIT>" : self . draw_move } <EOL> def draw ( self ) : <EOL> """<STR_LIT>""" <EOL> result = '<STR_LIT>' <EOL> if self . state in self . drawing : <EOL> result = self . drawing [ self . state ] ( ) <EOL> return result <EOL> def draw_white ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . flipped : <EOL> if self . colour : <EOL> return clr . format_color ( '<STR_LIT>' , fg = clr . rgb ( <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:4> ) , bg = clr . rgb ( <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> ) ) <EOL> return '<STR_LIT>' <EOL> else : <EOL> if self . colour : <EOL> return clr . format_color ( '<STR_LIT:U+0020>' , bg = clr . rgb ( <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> ) ) <EOL> return '<STR_LIT>' <EOL> def draw_black ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . flipped : <EOL> if self . colour : <EOL> return clr . format_color ( '<STR_LIT>' , fg = clr . rgb ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> ) , bg = clr . rgb ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> return '<STR_LIT>' <EOL> else : <EOL> if self . colour : <EOL> return clr . format_color ( '<STR_LIT:U+0020>' , bg = clr . rgb ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> return '<STR_LIT>' <EOL> def draw_board ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . colour : <EOL> return clr . format_color ( '<STR_LIT:U+0020>' , bg = clr . rgb ( <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:0> ) ) <EOL> else : <EOL> return '<STR_LIT:..>' <EOL> def draw_move ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . colour : <EOL> return clr . format_color ( '<STR_LIT>' , fg = clr . rgb ( <NUM_LIT:5> , <NUM_LIT:0> , <NUM_LIT:0> ) , bg = clr . rgb ( <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:0> ) ) <EOL> return '<STR_LIT>' <EOL> def set_black ( self ) : <EOL> """<STR_LIT>""" <EOL> self . state = '<STR_LIT>' <EOL> def set_white ( self ) : <EOL> """<STR_LIT>""" <EOL> self . state = '<STR_LIT>' <EOL> def set_move ( self ) : <EOL> """<STR_LIT>""" <EOL> self . state = MOVE <EOL> def set_board ( self ) : <EOL> """<STR_LIT>""" <EOL> self . state = BOARD <EOL> def get_state ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . state <EOL> def flip ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . state == BLACK : <EOL> self . state = WHITE <EOL> elif self . state == WHITE : <EOL> self . state = BLACK <EOL> else : <EOL> raise ValueError <EOL> self . flipped = True <EOL> def set_flipped ( self ) : <EOL> """<STR_LIT>""" <EOL> self . flipped = True <EOL> def reset_flipped ( self ) : <EOL> """<STR_LIT>""" <EOL> self . flipped = False <EOL> def is_flipped ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . flipped <EOL> def get_position ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . x , self . y <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . x , self . y ) </s>
