<s> __author__ = """<STR_LIT>""" <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from os import getcwd <EOL> from os import sys <EOL> sys . path . append ( getcwd ( ) ) <EOL> from MOAL . helpers . display import Section <EOL> from MOAL . helpers . display import print_h3 <EOL> from MOAL . computer_organization . bit_field import BitField <EOL> DEBUG = True if __name__ == '<STR_LIT:__main__>' else False <EOL> class ChessPieceBitBoard ( BitField ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . cols = list ( '<STR_LIT>' ) <EOL> self . rows = range ( <NUM_LIT:1> , <NUM_LIT:8> ) <EOL> super ( ChessPieceBitBoard , self ) . __init__ ( ) <EOL> self . _populate_fields ( ) <EOL> def __str__ ( self ) : <EOL> print ( '<STR_LIT>' . format ( self . cols , self . rows ) ) <EOL> return '<STR_LIT>' <EOL> def _populate_fields ( self ) : <EOL> """<STR_LIT>""" <EOL> for col in self . cols : <EOL> for row in self . rows : <EOL> self [ '<STR_LIT>' . format ( col , row ) ] = False <EOL> class ChessBoard : <EOL> def __init__ ( self ) : <EOL> self . winner = None <EOL> self . white = { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } <EOL> self . black = { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } <EOL> self . boards = { } <EOL> pieces = ( <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:2> , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:8> , '<STR_LIT>' ) , <EOL> ) <EOL> for num_pieces , piece_name in pieces : <EOL> self [ piece_name ] = num_pieces <EOL> def __str__ ( self ) : <EOL> for name , board in self . boards . iteritems ( ) : <EOL> print ( '<STR_LIT>' . format ( name , '<STR_LIT>' ) ) <EOL> return '<STR_LIT>' <EOL> def __setitem__ ( self , piece_name , num_pieces ) : <EOL> if num_pieces > <NUM_LIT:1> : <EOL> for index in range ( num_pieces ) : <EOL> self . boards [ '<STR_LIT>' . format ( <EOL> piece_name , index ) ] = ChessPieceBitBoard ( ) <EOL> else : <EOL> self . boards [ piece_name ] = ChessPieceBitBoard ( ) <EOL> def __getitem__ ( self , piece ) : <EOL> return self . boards [ piece ] <EOL> def move ( self , piece , player , old_position , new_position ) : <EOL> print ( '<STR_LIT>' . format ( <EOL> player , piece , old_position , new_position ) ) <EOL> self . boards [ piece ] [ old_position ] = False <EOL> self . boards [ piece ] [ new_position ] = True <EOL> if DEBUG : <EOL> with Section ( '<STR_LIT>' ) : <EOL> print_h3 ( '<STR_LIT>' ) <EOL> chess_board = ChessBoard ( ) <EOL> moves = ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) <EOL> for info in moves : <EOL> piece , player , old , new = info <EOL> chess_board . move ( piece , player , old , new ) <EOL> print ( chess_board [ '<STR_LIT>' ] ) <EOL> print ( chess_board ) </s>
