Esempio n. 1
0
 def print_out(self):
     int_to_char = {
         self.__BLANK: '. ',
         self._BLACK: 'X ',
         self._WHITE: 'O ',
     }
     print(self._FC_YELLOW + self.name)
     cell = ChessboardCell()
     # print column name on table head
     header = '    '
     for col_id in range(self._COLS, -1, -1):
         cell.from_col_row_id(col_id=col_id, row_id=1)
         header += cell.col_letter + ' '
     print(self._FC_YELLOW + header)
     # print layout row by row
     for row_id in range(0, self._ROWS):
         rowNum = self._ROWS - row_id
         col_string = ''
         for col_id in range(0, self._COLS):
             col_string += int_to_char[self._layout_array[18 -
                                                          col_id][18 -
                                                                  row_id]]
         row_string = "%02d" % rowNum + '  '
         print(self._FC_YELLOW + row_string + self._FC_RESET + col_string +
               self._FC_YELLOW + row_string)
     print(self._FC_YELLOW + header)
Esempio n. 2
0
    def print_out_died_area(self):
        int_to_char = {
            0: 'x ',
            1: 'O ',
            15: '. ',
            16: '- ',
            17: '* ',
            8: 'B ',
            3: 'W '
        }
        print(self._FC_YELLOW + 'Died area')
        cell = ChessboardCell()
        # print column name on table head
        header = '    '
        for col_id in range(19, -1, -1):
            cell.from_col_row_id(col_id=col_id, row_id=1)
            header += cell.col_letter + ' '
        print(self._FC_YELLOW + header)
        # print layout row by row
        for row_id in range(0, 19):
            rowNum = 19 - row_id
            col_string = ''
            for col_id in range(0, 19):
                value = self.__died_area_array[18 - col_id][18 - row_id]
                if value == 0:
                    col_string += self._BG_RED + int_to_char[
                        value] + self._FC_RESET
                else:
                    col_string += int_to_char[value]

            row_string = "%02d" % rowNum + '  '
            print(self._FC_YELLOW + row_string + self._FC_RESET + col_string +
                  self._FC_YELLOW + row_string)
        print(self._FC_YELLOW + header)
Esempio n. 3
0
 def get_first_died_cell(self):
     '''
     return:
         None means not found!
     '''
     cell = ChessboardCell()
     for row_id in range(0, self._ROWS):
         for col_id in range(0, self._COLS):
             if self.__died_area_array[col_id][row_id] == 0:
                 cell.from_col_row_id(col_id, row_id)
                 return cell
     return None
Esempio n. 4
0
 def get_first_cell(self, target_color):
     '''
     return:
         (x,y) is the target position
         (-1,-1) means not found!
     '''
     cell = ChessboardCell()
     for row_id in range(0, self._ROWS):
         for col_id in range(0, self._COLS):
             if self._layout_array[col_id][row_id] == target_color:
                 cell.from_col_row_id(col_id, row_id)
                 return cell
     return None
Esempio n. 5
0
 def create_four_corners(self):
     corners = [(0, 0), (0, 18), (18, 0), (18, 18)]
     for col, row in corners:
         cell = ChessboardCell()
         cell.from_col_row_id(col, row)
         self.__Deal_with_this_cell(cell)
Esempio n. 6
0
    def compare_with(self, target_layout, do_print_out=False):
        '''
        return: 
            total_diff_cells: the number of different cells.
            last_cell_name: first cell_name that different, might be None
            my_color: color of last_cell
            target_color: color of last_cell
        '''
        diffs = []
        cell = ChessboardCell()
        my_cell_color = target_cell_color = self.__BLANK

        int_to_char = {
            self.__BLANK: '. ',
            self._BLACK: 'X ',
            self._WHITE: 'O '
        }
        if do_print_out:
            title = self._FC_RESET + '       '
            title += self._BG_RED + self._FC_YELLOW + self.name
            title += self._FC_RESET + '                                         '
            title += self._BG_RED + self._FC_YELLOW + target_layout.name + self._FC_RESET
            print(title)

            # print column name on table head
            header = '  '
            for col_id in range(self._COLS, -1, -1):
                cell.from_col_row_id(col_id=col_id, row_id=1)
                header += cell.col_letter + ' '
            header += '  ' + header
            print(self._FC_YELLOW + header)

        # print layout row by row
        for row_id in range(self._ROWS - 1, -1, -1):
            rowNum = row_id + 1
            my_col_string = target_col_string = ''
            for col_id in range(self._COLS - 1, -1, -1):
                print_color = self._FC_RESET
                target_cell_color = target_layout.get_cell_color_col_row(
                    col_id=col_id, row_id=row_id)
                if (self._layout_array[col_id][row_id] != target_cell_color):
                    #color is different
                    print_color = self._BG_RED + self._FC_YELLOW
                    cell.from_col_row_id(col_id=col_id, row_id=row_id)
                    my_cell_color = self._layout_array[col_id][row_id]
                    diffs.append((cell.name, my_cell_color, target_cell_color))

                if do_print_out:
                    my_col_string += print_color + int_to_char[
                        self._layout_array[col_id][row_id]] + self._FC_RESET
                    k = target_layout.get_cell_color_col_row(col_id, row_id)
                    target_col_string += print_color + int_to_char[
                        k] + self._FC_RESET
            if do_print_out:
                row_string = self._FC_YELLOW + "%02d" % rowNum
                col_string = row_string + ' ' + my_col_string + ' ' + row_string + '  ' + target_col_string + ' ' + row_string
                print(col_string)
        if do_print_out:
            print(self._FC_YELLOW + header)
            print(self._BG_RED + self._FC_YELLOW + '%s' % diffs +
                  self._FC_RESET)
        return diffs
Esempio n. 7
0
 def play_col_row(self, col_id, row_id, color_code):
     cell = ChessboardCell()
     cell.from_col_row_id(col_id=col_id, row_id=row_id)
     self.play(cell.name, color_code)