-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.py
65 lines (59 loc) · 2.04 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
63
64
65
import engine as ce
import chess as ch
class Main:
def __init__(self, board=ch.Board):
self.board=board
#play human move
def playHumanMove(self):
try:
print(self.board.legal_moves)
print("""To undo your last move, type "undo".""")
#get human move
play = input("Your move: ")
if (play=="undo"):
self.board.pop()
self.board.pop()
self.playHumanMove()
return
self.board.push_san(play)
except:
self.playHumanMove()
#play engine move
def playEngineMove(self, maxDepth, color):
engine = ce.Engine(self.board, maxDepth, color)
self.board.push(engine.getBestMove())
#start a game
def startGame(self):
#get human player's color
color=None
while(color!="b" and color!="w"):
color = input("""Play as (type "b" or "w"): """)
maxDepth=None
while(isinstance(maxDepth, int)==False):
maxDepth = int(input("""Choose depth: """))
if color=="b":
while (self.board.is_checkmate()==False):
print("The engine is thinking...")
self.playEngineMove(maxDepth, ch.WHITE)
print(self.board)
self.playHumanMove()
print(self.board)
print(self.board)
print(self.board.outcome())
elif color=="w":
while (self.board.is_checkmate()==False):
print(self.board)
self.playHumanMove()
print(self.board)
print("The engine is thinking...")
self.playEngineMove(maxDepth, ch.BLACK)
print(self.board)
print(self.board.outcome())
#reset the board
self.board.reset
#start another game
self.startGame()
#create an instance and start a game
newBoard= ch.Board()
game = Main(newBoard)
bruh = game.startGame()