#!/usr/bin/env python
import sys;

sys.path.append("..")
from fireplace import cards
from fireplace.exceptions import GameOver
from fireplace.utils import play_full_game


def test_full_game():
    try:
        play_full_game()
    except GameOver:
        print("Game completed normally.")


def main():
    cards.db.initialize()
    if len(sys.argv) > 1:
        numgames = sys.argv[1]
        if not numgames.isdigit():
            sys.stderr.write("Usage: %s [NUMGAMES]\n" % (sys.argv[0]))
            exit(1)
        for i in range(int(numgames)):
            test_full_game()
    else:
        test_full_game()


if __name__ == "__main__":
    main()
