-
Notifications
You must be signed in to change notification settings - Fork 1
/
main01.py
105 lines (86 loc) · 3.33 KB
/
main01.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
from array import *
from chess_move import ChessMove
'''
Move to one space at a time.
'''
#define pieces
pieces = {
"bpawn":1,"brook":2,'bknight':3,'bbishop':4,'bqueen':5,'bking':6,
'wpawn':7,'wrook':8,'wknight':9,'wbishop':10,'wqueen':11,'wking':12
}
#create reference for board letters and numbers so actual numbers on the board(1-8) work with array(0-7)
reference = {
'a' : 0 , 'b' : 1 , 'c' : 2 , 'd': 3 , 'e': 4 , 'f': 5 , 'g': 6 , 'h': 7,
'1': 0 , '2': 1 ,'3': 2 ,'4': 3 ,'5': 4 ,'6' : 5 ,'7': 6 ,'8': 7
}
current_position = [0,0]
move_position = [0,0]
'''
create board array
letters go left to right starting from a
numbers go down staring from 1
'''
board = [[8,9,10,11,12,10,9,8], \
[7,7,7,7,7,7,7,7],\
[0,0,0,0,0,0,0,0],\
[0,0,0,0,0,0,0,0],\
[0,0,0,0,0,0,0,0],\
[0,0,0,0,0,0,0,0],\
[1,1,1,1,1,1,1,1],\
[2,3,4,5,6,4,3,2]]
def take_piece(current, move_position):
print("take piece", current, board[move_position[1]][move_position[0]])
if current > 6 and board[move_position[1]][move_position[0]] < 7 and current != 0 and board[move_position[1]][move_position[0]] != 0:
return True
elif current < 7 and board[move_position[1]][move_position[0]] > 6 and current != 0 and board[move_position[1]][move_position[0]] != 0:
return True
else:
return False
def print_board():
for r in board:
for c in r:
print(c,end = " ")
print()
move = ChessMove()
while (True):
moveTo = input("enter ending position (lower case letters) and o or f for electromagnet ") #intake ending position and split into letter and number
# print(moveTo)
temp = 0
knight = False
try:
deltaX = reference[moveTo[0]] - current_position[0]
deltaY = reference[moveTo[1]] - current_position[1]
print(deltaX, deltaY)
if deltaX > 0:
directionX = "positive"
move_position[0] += deltaX
else:
directionX = "negative"
move_position[0] += deltaX # negative number
if deltaY > 0:
directionY = "positive"
move_position[1] += deltaY
else:
directionY = "negative"
move_position[1] += deltaY # negative number
if moveTo[2] == "o":
magnet = "on"
temp = board[current_position[1]][current_position[0]]
board[current_position[1]][current_position[0]] = 0
if temp == 3 or temp == 9:
knight = True
else:
knight = False
else:
magnet = "off"
if take_piece(temp,move_position) and magnet == "on":
move.take_piece(abs(deltaX), abs(deltaY), directionX, directionY, move_position)
print(current_position, move_position, abs(deltaX), abs(deltaY), directionX, directionY, magnet, knight, board[current_position[1]][current_position[0]])
move.move_steppers_uneven(abs(deltaX), abs(deltaY), directionX, directionY, magnet, knight)
current_position[0] = move_position[0]
current_position[1] = move_position[1]
if moveTo[2] == "o":
board[current_position[1]][current_position[0]] = temp
print_board()
except:
print("invalid entry")