2020-12-24 06:10:53 +01:00
|
|
|
import sys, getopt
|
2020-12-28 22:39:37 +01:00
|
|
|
from TicTacToe import TicTacToe
|
2020-12-20 21:46:22 +01:00
|
|
|
|
2021-01-09 22:05:47 +01:00
|
|
|
games = None
|
|
|
|
player_x = None
|
|
|
|
player_o = None
|
|
|
|
|
2020-12-25 04:20:54 +01:00
|
|
|
try:
|
2021-01-09 22:05:47 +01:00
|
|
|
opts, args = getopt.getopt(sys.argv[1:], "n:", ["games="])
|
2020-12-25 04:20:54 +01:00
|
|
|
except getopt.GetoptError:
|
2021-01-09 22:05:47 +01:00
|
|
|
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
|
|
|
|
''')
|
2020-12-25 04:45:14 +01:00
|
|
|
sys.exit(2)
|
|
|
|
|
2021-01-09 22:05:47 +01:00
|
|
|
if((len(sys.argv) != 1) and (sys.argv[-2] in ("random", "human")) and (sys.argv[-1] in ("random", "human"))):
|
2020-12-25 04:45:14 +01:00
|
|
|
for opt, arg in opts:
|
|
|
|
if opt in ("-n", "--numberofrounds"):
|
2021-01-09 22:05:47 +01:00
|
|
|
games = arg
|
|
|
|
player_x = sys.argv[-2]
|
|
|
|
player_o = sys.argv[-1]
|
2020-12-25 04:45:14 +01:00
|
|
|
else:
|
2021-01-09 22:05:47 +01:00
|
|
|
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
|
|
|
|
''')
|
2020-12-25 04:20:54 +01:00
|
|
|
sys.exit()
|
2020-12-20 02:13:38 +01:00
|
|
|
|
2021-01-09 22:05:47 +01:00
|
|
|
game = TicTacToe(player_x, player_o)
|
|
|
|
for x in range(0, int(games)):
|
2020-12-25 04:59:32 +01:00
|
|
|
game.run()
|