Esempio n. 1
0
    def test_source_valid(self):
        ris = source("apologies.source.RandomInputSource")
        assert isinstance(ris, RandomInputSource)

        ris = source("RandomInputSource")
        assert isinstance(
            ris, RandomInputSource
        )  # if there's no module, we assume "apologies.source"
Esempio n. 2
0
def demo(argv: List[str], unused_stdout: IO[str],
         unused_stderr: IO[str]) -> None:
    """Run a game with simulated players, displaying output on the terminal."""
    parser = argparse.ArgumentParser(
        description=
        "Run a game with simulated players, displaying output on the terminal.",
        epilog=
        "By default, the game runs in %s mode with %d players. A source is a class that chooses a player's move."
        % (_DEMO_DEFAULT_MODE, _DEMO_DEFAULT_PLAYERS),
    )

    parser.add_argument("--players",
                        type=int,
                        default=_DEMO_DEFAULT_PLAYERS,
                        help="Number of simulated players in the game")
    parser.add_argument("--mode",
                        type=str,
                        default=_DEMO_DEFAULT_MODE,
                        choices=_DEMO_MODE_CHOICES,
                        help="Choose the game mode")
    parser.add_argument("--source",
                        type=str,
                        default=_DEMO_DEFAULT_SOURCE,
                        help="Fully-qualified name of the character source")
    parser.add_argument(
        "--delay",
        type=float,
        default=_DEMO_DEFAULT_DELAY_SEC,
        help="Delay between computer-generated moves (fractional seconds)")

    args = parser.parse_args(args=argv[2:])
    run_demo(players=args.players,
             mode=GameMode[args.mode],
             source=source(args.source),
             delay_sec=args.delay)
Esempio n. 3
0
def simulation(argv: List[str], unused_stdout: IO[str],
               unused_stderr: IO[str]) -> None:
    """Run a simulation and display results."""
    parser = argparse.ArgumentParser(
        description=
        "Run a simulation to see how well different character input sources behave.",
        epilog=
        "Every combination of game mode, number of players, and input source is tested, "
        "using %d iterations by default.  A spreadsheet is generated containing statistics "
        "on mean and median turns and duration to win, as well as number of wins for each "
        "source." % _SIM_DEFAULT_ITERATIONS,
    )

    parser.add_argument("--iter",
                        type=int,
                        default=_SIM_DEFAULT_ITERATIONS,
                        help="Number of iterations per scenario")

    parser.add_argument("--out",
                        type=str,
                        default=_SIM_DEFAULT_OUT,
                        help="Path to the output CSV file")

    parser.add_argument(
        "source",
        type=str,
        nargs="+",
        help="Fully-qualified name of the character sources to test")

    args = parser.parse_args(args=argv[2:])

    errors = []
    if args.iter <= 0:
        errors.append("simulation: error: there must be at least 1 iteration")

    if errors:
        parser.print_usage()
        print("\n".join(errors))
        sys.exit(1)

    run_simulation(iterations=args.iter,
                   output=args.out,
                   sources=[source(s) for s in args.source])
Esempio n. 4
0
 def test_source_invalid(self):
     with pytest.raises(ValueError):
         source("apologies.engine.Engine"
                )  # valid class, but not a CharacterInputSource
Esempio n. 5
0
 def test_source_unknown(self):
     with pytest.raises(TypeError):
         source("apologies.game.Blah")  # not a valid class