asaaaaas
This commit is contained in:
parent
b8dcadbeb3
commit
17ebde7fab
19
main.py
19
main.py
@ -21,18 +21,18 @@ class TicTacToe:
|
|||||||
if self.board.is_win(self.player1.token):
|
if self.board.is_win(self.player1.token):
|
||||||
self.board.print()
|
self.board.print()
|
||||||
if len(self.board.empty_fields) == 0:
|
if len(self.board.empty_fields) == 0:
|
||||||
print("It's a draw.")
|
print("It's a draw.\n")
|
||||||
else:
|
else:
|
||||||
print(self.player1.name + " has won.")
|
print(self.player1.name + " has won.\n")
|
||||||
break
|
break
|
||||||
|
|
||||||
self.board.make_move(self.player2.token, self.player2.choose_random_field(self.board.empty_fields))
|
self.board.make_move(self.player2.token, self.player2.choose_random_field(self.board.empty_fields))
|
||||||
if self.board.is_win(self.player2.token):
|
if self.board.is_win(self.player2.token):
|
||||||
self.board.print()
|
self.board.print()
|
||||||
if len(self.board.empty_fields) == 0:
|
if len(self.board.empty_fields) == 0:
|
||||||
print("It's a draw.")
|
print("It's a draw.\n")
|
||||||
else:
|
else:
|
||||||
print(self.player2.name + " has won.")
|
print(self.player2.name + " has won.\n")
|
||||||
break
|
break
|
||||||
|
|
||||||
class Board:
|
class Board:
|
||||||
@ -83,11 +83,16 @@ number_of_rounds = None
|
|||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:], "n:", ["numberofrounds="])
|
opts, args = getopt.getopt(sys.argv[1:], "n:", ["numberofrounds="])
|
||||||
except getopt.GetoptError:
|
except getopt.GetoptError:
|
||||||
|
print("main.py -n <numberofrounds>")
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
if(len(sys.argv) != 1):
|
||||||
|
for opt, arg in opts:
|
||||||
|
if opt in ("-n", "--numberofrounds"):
|
||||||
|
number_of_rounds = arg
|
||||||
|
else:
|
||||||
print("main.py -n <numberofrounds>")
|
print("main.py -n <numberofrounds>")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
for opt, arg in opts:
|
|
||||||
if opt in ("-n", "--numberofrounds"):
|
|
||||||
number_of_rounds = arg
|
|
||||||
|
|
||||||
game = TicTacToe()
|
game = TicTacToe()
|
||||||
for x in range(0, int(number_of_rounds)):
|
for x in range(0, int(number_of_rounds)):
|
||||||
|
Loading…
Reference in New Issue
Block a user