Ejemplo n.º 1
0
def main(bot=None):
    # parse_args_and_set_up_settings()
    bot_tracker.bot = bot
    if bot_tracker.bot.first_time:
        set_up_logging()
        bot_tracker.bot.first_time = False
    connect_and_play()
Ejemplo n.º 2
0
def parse_args_and_start_reproducer():
    parser = OptionParser()

    parser.add_option('-o', '--online_log',
                      type='string',
                      help='Tenhou log with specified player and round number. '
                           'Example: http://tenhou.net/0/?log=2017041516gm-0089-0000-23b4752d&tw=3&ts=2')

    parser.add_option('-l', '--local_log',
                      type='string',
                      help='Path to local log file')

    parser.add_option('-d', '--dry_run',
                      action='store_true',
                      default=False,
                      help='Special option for tenhou log reproducer. '
                           'If true, it will print all available tags in the round')

    parser.add_option('-t', '--tag',
                      type='string',
                      help='Special option for tenhou log reproducer. It indicates where to stop parse round tags')

    opts, _ = parser.parse_args()

    if not opts.online_log and not opts.local_log:
        print('Please, set -o or -l option')
        return

    if opts.online_log and not opts.dry_run and not opts.tag:
        print('Please, set -t for real run of the online log')
        return

    if opts.online_log:
        if '?' not in opts.online_log and '&' not in opts.online_log:
            print('Wrong tenhou log format, please provide log link with player position and round number')
            return

        reproducer = TenhouLogReproducer(opts.online_log, opts.tag)
        reproducer.reproduce(opts.dry_run)
    else:
        set_up_logging()

        client = TenhouClient(SocketMock(opts.local_log))
        try:
            client.connect()
            client.authenticate()
            client.start_game()
        except (Exception, KeyboardInterrupt) as e:
            logger.exception('', exc_info=e)
            client.end_game()
def parse_args_and_start_reproducer():
    parser = OptionParser()

    parser.add_option('-o', '--online_log',
                      type='string',
                      help='Tenhou log with specified player and round number. '
                           'Example: http://tenhou.net/0/?log=2017041516gm-0089-0000-23b4752d&tw=3&ts=2')

    parser.add_option('-l', '--local_log',
                      type='string',
                      help='Path to local log file')

    parser.add_option('-d', '--dry_run',
                      action='store_true',
                      default=False,
                      help='Special option for tenhou log reproducer. '
                           'If true, it will print all available tags in the round')

    parser.add_option('-t', '--tag',
                      type='string',
                      help='Special option for tenhou log reproducer. It indicates where to stop parse round tags')

    opts, _ = parser.parse_args()

    if not opts.online_log and not opts.local_log:
        print('Please, set -o or -l option')
        return

    if opts.online_log and not opts.dry_run and not opts.tag:
        print('Please, set -t for real run of the online log')
        return

    if opts.online_log:
        if '?' not in opts.online_log and '&' not in opts.online_log:
            print('Wrong tenhou log format, please provide log link with player position and round number')
            return

        reproducer = TenhouLogReproducer(opts.online_log, opts.tag)
        reproducer.reproduce(opts.dry_run)
    else:
        set_up_logging(save_to_file=False)

        client = TenhouClient(SocketMock(opts.local_log))
        try:
            client.connect()
            client.authenticate()
            client.start_game()
        except (Exception, KeyboardInterrupt) as e:
            logger.exception('', exc_info=e)
            client.end_game()
Ejemplo n.º 4
0
    def __init__(self, bot_config, print_logs, replay_name, game_count):
        super().__init__(bot_config)
        self.id = make_random_letters_and_digit_string()
        self.player.name = bot_config.name

        if print_logs:
            settings.LOG_PREFIX = self.player.name
            logger = set_up_logging(
                save_to_file=True, print_to_console=False, logger_name=self.player.name + str(game_count)
            )
            logger.info(f"Replay name: {replay_name}")
            self.player.init_logger(logger)
Ejemplo n.º 5
0
    def get_next_cost_dict(self, params_dict):

        #Get parameters from the dictionary provided by the learner
        print('\n\n\n\n\n')
        params = params_dict['params']

        #start a game
        parse_args_and_set_up_settings()
        handlers = set_up_logging()
        cost, bad = connect_and_play(params)
        terminate_logging(handlers)
        #keep the uncertainty relatively large, because of the random nature of mahjong
        uncer = 5

        #The cost, uncertainty and bad boolean must all be returned as a dictionary
        #You can include other variables you want to record as well if you want
        cost_dict = {'cost': cost, 'uncer': uncer, 'bad': bad}
        return cost_dict
Ejemplo n.º 6
0
def connect_and_play():
    logger = set_up_logging()

    client = TenhouClient(logger)
    client.connect()

    try:
        was_auth = client.authenticate()

        if was_auth:
            client.start_game()
        else:
            client.end_game()
    except KeyboardInterrupt:
        logger.info("Ending the game...")
        client.end_game()
    except Exception as e:
        logger.exception("Unexpected exception", exc_info=e)
        logger.info("Ending the game...")
        client.end_game(False)
Ejemplo n.º 7
0
    def run(self):
        logger = set_up_logging()

        client = TenhouClient(logger, bot_config=self.bot_config)

        for _ in range(self.opt.num_games):
            client.connect()

            try:
                was_auth = client.authenticate()

                if was_auth:
                    client.start_game()
                else:
                    client.end_game()
            except KeyboardInterrupt:
                logger.info("Ending the game...")
                client.end_game()
            except Exception as e:
                logger.exception("Unexpected exception", exc_info=e)
                logger.info("Ending the game...")
                client.end_game(False)

        client.table.player.ai.write_buffer()
Ejemplo n.º 8
0
def main():
    parse_args_and_set_up_settings()
    set_up_logging()

    connect_and_play()
Ejemplo n.º 9
0
def main():
    parse_args_and_set_up_settings()
    set_up_logging()

    connect_and_play()
Ejemplo n.º 10
0
__author__ = "jonathan"

from utils import configuration
from utils import logger
from worker import download
from worker import importer

log = logger.set_up_logging(file_name="boundaryline.log", console_verbosity="info", file_verbosity="debug")
config = configuration.load("config.ini")

downloader = download.Downloader(config, log)
source_zip = downloader.start()

boundaryline_importer = importer.Importer(config, log)
boundaryline_importer.start(source_zip)
Ejemplo n.º 11
0
def main():
    parse_args_and_set_up_settings()
    set_up_logging()

    for i in range(500):
        connect_and_play()
Ejemplo n.º 12
0
def main():
    logger = set_up_logging(save_to_file=False)
    parse_args_and_start_reproducer(logger)