-
Notifications
You must be signed in to change notification settings - Fork 0
/
pos_generator.py
65 lines (57 loc) · 2.29 KB
/
pos_generator.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
from chess import Board, Piece
import random
def generate_kxk():
board = Board()
while True:
board.clear()
positions = random.sample(range(64), 3)
board.set_piece_at(positions[0], Piece.from_symbol("K"))
board.set_piece_at(
positions[1], Piece.from_symbol(random.choice(["Q", "R", "P"]))
)
# board.set_piece_at(positions[1], Piece.from_symbol('Q'))
board.set_piece_at(positions[2], Piece.from_symbol("k"))
if board.is_valid():
return board
def generate_kqk():
board = Board()
while True:
board.clear()
positions = random.sample(range(64), 3)
bk_pos = positions[2]
if (bk_pos & 7) in [0, 7] or (bk_pos >> 3) in [0, 7]:
wk_pos = positions[0]
dist = abs((bk_pos & 7) - (wk_pos & 7)) + abs((bk_pos >> 3) - (wk_pos >> 3))
if dist == 2:
board.set_piece_at(positions[0], Piece.from_symbol("K"))
board.set_piece_at(positions[1], Piece.from_symbol("Q"))
board.set_piece_at(positions[2], Piece.from_symbol("k"))
if board.is_valid():
return board
def generate_krk():
board = Board()
while True:
board.clear()
positions = random.sample(range(64), 3)
bk_pos = positions[2]
if (bk_pos & 7) in [0, 7] or (bk_pos >> 3) in [0, 7]:
wk_pos = positions[0]
dist = abs((bk_pos & 7) - (wk_pos & 7)) + abs((bk_pos >> 3) - (wk_pos >> 3))
if dist == 2:
board.set_piece_at(positions[0], Piece.from_symbol("K"))
board.set_piece_at(positions[1], Piece.from_symbol("R"))
board.set_piece_at(positions[2], Piece.from_symbol("k"))
if board.is_valid():
return board
def generate_kqkr():
board = Board()
while True:
board.clear()
positions = random.sample(range(64), 4)
while True:
board.set_piece_at(positions[0], Piece.from_symbol("K"))
board.set_piece_at(positions[1], Piece.from_symbol("Q"))
board.set_piece_at(positions[2], Piece.from_symbol("k"))
board.set_piece_at(positions[3], Piece.from_symbol("r"))
if board.is_valid():
return board