-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathkon.py
More file actions
executable file
·109 lines (96 loc) · 3.26 KB
/
kon.py
File metadata and controls
executable file
·109 lines (96 loc) · 3.26 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
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
#!/usr/bin/env python
import sys, random
desired_id = 0
free_fields = []
starting_position = [' ']*8
def show_usage():
print "Usage: " + sys.argv[0] + " [game id]"
print "\twhere id needs to have a value between 0 and 959;"
print "\tif id is omitted, a random game will be choosen"
sys.exit(1)
def update_free_fields():
global free_fields
free_fields = [] # get an array of indices of free fields
for i in range(0,8):
if (starting_position[i] == ' '):
free_fields.append(i)
if len(sys.argv) > 2: # too many arguments?
show_usage()
elif len(sys.argv) == 2: # id has been supplied by user?
try:
desired_id = int(sys.argv[1]);
if (desired_id < 0) or (desired_id > 959): # check range
show_usage();
except ValueError:
show_usage()
else: # no id supplied, generate number by random
random.seed()
desired_id = random.randint(0, 959)
# okay, we have our desired id now, start calculating ;-)
print "Game #" + str(desired_id)
# R - Rook
# N - Knight
# B - Bishop
# Q - Queen
# K - King
# P - Pawn (not that important)
#==================== place first bishop (on bright square) ====================
#print "desired_id:", desired_id
bishop1_pos = desired_id % 4
desired_id /= 4
starting_position[1 + 2*bishop1_pos] = 'B'
#print "desired_id:", desired_id, "remainder:", bishop1_pos
#print starting_position
#==================== place second bishop (on dark square) =====================
bishop2_pos = desired_id % 4
desired_id /= 4
starting_position[0 + 2*bishop2_pos] = 'B'
#print "desired_id:", desired_id, "remainder:", bishop2_pos
#print starting_position
#================================ place queen ==================================
update_free_fields()
queen_pos = desired_id % 6
desired_id /= 6
starting_position[free_fields[queen_pos]] = 'Q'
#print "desired_id:", desired_id, "remainder:", queen_pos
#print starting_position
#================================ place knights ================================
update_free_fields()
knight_pos = desired_id
if (knight_pos == 0):
starting_position[free_fields[0]] = 'N';
starting_position[free_fields[1]] = 'N';
elif (knight_pos == 1):
starting_position[free_fields[0]] = 'N';
starting_position[free_fields[2]] = 'N';
elif (knight_pos == 2):
starting_position[free_fields[0]] = 'N';
starting_position[free_fields[3]] = 'N';
elif (knight_pos == 3):
starting_position[free_fields[0]] = 'N';
starting_position[free_fields[4]] = 'N';
elif (knight_pos == 4):
starting_position[free_fields[1]] = 'N';
starting_position[free_fields[2]] = 'N';
elif (knight_pos == 5):
starting_position[free_fields[1]] = 'N';
starting_position[free_fields[3]] = 'N';
elif (knight_pos == 6):
starting_position[free_fields[1]] = 'N';
starting_position[free_fields[4]] = 'N';
elif (knight_pos == 7):
starting_position[free_fields[2]] = 'N';
starting_position[free_fields[3]] = 'N';
elif (knight_pos == 8):
starting_position[free_fields[2]] = 'N';
starting_position[free_fields[4]] = 'N';
elif (knight_pos == 9):
starting_position[free_fields[3]] = 'N';
starting_position[free_fields[4]] = 'N';
#============================= place rooks and king ============================
update_free_fields()
starting_position[free_fields[0]] = 'R'
starting_position[free_fields[1]] = 'K'
starting_position[free_fields[2]] = 'R'
#print free_fields
print starting_position