-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBishopModule.py
112 lines (72 loc) · 2.61 KB
/
BishopModule.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
109
110
111
112
#Author: NWANKWO CHUKWUEBUKA JUSTIN
# Date: 5/26/2016
"""
Bishop moves:
"""
class Bishop:
def __init__(self, row, col, player_num):
self.row = row
self.col = col
self.symbol = 'B'
self.player_num = player_num
def get_position(self):
return (self.row, self.col)
def get_symbol(self):
return self.symbol
def get_number(self):
return self.player_num
def move(self, to_row, to_col):
self.row = to_row
self.col = to_col
def is_valid(self, piece_positions, from_row, from_col, to_row, to_col):
if((from_row == to_row) or (from_col == to_col)):
return False
if(from_row < to_row):
start_row_index = from_row + 1
stop_row_index = to_row
start_col_index = from_col
stop_col_index = to_col
is_from_row = 1
else:
piece, num = piece_positions.get_piece(to_row, to_col)
if(num != self.player_num):
start_row_index = to_row + 1
stop_row_index = from_row
start_col_index = to_col
stop_col_index = from_col
is_from_row = 0
else:
return False
if(start_col_index < stop_col_index):
col_increment = 1
else:
col_increment = -1
start_col_index += col_increment
break_reached = 0
while(start_row_index <= stop_row_index):
piece, num = piece_positions.get_piece(start_row_index, start_col_index)
if(num != '-' or start_col_index == stop_col_index):
break_reached = 1
break
start_row_index += 1
start_col_index += col_increment
if(not break_reached):
start_row_index -= 1
start_col_index += (-col_increment)
if(start_row_index != stop_row_index):
return False
if(start_col_index != stop_col_index):
return False
else:
if(num == '-'):
return True
if(is_from_row):
if(num != self.player_num):
return True
else:
return False
else:
if(num == self.player_num):
return True
else:
return False