def test_game_win(): small_board = Board(2, 2) small_board.set_value((0, 0), 'boom') small_board.set_value((0, 1), 'boom') small_board.set_value((1, 0), 'boom') small_board.fill_board() small_board.dig((1, 1)) assert small_board.game_over is True assert small_board.game_won is True
def test_rupoor(): new = Board(2, 2) new.set_value((0, 0), 'rupoor') new.fill_board() new.dig((0, 1)) assert new.bombs == 1 assert new.dig((0, 0)) == 'rupoor' assert new.score == 0 assert new.values[1][1] == 'blue' assert new.bombs == 0
def test_set_value(): fake = Board(5, 8) fake.set_value((1, 1), 'blue') fake.set_value((1, 2), 'green') fake.set_value((2, 2), 'silver') assert fake.values[1][1] == 'blue' assert fake.values[1][2] == 'green' assert fake.values[2][2] == 'silver'
def test_score_code(): new = Board() assert new.score_code('green') == 1 assert new.score_code('blue') == 5 assert new.score_code('red') == 20 assert new.score_code('silver') == 100 assert new.score_code('gold') == 300 assert new.score_code('boom') == 0
def test_color_code(): new = Board() assert new.color_code(0) == 'green' assert new.color_code(1) == 'blue' assert new.color_code(2) == 'blue' assert new.color_code(3) == 'red' assert new.color_code(4) == 'red' assert new.color_code(5) == 'silver' assert new.color_code(6) == 'silver' assert new.color_code(7) == 'gold' assert new.color_code(8) == 'gold'
def test_game_start(): new = Board() new.game_start(booms=5, rupoors=4) assert new.bombs == 9 values_list = [] for row in new.values: values_list += row for col in row: assert col is not None assert values_list.count('boom') == 5 assert values_list.count('rupoor') == 4 new.dig((0, 0)) new.game_start() assert not new.game_over
def play(num_games): play_area = Board(5, 8) scores = [] moveslist = [] winlist = [] for i in range(num_games): play_area.game_start() while not play_area.game_over: play_area.random_play() scores.append(play_area.score) moveslist.append(play_area.moves) winlist.append(play_area.game_won) return moveslist, scores, winlist
def test_valid_start(): failed_start = Board(2, 2) try: failed_start.game_start() assert False except AssertionError: assert failed_start.values[0][0] is None try: failed_start.game_start(2, 2) assert False except AssertionError: assert failed_start.values[0][0] is None
def gen_game(game_type): if game_type == 'beginner': game = Board(4, 5) game.game_start(4, 0) if game_type == 'intermediate': game = Board(5, 6) game.game_start(4, 4) if game_type == 'expert': game = Board(5, 8) game.game_start(8, 8) return game
def interactive_start(): print('Welcome to Thrill Digger! (version: {})'.format( thrill_digger_tdd.__version__)) print('Choose difficulty: (beginner, intermediate, expert)') game_type = input() if game_type == 'beginner': play_area = Board(4, 5) play_area.game_start(booms=4, rupoors=0) elif game_type == 'intermediate': play_area = Board(5, 6) play_area.game_start(booms=4, rupoors=4) elif game_type == 'expert': play_area = Board(5, 8) play_area.game_start(booms=8, rupoors=8) elif game_type == 'q': print('Quitting') else: interactive_start() digs = [[' ' for _ in row] for row in play_area.values] print_board(play_area, digs) return play_area, digs
def new(): new = Board(5, 8) new.set_value((0, 0), 'boom') new.set_value((2, 2), 'boom') new.set_value((4, 7), 'boom') new.set_value((4, 6), 'boom') new.set_value((4, 5), 'boom') new.set_value((3, 7), 'boom') new.set_value((3, 5), 'boom') new.set_value((2, 7), 'boom') new.set_value((3, 3), 'rupoor') new.fill_board() return new
def test_set_random(): new = Board(5, 8) pos = new.set_random('boom') assert new.is_bomb((pos[0], pos[1]))
def test_board_default_shape(): default = Board() assert default.height == 5 assert default.width == 8 assert default.size == 40