コード例 #1
0
 def mancala(self):
     return MancalaBoard(6, 4,
                         [[0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0], [27, 19]])
コード例 #2
0
 def mancala(self):
     return MancalaBoard(6, 4, None, 555)
コード例 #3
0
 def mancala(self):
     return MancalaBoard(6, 4,
                         [[0, 0, 0, 0, 5, 0], [1, 0, 0, 0, 0, 0], [20, 20]])
コード例 #4
0
 def mancala(self):
     return MancalaBoard(6, 10,
                         [[0, 0, 0, 3, 2, 1], [1, 4, 6, 0, 0, 2], [0, 0]])
コード例 #5
0
 def test_appends_the_game_state_to_logs_when_player_one_takes_a_turn(
         self, game_state_mock):
     mancala = MancalaBoard(6, 4)
     mancala.play(1, 3)
     assert mancala.game_state_log == [{"game_state": "values"}]
コード例 #6
0
 def mancala(self):
     return MancalaBoard(6, 4)
コード例 #7
0
 def __init__(self):
     super().__init__()
     self.board_drawer = MancalaBoardDrawer(self.WIDTH, self.HEIGHT)
     self.moves_sequence = []
     self.board = MancalaBoard()
コード例 #8
0
class MancalaCanvas(GameCanvas):
    """
    Class represents mancala GUI.
    """
    def __init__(self):
        super().__init__()
        self.board_drawer = MancalaBoardDrawer(self.WIDTH, self.HEIGHT)
        self.moves_sequence = []
        self.board = MancalaBoard()

    def paintEvent(self, event: QtGui.QPaintEvent):
        """
        Repaints game area. Overrides the base class.

		Args:
			event:  QtGui.QPaintEvent object, event that caused the repaint

		Returns:
			None        
		"""
        super().paintEvent(event)
        painter = QPainter(self)
        painter.setRenderHint(QPainter.HighQualityAntialiasing)
        self.board_drawer.draw_board(painter, self.board)

    def mousePressEvent(self, event):
        """
        Handler to player's click event. Checks if player can move - if a valid move was chosen, it is executed then.
        Overrides the base class.

		Args:
			event:  QtGui.QMouseEvent with information about click

		Returns:
			None        
		"""
        if not self.player_can_click:
            return
        super().mousePressEvent(event)
        pos = event.pos()
        player_moved, moved_index = self.board_drawer.detect_click(
            pos.x(), pos.y())
        if not player_moved and self.board_drawer.selected_hole_index != -1:
            board_index = self.board_drawer.draw_index_to_board_index(
                self.board_drawer.selected_hole_index)
            if not self.board.is_hole_valid(board_index):
                self.board_drawer.selected_hole_index = -1
        extra_turn = False
        if player_moved:
            old_board_values = copy.deepcopy(self.board.board_values)
            extra_turn = self.board.perform_move_internal(
                moved_index, self.board.current_player)
            self.board_drawer.update_stones_positions(self.board,
                                                      old_board_values)
            self.moves_sequence.append(moved_index)
        self.repaint()

        if not extra_turn and player_moved or self.board.phase != GamePhase.IN_PROGRESS:
            player = 1 if self.board.current_player == 2 else 2
            player_move = MancalaMove(copy.deepcopy(self.moves_sequence),
                                      player)
            self.moves_sequence.clear()
            move_info = {"move": player_move, "phase": self.board.phase}
            self.player_move_performed.fire(self, earg=move_info)

    def perform_algorithm_move(self, move: MancalaMove):
        """
        Performs PC's move and causes a game area repaint.

		Args:
			move:  MancalaMove object

		Returns:
			None        
		"""
        super().perform_algorithm_move(move)
        old_board_values = copy.deepcopy(self.board.board_values)
        self.board.perform_move(move)
        self.board_drawer.update_stones_positions(self.board, old_board_values)
        self.repaint()