#!/usr/bin/env python

"""A script to run the Axelrod tournament.

The code for strategies is present in `axelrod/strategies`.
"""

from __future__ import division
import argparse
from axelrod import run_tournaments, setup_logging

if __name__ == "__main__":

    parser = argparse.ArgumentParser(
        description="Run a recreation of Axelrod's tournament")

    parser.add_argument(
        '-l', '--logging',
        type=str,
        default='console',
        dest="logging_destination",
        help='logging (none, console or file)')

    parser.add_argument(
        '-v', '--verbosity',
        type=str,
        default='INFO',
        help='Logging level. DEBUG, INFO, ERROR or CRITICAL')

    parser.add_argument(
        '-t',
        '--turns',
        type=int,
        default=200,
        help='turns per pair')

    parser.add_argument(
        '-r', '--repetitions',
        type=int,
        default=10,
        help='round-robin repetitions')

    parser.add_argument(
        '-o', '--output_directory',
        default='./',
        help='output directory')

    parser.add_argument(
        '--xb',
        "--exclude-basic",
        action='store_true',
        dest="exclude_basic",
        help='exclude basic strategies plot')

    parser.add_argument(
        '--xs', "--exclude-ordinary",
        action='store_true',
        dest="exclude_ordinary",
        help='exclude ordinary strategies plot')

    parser.add_argument(
        '--xc', "--exclude-cheating",
        action='store_true',
        dest="exclude_cheating",
        help='exclude cheating strategies plot')

    parser.add_argument(
        '--xa', "--exclude-combined",
        action='store_true',
        dest="exclude_combined",
        help='exclude combined strategies plot')

    parser.add_argument(
        '--ne', "--no-ecological",
        action='store_true',
        dest="no_ecological",
        help='no ecological variant')

    parser.add_argument(
        '-p', '--processes',
        type=int,
        default=None,
        help='Number of parallel processes to spawn. 0 uses cpu count.')

    parser.add_argument(
        '--rc', "--rebuild-cache",
        action='store_true',
        dest="rebuild_cache",
        help='rebuild cache and save to file')

    parser.add_argument(
        '-c', '--cache_file',
        type=str,
        default='./cache.txt',
        help='Path to cache file')

    parser.add_argument(
        '-n', '--noise',
        type=float,
        default=0,
        help='Noise level')

    parser.add_argument(
        '-i', '--image_format',
        type=str,
        default="svg",
        help='Image format for matplotlib, e.g. svg, jpeg, png')

    args = parser.parse_args()

    if all([args.exclude_basic,
            args.exclude_ordinary,
            args.exclude_cheating,
            args.exclude_combined]):
        print("You've excluded everything - nothing for me to do")
    else:
        setup_logging(args.logging_destination, args.verbosity)
        # Unravel argparse Namespace object to python keyword arguments.
        kwargs = vars(args)
        del kwargs["logging_destination"]
        del kwargs["verbosity"]
        run_tournaments(**kwargs)
