-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchessboard.py
More file actions
executable file
·52 lines (40 loc) · 1.02 KB
/
chessboard.py
File metadata and controls
executable file
·52 lines (40 loc) · 1.02 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
#/usr/bin/python
#-*- coding:utf-8 -*-
def ChessBoard(tr, tc, dr, dc, size):
global Board
global tile
if size == 1: return
tile += 1
t, s = tile, size/2
if dr<tr+s and dc<tc+s:
ChessBoard(tr, tc, dr, dc, s)
else:
Board[tr+s-1][tc+s-1] = t
ChessBoard(tr, tc, tr+s-1, tc+s-1, s)
if dr<tr+s and dc>=tc+s:
ChessBoard(tr, tc+s, dr, dc, s)
else:
Board[tr+s-1][tc+s] = t
ChessBoard(tr, tc+s, tr+s-1, tc+s, s)
if dr>=tr+s and dc<tc+s:
ChessBoard(tr+s, tc, dr, dc, s)
else:
Board[tr+s][tc+s-1] = t
ChessBoard(tr+s, tc, tr+s, tc+s-1, s)
if dr>=tr+s and dc>=tc+s:
ChessBoard(tr+s, tc+s, dr, dc, s)
else:
Board[tr+s][tc+s] = t
ChessBoard(tr+s, tc+s, tr+s, tc+s, s)
def printBoard():
global Board
for i in range(len(Board)):
for item in Board[i]:
print item,'\t',
print '\r'
if __name__ == "__main__":
SIZE, dr, dc = input("size:"), input("dr:"), input("dc:")
Board = [[0 for i in range(SIZE)] for i in range(SIZE)]
tile = 0
ChessBoard(0, 0, dr, dc, SIZE)
printBoard()