예제 #1
0
 def _init_board(self):
     """Initialization of the chess board"""
     
     self._buttons = []
     layout = QGridLayout()
     layout.setSpacing(0)
     
     #create labels of rows and columns
     for i in range(1, Common.board_size + 1):
         self._add_chessboard_label(layout, i, 0)
         self._add_chessboard_label(layout, i, Common.board_size + 1)
         self._add_chessboard_label(layout, 0, i)
         self._add_chessboard_label(layout, Common.board_size + 1, i)
         
     #create fields of the board
     for x in range(Common.board_size):
         for y in range(Common.board_size):
             button = PictureButton(self, Common.reverse(y, -1) * Common.board_size + x)
             button.setCheckable(True)
             button.clicked.connect(self.button_clicked)
             self._buttons.append(button)
             layout.addWidget(button, y + 1, x + 1)
     self.board_layout = layout
     self._board_labels()
     return layout
예제 #2
0
 def _board_labels(self):
     """Write labels of rows and columns of the chess board."""
     
     for x in range(1, Common.board_size + 1):
         letter = chr(ord('A') + x - 1)
         self.board_layout.itemAtPosition(0, x).widget().setText(letter)
         self.board_layout.itemAtPosition(Common.board_size + 1, x).widget().setText(letter)
     direction = -1 if self.players_select[UICommons.WHITE_STR].isChecked() else 1
     for y in range(1, Common.board_size + 1):
         letter = chr(ord('A') + Common.reverse(y - 1, direction))
         self.board_layout.itemAtPosition(y, 0).widget().setText(letter)
         self.board_layout.itemAtPosition(y, Common.board_size + 1).widget().setText(letter)
예제 #3
0
 def game_position(position, color):
     """Evaluate position on the game from position on the board by regarding player's color"""
     direction = color * 2 - 1
     x, y = position % Common.board_size, position // Common.board_size
     return Common.reverse(
         x, direction) + Common.reverse(y, direction) * Common.board_size
예제 #4
0
 def game_position(position, color):
     """Evaluate position on the game from position on the board by regarding player's color"""
     direction = color * 2 - 1
     x, y = position % Common.board_size, position // Common.board_size
     return Common.reverse(x, direction) + Common.reverse(y, direction) * Common.board_size