def test_draw(pixmap_differ: PixmapDiffer):
    size = 240
    with pixmap_differ.create_painters(size, size,
                                       'tictactoe_draw') as (actual, expected):
        draw_square_grid(expected)
        expected.setBrush(TicTacToeDisplay.player1_colour)
        expected.drawEllipse(10, 10, 60, 60)
        expected.drawEllipse(10, 90, 60, 60)
        expected.drawEllipse(90, 170, 60, 60)
        expected.drawEllipse(170, 170, 60, 60)
        expected.drawEllipse(170, 10, 60, 60)
        expected.setBrush(TicTacToeDisplay.player2_colour)
        expected.drawEllipse(90, 10, 60, 60)
        expected.drawEllipse(90, 90, 60, 60)
        expected.drawEllipse(170, 90, 60, 60)
        expected.drawEllipse(10, 170, 60, 60)

        display = TicTacToeDisplay()
        display.resize(324, 264)

        display.update_board(display.start_state)
        board = TicTacToeState('''\
XOX
XOO
OXX
''')
        display.update_board(board)

        render_display(display, actual)
    assert display.ui.player_pixmap.pixmap() is None
    assert display.move_text.text() == 'draw'
def test_piece_hover_enter(pixmap_differ: PixmapDiffer):
    size = 240
    with pixmap_differ.create_painters(
            size, size, 'tictactoe_piece_hover_enter') as (actual, expected):
        draw_square_grid(expected)
        expected.setBrush(TicTacToeDisplay.player1_colour)
        expected.drawEllipse(10, 10, 60, 60)
        colour = QColor(TicTacToeDisplay.player2_colour)
        expected.setBrush(colour)
        colour.setAlpha(127)
        expected.setBrush(colour)
        colour.setRgb(0, 0, 0, 127)
        pen = QPen(colour)
        expected.setPen(pen)
        expected.drawEllipse(90, 10, 60, 60)

        display = TicTacToeDisplay()

        board = TicTacToeState('''\
X..
...
...
''')
        display.resize(324, 264)
        display.ui.game_display.grab()
        display.update_board(board)
        display.on_hover_enter(display.spaces[0][1])

        render_display(display, actual)
def test_start_tall(pixmap_differ: PixmapDiffer):
    size = 120
    with pixmap_differ.create_painters(size, size * 2,
                                       'tictactoe_start_tall') as (actual,
                                                                   expected):
        expected.fillRect(0, 0, size + 40, size * 2,
                          TicTacToeDisplay.background_colour)
        expected.drawLine(0, 100, 120, 100)
        expected.drawLine(0, 140, 120, 140)
        expected.drawLine(40, 60, 40, 180)
        expected.drawLine(80, 60, 80, 180)

        display = TicTacToeDisplay()
        display.resize(180, 264)
        render_display(display, actual)
def test_start_wide(pixmap_differ: PixmapDiffer):
    size = 240
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(size * 2, size,
                                       'tictactoe_start_wide') as (actual,
                                                                   expected):
        expected.fillRect(0, 0, size * 2 + 80, size,
                          TicTacToeDisplay.background_colour)
        expected.drawLine(120, 80, 360, 80)
        expected.drawLine(120, 160, 360, 160)
        expected.drawLine(200, 0, 200, 240)
        expected.drawLine(280, 0, 280, 240)

        display = TicTacToeDisplay()
        display.resize(612, 264)
        render_display(display, actual)
def test_coordinates(pixmap_differ: PixmapDiffer):
    assert 1 == 1
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(200, 200,
                                       'tictactoe_coordinates') as (actual,
                                                                    expected):
        expected.fillRect(0, 0, 250, 200, TicTacToeDisplay.background_colour)
        expected.drawLine(50, 100, 200, 100)
        expected.drawLine(50, 150, 200, 150)
        expected.drawLine(100, 50, 100, 200)
        expected.drawLine(150, 50, 150, 200)
        expected.setBrush(TicTacToeDisplay.player1_colour)
        expected.drawEllipse(106, 106, 37, 37)
        set_font_size(expected, 25)
        draw_text(expected, 75, 25, 'A')
        draw_text(expected, 125, 25, 'B')
        draw_text(expected, 175, 25, 'C')
        draw_text(expected, 25, 75, '1')
        draw_text(expected, 25, 125, '2')
        draw_text(expected, 25, 175, '3')

        display = TicTacToeDisplay()
        display.resize(276, 224)

        display.show_coordinates = True
        board = TicTacToeState('''\
  ABC
1 ...
2 .X.
3 ...
''')
        display.update_board(board)

        render_display(display, actual)
def test_piece_hover_leave(pixmap_differ: PixmapDiffer):
    size = 240
    with pixmap_differ.create_painters(
            size, size, 'tictactoe_piece_hover_leave') as (actual, expected):
        draw_square_grid(expected)

        display = TicTacToeDisplay()
        display.resize(324, 264)
        display.ui.game_display.grab()
        display.on_hover_enter(display.spaces[0][1])
        display.on_hover_leave(display.spaces[0][1])

        render_display(display, actual)
def test_pieces(pixmap_differ: PixmapDiffer):
    size = 240
    with pixmap_differ.create_painters(size, size,
                                       'tictactoe_pieces') as (actual,
                                                               expected):
        draw_square_grid(expected)
        expected.setBrush(TicTacToeDisplay.player1_colour)
        expected.drawEllipse(10, 10, 60, 60)
        expected.drawEllipse(90, 90, 60, 60)
        expected.setBrush(TicTacToeDisplay.player2_colour)
        expected.drawEllipse(90, 10, 60, 60)

        display = TicTacToeDisplay()
        board = TicTacToeState('''\
XO.
.X.
...
''')
        display.update_board(board)

        display.resize(324, 264)
        render_display(display, actual)

    player_pixmap = display.ui.player_pixmap.pixmap()
    assert player_pixmap.toImage() == display.player2_icon.toImage()
def test_winner(pixmap_differ: PixmapDiffer):
    assert 1 == 1
    size = 240
    with pixmap_differ.create_painters(size, size,
                                       'tictactoe_winner') as (actual,
                                                               expected):
        draw_square_grid(expected)
        expected.setBrush(TicTacToeDisplay.player1_colour)
        expected.drawEllipse(10, 10, 60, 60)
        expected.drawEllipse(90, 90, 60, 60)
        expected.drawEllipse(170, 170, 60, 60)
        expected.setBrush(TicTacToeDisplay.player2_colour)
        expected.drawEllipse(90, 10, 60, 60)
        expected.drawEllipse(170, 90, 60, 60)

        display = TicTacToeDisplay()
        display.resize(324, 264)

        board = TicTacToeState('''\
XO.
.XO
..X
''')
        display.update_board(board)

        assert not display.spaces[0][2].isVisible()
        expected_icon = display.player1_icon.toImage()
        assert display.ui.player_pixmap.pixmap().toImage() == expected_icon
        assert display.move_text.text() == 'wins'
        render_display(display, actual)
def test_start_square(pixmap_differ: PixmapDiffer):
    size = 240
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(size, size,
                                       'tictactoe_start_square') as (actual,
                                                                     expected):
        draw_square_grid(expected)
        expected.setBrush(TicTacToeDisplay.player1_colour)

        display = TicTacToeDisplay()
        display.resize(324, 264)

        render_display(display, actual)
        player_pixmap = display.ui.player_pixmap.pixmap()
        assert player_pixmap.toImage() == display.player1_icon.toImage()
        assert display.ui.move_text.text() == 'to move'
        assert display.ui.black_count_pixmap.pixmap() is None
        assert display.ui.white_count_pixmap.pixmap() is None
        assert display.ui.black_count_pixmap.text() == ''
        assert display.ui.white_count_pixmap.text() == ''
        assert display.ui.black_count.text() == ''
        assert display.ui.white_count.text() == ''
Exemplo n.º 10
0
    def __init__(self):
        display = TicTacToeDisplay()
        display.update_board(TicTacToeState('''\
OX.
XO.
X.O
'''))
        display.resize(276, 224)
        super().__init__(display, 200, 200)
def test_piece_hover_enter_mcts(pixmap_differ: PixmapDiffer):
    """ Don't display move options while MCTS player is thinking. """
    size = 240
    with pixmap_differ.create_painters(
            size, size,
            'tictactoe_piece_hover_enter_mcts') as (actual, expected):
        draw_square_grid(expected)

        display = TicTacToeDisplay()
        player = MctsPlayer(display.start_state, TicTacToeState.X_PLAYER)
        display.mcts_players = (player, )

        display.resize(324, 264)
        display.ui.game_display.grab()
        display.on_hover_enter(display.spaces[0][1])

        render_display(display, actual)
        display.close()
    assert display.move_text.text() == 'thinking'
    expected_icon = display.player1_icon.toImage()
    assert display.ui.player_pixmap.pixmap().toImage() == expected_icon
def test_piece_hover_existing(pixmap_differ: PixmapDiffer):
    size = 240
    with pixmap_differ.create_painters(
            size, size,
            'tictactoe_piece_hover_existing') as (actual, expected):
        draw_square_grid(expected)
        expected.setBrush(TicTacToeDisplay.player1_colour)
        expected.drawEllipse(10, 10, 60, 60)

        display = TicTacToeDisplay()

        board = TicTacToeState('''\
X..
...
...
''')
        display.update_board(board)
        display.resize(324, 264)
        display.ui.game_display.grab()
        display.on_hover_enter(display.spaces[0][0])

        render_display(display, actual)
def test_piece_click(pixmap_differ: PixmapDiffer):
    size = 240
    with pixmap_differ.create_painters(size, size,
                                       'tictactoe_piece_click') as (actual,
                                                                    expected):
        draw_square_grid(expected)
        expected.setBrush(TicTacToeDisplay.player1_colour)
        expected.drawEllipse(10, 10, 60, 60)

        display = TicTacToeDisplay()
        display.resize(324, 264)
        display.ui.game_display.grab()

        display.on_click(display.spaces[0][0])

        render_display(display, actual)
Exemplo n.º 14
0
def test_icon(pixmap_differ: PixmapDiffer):
    actual: QPainter
    expected: QPainter
    with pixmap_differ.create_painters(
            300, 240, 'scaled_radio_button_icon') as (actual, expected):
        display = TicTacToeDisplay()
        icon = display.player1_icon
        display.close()
        ex_widget = QWidget()
        ex_layout = QVBoxLayout(ex_widget)
        ex_radio1 = QRadioButton()
        ex_radio2 = QRadioButton('Lorem ipsum')
        ex_radio1.setIcon(icon)
        ex_radio2.setIcon(icon)
        ex_font = ex_radio1.font()
        if ex_font.family() == 'Sans Serif':
            # Fonts are different on GitHub actions.
            big_font_size = 93
            small_font_size = 23
            ex_radio1.setStyleSheet('QRadioButton::indicator {width: 93} '
                                    'QRadioButton {spacing: 46}')
            ex_radio2.setStyleSheet('QRadioButton::indicator {width: 23} '
                                    'QRadioButton {spacing: 11}')
        else:
            big_font_size = 93
            small_font_size = 25
            ex_radio1.setStyleSheet('QRadioButton::indicator {width: 93} '
                                    'QRadioButton {spacing: 46}')
            ex_radio2.setStyleSheet('QRadioButton::indicator {width: 25} '
                                    'QRadioButton {spacing: 12}')
        ex_radio1.setIconSize(
            QSize(big_font_size * 3 // 2, big_font_size * 3 // 2))
        ex_radio2.setIconSize(
            QSize(small_font_size * 3 // 2, small_font_size * 3 // 2))
        ex_font.setPointSize(big_font_size)
        ex_radio1.setFont(ex_font)
        ex_font.setPointSize(small_font_size)
        ex_radio2.setFont(ex_font)
        ex_size_policy = QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
        ex_radio1.setSizePolicy(ex_size_policy)
        ex_radio2.setSizePolicy(ex_size_policy)
        ex_layout.addWidget(ex_radio1)
        ex_layout.addWidget(ex_radio2)
        ex_layout.setStretch(0, 4)
        ex_layout.setStretch(1, 1)

        ex_widget.resize(300, 240)
        expected.drawPixmap(0, 0, ex_widget.grab())

        widget = QWidget()
        layout = QVBoxLayout(widget)
        radio1 = ScaledRadioButton()
        radio2 = ScaledRadioButton('Lorem ipsum')
        radio1.setIcon(icon)
        radio2.setIcon(icon)
        size_policy = QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
        radio1.setSizePolicy(size_policy)
        radio2.setSizePolicy(size_policy)
        layout.addWidget(radio1)
        layout.addWidget(radio2)
        layout.setStretch(0, 4)
        layout.setStretch(1, 1)

        widget.resize(300, 240)

        actual.drawPixmap(0, 0, widget.grab())