Tic-Tac-Toe/main.py

48 lines
1.1 KiB
Python

import sys, getopt
from TicTacToe import TicTacToe
games = None
player_x = None
player_o = None
try:
opts, args = getopt.getopt(sys.argv[1:], "n:", ["games="])
except getopt.GetoptError:
print('''
usage: main.py -n GAMES
player_x player_o
positional arguments:
player_x Type of the X player [human|random]
player_o Type of the O player [human|random]
optional arguments:
-n GAMES, --games GAMES
number of games to play
''')
sys.exit(2)
if((len(sys.argv) != 1) and (sys.argv[-2] in ("random", "human")) and (sys.argv[-1] in ("random", "human"))):
for opt, arg in opts:
if opt in ("-n", "--numberofrounds"):
games = arg
player_x = sys.argv[-2]
player_o = sys.argv[-1]
else:
print('''
usage: main.py -n GAMES
player_x player_o
positional arguments:
player_x Type of the X player [human|random]
player_o Type of the O player [human|random]
optional arguments:
-n GAMES, --games GAMES
number of games to play
''')
sys.exit()
game = TicTacToe(player_x, player_o)
for x in range(0, int(games)):
game.run()