Repository navigation
Expand file tree
/
Copy pathapp_smallBoard.py
More file actions
64 lines (55 loc) · 2.23 KB
/
Copy pathapp_smallBoard.py
File metadata and controls
64 lines (55 loc) · 2.23 KB
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
from logic.game import chessGame
from engine.engine import chessEngine
from pickle import dump, load
import numpy as np
from components.pieces.emptyPiece import emptyPiece
from components.pieces.knight import Knight
from components.pieces.bishop import Bishop
from components.pieces.queen import Queen
from components.pieces.king import King
from components.pieces.rook import Rook
from components.pieces.pawn import Pawn
# small board 4x4 with only king and pawns and king on corner
def main():
game = chessGame()
game.board.setBoard(
np.array([
[King("black", (0, 0)), emptyPiece(), emptyPiece(), emptyPiece(), emptyPiece()],
[Pawn("black", (1, 0)), Pawn("black", (1, 1)), Pawn("black", (1, 2)), Pawn("black", (1, 3)), Pawn("black", (1, 4))],
[emptyPiece(), emptyPiece(), emptyPiece(), emptyPiece(), emptyPiece()],
[Pawn("white", (3, 0)), Pawn("white", (3, 1)), Pawn("white", (3, 2)), Pawn("white", (3, 3)), Pawn("white", (3, 4))],
[emptyPiece(), emptyPiece(), emptyPiece(), emptyPiece(), King("white", (4, 4))]
])
)
engine = chessEngine(n_squares=25, game=game)
# engine.trainAgainstSelf(10, depth=2)
# with open("smallBoardEngine.pkl", "wb") as f:
# dump(engine, f)
game2 = chessGame()
game2.board.setBoard(
np.array([
[King("black", (0, 0)), emptyPiece(), emptyPiece(), emptyPiece(), emptyPiece()],
[Pawn("black", (1, 0)), Pawn("black", (1, 1)), Pawn("black", (1, 2)), Pawn("black", (1, 3)), Pawn("black", (1, 4))],
[emptyPiece(), emptyPiece(), emptyPiece(), emptyPiece(), emptyPiece()],
[Pawn("white", (3, 0)), Pawn("white", (3, 1)), Pawn("white", (3, 2)), Pawn("white", (3, 3)), Pawn("white", (3, 4))],
[emptyPiece(), emptyPiece(), emptyPiece(), emptyPiece(), King("white", (4, 4))]
])
)
while not game2.game_over:
game2.showBoard()
x1 = int(input("x1: "))
y1 = int(input("y1: "))
x2 = int(input("x2: "))
y2 = int(input("y2: "))
game2.makeMove(((x1, y1), (x2, y2)))
if game2.game_over:
print(game2.winner)
break
bestMove = engine.getBestMove(game2, "black", depth=3)
game2.makeMove(bestMove)
game2.showBoard()
if game2.game_over:
print(game2.winner)
break
if __name__ == "__main__":
main()