Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 9d56b12587
Fetching contributors…

Cannot retrieve contributors at this time

executable file 110 lines (83 sloc) 3.39 kB
#!/usr/bin/env python
__copyright__ = "Copyright (c) 2005-2012 David Ripton"
__license__ = "GNU GPL v2"
"""Script to stress-test the game and train the AI by running many AI games."""
import argparse
import sys
import os
import logging
import random
from twisted.internet import reactor, utils
from twisted.python import log
from slugathon.net import config
# We never stop the server, but it seems to go down when this script does.
def start_server():
def1 = utils.getProcessOutputAndValue(sys.executable,
["-m", "slugathon.net.Server"], env=os.environ)
def1.addCallback(server_exited)
def1.addErrback(server_failed)
def server_exited((out, err, code)):
logging.info("server exited with returncode %s stderr %s" % (code, err))
def server_failed(arg):
log.err("server failed %s" % arg)
def start_game(playername, password, ai_time_limit, min_players, max_players,
num_games):
if num_games <= 0:
logging.info("finished running games")
reactor.callWhenRunning(reactor.stop)
return
num_players = random.randrange(min_players, max_players + 1)
def1 = utils.getProcessValue(sys.executable,
[
"-m", "slugathon.ai.AIClient",
"--form-game",
"--playername", playername,
"--password", password,
"--min-players", str(num_players),
"--max-players", str(num_players),
"--ai-time-limit", str(ai_time_limit),
"--game-name", "stresstest_game_%d_%d" % (os.getpid(), num_games),
],
env=os.environ)
def1.addCallback(game_exited, playername, password, ai_time_limit,
min_players, max_players, num_games - 1)
def1.addErrback(game_failed)
def game_exited(returncode, playername, password, ai_time_limit, min_players,
max_players, num_games):
logging.info("returncode %s" % returncode)
if returncode == 0:
start_game(playername, password, ai_time_limit, min_players,
max_players, num_games)
else:
reactor.stop()
def game_failed(arg):
log.err("game failed %s" % arg)
def main():
parser = argparse.ArgumentParser(prog="stresstest-slugathon")
parser.add_argument("-n", "--playername", action="store", type=str,
default="")
parser.add_argument("-a", "--password", action="store", type=str,
default="")
parser.add_argument("-s", "--start-server", action="store_true")
parser.add_argument("-g", "--num-games", action="store", type=int,
default=10000000)
parser.add_argument("--ai-time-limit", type=int,
default=config.DEFAULT_AI_TIME_LIMIT)
parser.add_argument("--min-players", action="store", type=int, default=2)
parser.add_argument("--max-players", action="store", type=int, default=6)
args = parser.parse_args()
log_observer = log.PythonLoggingObserver()
log_observer.start()
formatter = logging.Formatter(
"%(asctime)s %(filename)s %(funcName)s %(lineno)d %(message)s")
console_handler = logging.StreamHandler()
console_handler.setFormatter(formatter)
logging.getLogger().addHandler(console_handler)
logging.getLogger().setLevel(logging.DEBUG)
if args.start_server:
start_server()
start_game(args.playername, args.password, args.ai_time_limit,
args.min_players, args.max_players, args.num_games)
reactor.run()
if __name__ == "__main__":
main()
Jump to Line
Something went wrong with that request. Please try again.