Tic-Tac-Toe/main.py

48 lines
1.1 KiB
Python
Raw Permalink Normal View History

2020-12-24 06:10:53 +01:00
import sys, getopt
from TicTacToe import TicTacToe
2020-12-20 21:46:22 +01:00
games = None
player_x = None
player_o = None
2020-12-25 04:20:54 +01:00
try:
opts, args = getopt.getopt(sys.argv[1:], "n:", ["games="])
2020-12-25 04:20:54 +01:00
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
''')
2020-12-25 04:45:14 +01:00
sys.exit(2)
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"):
games = arg
player_x = sys.argv[-2]
player_o = sys.argv[-1]
2020-12-25 04:45:14 +01:00
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
''')
2020-12-25 04:20:54 +01:00
sys.exit()
2020-12-20 02:13:38 +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()