#!/usr/bin/env python

import sys

from game import Game
from strategies import strategy_human, strategy_never_lose, strategy_dumb


def get_user_choice(user_input):
    choice = user_input.strip()

    if choice not in set('XxOo0'):
        print
        print "You can't play as `%s` here." % choice
        print
        print "Bye..."
        print
        sys.exit()

    user = 'O' if (choice == '0') else choice.upper()
    opponent = 'X' if (user == 'O') else 'O'

    return (user, opponent)


if __name__ == '__main__':
    print

    try:
        user_input = raw_input("Choose your side ('X' or 'O'): ")
    except (EOFError, KeyboardInterrupt):
        print
        print
        print "Bye..."
        print
        sys.exit()

    user, opponent = get_user_choice(user_input)

    strategies = {}
    strategies[user] = strategy_human
    strategies[opponent] = strategy_never_lose

    Game(strategies).play()
