-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
108 lines (83 loc) · 2.63 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import game
import pawn
import bishop
import knight
import queen
import rook
import king
import gui
from tkinter import NW
alpha = ['H','G','F','E','D','C','B','A','X']
alpha2 = ['A','B','C','D','E','F','G','H']
game = game.Game()
#team white
Wpawn1 = pawn.Pawn('H2','white',game)
Wpawn2 = pawn.Pawn('G2','white',game)
Wpawn3 = pawn.Pawn('F2','white',game)
Wpawn4 = pawn.Pawn('E2','white',game)
Wpawn5 = pawn.Pawn('D2','white',game)
Wpawn6 = pawn.Pawn('C2','white',game)
Wpawn7 = pawn.Pawn('B2','white',game)
Wpawn8 = pawn.Pawn('A2','white',game)
Wknight1 = knight.Knight("B1","white",game)
Wknight2 = knight.Knight("G1","white",game)
Wbishop1 = bishop.Bishop("F1","white",game)
Wbishop2 = bishop.Bishop("C1","white",game)
Wrook1 = rook.Rook("H1","white",game)
Wrook2 = rook.Rook("A1","white",game)
Wking = king.King("D1","white",game)
Wqueen = queen.Queen("E1","white",game)
#team black
Bpawn1 = pawn.Pawn('H7','black',game)
Bpawn2 = pawn.Pawn('G7','black',game)
Bpawn3 = pawn.Pawn('F7','black',game)
Bpawn4 = pawn.Pawn('E7','black',game)
Bpawn5 = pawn.Pawn('D7','black',game)
Bpawn6 = pawn.Pawn('C7','black',game)
Bpawn7 = pawn.Pawn('B7','black',game)
Bpawn8 = pawn.Pawn('A7','black',game)
Bknight1 = knight.Knight("G8","black",game)
Bknight2 = knight.Knight("B8","black",game)
Bbishop1 = bishop.Bishop("F8","black",game)
Bbishop2 = bishop.Bishop("C8","black",game)
Brook1 = rook.Rook("H8","black",game)
Brook2 = rook.Rook("A8","black",game)
Bking = king.King("D8","black",game)
Bqueen = queen.Queen("E8","black",game)
def undo(event):
game.undo(guiw)
def lgetxy(event):
try:
for i in guiw.selec_poss_seen:
guiw.canvas.delete(i)
game.left = alpha2[int(event.x/80)-1]+str(9-int(event.y/80))
assert game.board[game.left].team == game.turn
game.selec_poss = game.board[game.left].possible_moves()+game.board[game.left].possible_attacks()
guiw.selec_poss_seen = [
guiw.canvas.create_image(
gui.convert(i)[0],
gui.convert(i)[1],
image = guiw.selec_poss_im,
anchor = NW )
for i in game.selec_poss
]
except:
print('invalid selection')
def rgetxy(event):
try:
game.right = alpha2[int(event.x/80)-1]+str(9-int(event.y/80))
except:
print('error')
game.play(guiw)
for i in guiw.selec_poss_seen:
guiw.canvas.delete(i)
if game.winner != None:
print('the winner is {}'.format(game.winner))
input()
guiw = gui.Window(game)
guiw.canvas.bind('<Button-1>', lgetxy)
guiw.canvas.bind('<Button-2>', undo)
guiw.canvas.bind('<Button-3>', rgetxy)
guiw.canvas.grid()
guiw.update()
guiw.window.mainloop()