forked from ParleyMarvit/KnightsDistance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SynthesizedChess
52 lines (45 loc) · 1.66 KB
/
SynthesizedChess
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
def make_board(num_rows, num_columns):
board = []
for i in range(num_rows):
board.append([])
for j in range(num_columns):
board[i].append(' ')
return board
def print_row(row, row_number):
row_text = str(row_number)
if row_number < 10:
row_text += ' '
row_text += '│ '
for item in row:
row_text += str(item) + ' │ '
print(row_text)
def print_board(board):
print(' ┌───' + '┬───' * (len(board[0]) - 1) + '┐')
for i in range(len(board) - 1):
print_row(board[i], len(board) - i)
print(' ├───' + '┼───' * (len(board[i]) - 1) + '┤')
print_row(board[-1], 1)
print(' └───' + '┴───' * (len(board[-1]) - 1) + '┘')
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
column_letters = ' '
for i in range(len(board[-1])):
column_letters += ' ' + alphabet[i]
print(column_letters)
def get_legal_moves(board, position):
legal_moves = []
for row in range(len(board)):
for sq in range(len(board[row])):
# Every space that is exactly 1 row and 2 columns or 2 rows and 1
# column away from the knight.
if (abs(row - position[0]) + abs(sq - position[1]) == 3
and abs(row - position[0]) < 3 and abs(sq - position[1]) < 3
and -1 not in [row, sq] and len(board) not in [row, sq]):
legal_moves.append([row, sq])
return legal_moves
length = 21
board = make_board(length, length)
position = [length//2, length//2]
len_1 = get_legal_moves(board, position)
for sq in len_1:
board[sq[0]][sq[1]] = '1'
print_board(board)