-
Notifications
You must be signed in to change notification settings - Fork 0
/
playBattleship.py
47 lines (37 loc) · 1.14 KB
/
playBattleship.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# from battleship import BattleShip
from game import Game
if __name__ == "__main__":
while True:
try:
boardSize = input("Enter Board Size: ")
boardSize = int(boardSize)
except ValueError:
print("Please enter a valid integer input")
continue
else:
if boardSize < 5:
print("Please enter a larger Board Size")
continue
else:
break
player1 = input("Enter Player 1 Name (Press Enter to play as CPU): ")
player2 = input("Enter Player 2 Name (Press Enter to play as CPU): ")
if not player1:
game = Game(boardSize, "CPU1", "CPU2")
elif not player2:
game = Game(boardSize, player1, "CPU1")
else:
game = Game(boardSize, player1, player2)
game.playGame()
# Uncomment to play multiple CPU games in a go
# allGames = []
# for i in range(100):
# print("Game : ", i)
# game = Game(10, "CPU1", "CPU2")
# moves = game.playGame()
# allGames.append(moves)
# import matplotlib.pyplot as plt
# plt.xlabel('Number of Moves')
# plt.ylabel('Count')
# plt.hist(allGames, facecolor='blue', edgecolor='black',linewidth=1.2)
# plt.show()