Beispiel #1
0
def test_first_move(x, y, p):
    board = oxo.OxoBoard()
    assert board.set_square(x, y, p)
    assert board.get_winner() == 0
    expected = [0] * 9
    expected[y * 3 + x] = p
    compare_board(board, expected)
Beispiel #2
0
def test_fill_board(p):
    board = oxo.OxoBoard()

    for x, y in [(1, 1), (0, 0), (1, 2), (1, 0), (2, 0), (0, 2), (0, 1),
                 (2, 1)]:
        assert board.set_square(x, y, p)
        assert board.get_winner() == 0
        assert not board.is_board_full()
        p = 3 - p

    assert board.set_square(2, 2, p)
    assert board.get_winner() == 0
    assert board.is_board_full()
Beispiel #3
0
def test_diagonal_line_1(p):
    p2 = 3 - p

    board = oxo.OxoBoard()

    for x in xrange(2):
        assert board.set_square(x, x, p)
        assert board.get_winner() == 0

        assert board.set_square(x, (x + 1) % 3, p2)
        assert board.get_winner() == 0

    assert board.set_square(2, 2, p)
    assert board.get_winner() == p
Beispiel #4
0
def test_horizontal_line(y, p):
    y2 = (y + 1) % 3
    p2 = 3 - p

    board = oxo.OxoBoard()

    for x in xrange(2):
        assert board.set_square(x, y, p)
        assert board.get_winner() == 0

        assert board.set_square(x, y2, p2)
        assert board.get_winner() == 0

    assert board.set_square(2, y, p)
    assert board.get_winner() == p
Beispiel #5
0
def test_vertical_line(x, p):
    x2 = (x + 1) % 3
    p2 = 3 - p

    board = oxo.OxoBoard()

    for y in xrange(2):
        assert board.set_square(x, y, p)
        assert board.get_winner() == 0

        assert board.set_square(x2, y, p2)
        assert board.get_winner() == 0

    assert board.set_square(x, 2, p)
    assert board.get_winner() == p
Beispiel #6
0
def test_second_move(x1, y1, p1, x2, y2):
    board = oxo.OxoBoard()
    assert board.set_square(x1, y1, p1)
    assert board.get_winner() == 0

    p2 = 3 - p1

    if x1 == x2 and y1 == y2:
        assert board.set_square(x2, y2, p2) == False
        assert board.get_winner() == 0
    else:
        assert board.set_square(x2, y2, p2)
        assert board.get_winner() == 0
        expected = [0] * 9
        expected[y1 * 3 + x1] = p1
        expected[y2 * 3 + x2] = p2
        compare_board(board, expected)
Beispiel #7
0
def test_empty_board_no_winner():
    board = oxo.OxoBoard()
    assert board.get_winner() == 0
Beispiel #8
0
def test_empty_board():
    board = oxo.OxoBoard()
    compare_board(board, [0] * 9)
Beispiel #9
0
window_width = 600
window_height = 600
window_size = (window_width, window_height)

grid_width = 3
grid_height = 3

square_width = window_width / grid_width
square_height = window_height / grid_height

# Create the screen
screen = pygame.display.set_mode(window_size)

# Create the game board
game_board = oxo.OxoBoard()

# If the game is over, game_over_text will be a pygame surface containing the game over text
# Otherwise it will be None
game_over_text = None


def check_game_over():
    """ Check if the game has ended; if so, set game_over_text.
		Return True if the game is over, otherwise False. """
    global game_over_text

    winner = game_board.get_winner()
    if winner != 0:
        font = pygame.font.Font(None, 60)
        game_over_text = font.render("Player %i wins!" % winner, True, purple,
window_width = 600
window_height = 600
window_size = (window_width, window_height)

grid_width = 3
grid_height = 3
win_amount = 3

square_width = window_width / grid_width
square_height = window_height / grid_height

# Create the screen
screen = pygame.display.set_mode(window_size)

# Create the game board
game_board = oxo.OxoBoard(grid_width, grid_height, win_amount)

# If the game is over, game_over_text will be a pygame surface containing the game over text
# Otherwise it will be None
game_over_text = None


def check_game_over():
	""" Check if the game has ended; if so, set game_over_text.
		Return True if the game is over, otherwise False. """
	global game_over_text

	winner = game_board.get_winner()
	if winner != 0:
		font = pygame.font.Font(None, 60)
		game_over_text = font.render("Player %i wins!" % winner, True, purple, white)