-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
62 lines (41 loc) · 1.5 KB
/
main.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from time import time
import mancala
import minimax
def play():
board = mancala.Board()
board.show()
firstInput = input("Going first? (y/n): ").lower()
if "y" in firstInput:
playing = True
else:
playing = False
while not board.noMoreMoves():
if playing:
print("\nSearching Minimax Tree w/ Alpha-Beta Pruning...")
t = time()
score, sequence = minimax.minimaxAlphaBeta(board)
print(f"Finished calculations (time {(time() - t) * 1000:.2f}ms).")
print(f"\nYour best move this turn: pot(s) {', then '.join([str(move + 1) for move in sequence[0]])}. ")
for move in sequence[0]:
playing, takeOpposite = board.playerMove(move)
else:
opponentMove = input("Enter the move your opponent made: ")
notPlaying, takeOpposite = board.opponentMove(int(opponentMove) - 1)
playing = not notPlaying
if notPlaying:
print("[GO AGAIN]")
if takeOpposite:
print("[TAKE OPPOSITE STONES]")
board.show()
if board.heuristicScore() > 0:
print(f"I win ({board.state[6]} to {board.state[13]}! ")
elif board.heuristicScore() < 0:
print(f"Opponent wins ({board.state[13]} to {board.state[6]}! ")
# mancala.runAllTests()
print("Game self-tests successful.")
while True:
play()
again = input("Play again? (y/n): ").lower()
if "n" in again:
break
print("Program ended.")