Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from itertools import permutations, combinations
- def generate_positions():
- ozn = [(i, j) for j in range(1, 9) for i in range(1, 9)]
- ozn_dict = {8 * (j - 1) + i: chr(i + ord('a') - 1) + str(j) for j in range(1, 9) for i in range(1, 9)}
- p = np.zeros((64, 64, 64), dtype=int)
- q = np.zeros((64, 64, 64), dtype=int)
- m = 0
- for i in range(64):
- for j in range(64):
- for k in range(64):
- y1, x1 = divmod(i, 8)
- y2, x2 = divmod(j, 8)
- y3, x3 = divmod(k, 8)
- if i == j or i == k or j == k:
- p[i, j, k] = -2000
- elif abs(y1 - y2) <= 1 and abs(x1 - x2) <= 1:
- p[i, j, k] = -2000
- elif (y2 == y3 and (y1 != y3 or (x2 - x1) * (x2 - x3) < 0)) or \
- (x2 == x3 and (x1 != x3 or (y2 - y1) * (y2 - y3) < 0)) or \
- (y2 - y3 == x2 - x3 and (y2 - y1 != x2 - x1 or (x1 - x3) * (x1 - x2) > 0)) or \
- (y2 - y3 == x3 - x2 and (y2 - y1 != x1 - x2 or (x1 - x3) * (x1 - x2) > 0)):
- p[i, j, k] = -2000
- else:
- m += 1
- print(f"Celkem {m} pripustnych pozic pro bileho")
- n, n2, n3, n4 = 0, 0, 0, 0
- for i in range(64):
- for j in range(64):
- for k in range(64):
- y1, x1 = divmod(i, 8)
- y2, x2 = divmod(j, 8)
- y3, x3 = divmod(k, 8)
- if i == j or i == k or j == k:
- q[i, j, k] = -2000
- elif abs(y1 - y2) <= 1 and abs(x1 - x2) <= 1:
- q[i, j, k] = -2000
- else:
- sach = 0
- if (y2 == y3 and (y1 != y3 or (x2 - x1) * (x2 - x3) < 0)) or \
- (x2 == x3 and (x1 != x3 or (y2 - y1) * (y2 - y3) < 0)) or \
- (y2 - y3 == x2 - x3 and (y2 - y1 != x2 - x1 or (x1 - x3) * (x1 - x2) > 0)) or \
- (y2 - y3 == x3 - x2 and (y2 - y1 != x1 - x2 or (x1 - x3) * (x1 - x2) > 0)):
- sach = 1
- if q[i, j, k] == 0:
- tahu = 0
- for t1 in range(-1, 2):
- for t2 in range(-1, 2):
- if t1 != 0 or t2 != 0:
- x4, y4 = x2 + t1, y2 + t2
- if 0 <= x4 < 8 and 0 <= y4 < 8 and (abs(x4 - x1) > 1 or abs(y4 - y1) > 1):
- if (x4 == x3 and y4 == y3) or p[y1 * 8 + x1, y4 * 8 + x4, y3 * 8 + x3] == 0:
- tahu += 1
- if x4 == x3 and y4 == y3:
- q[i, j, k] = 332
- n4 += 1
- if tahu == 0 and sach == 1:
- q[y1 * 8 + x1, y2 * 8 + x2, y3 * 8 + x3] = -1000
- n2 += 1
- elif tahu == 0:
- q[i, j, k] = 333
- n3 += 1
- else:
- n += 1
- print(f"Celkem {n} pripustnych pozic pro cerneho")
- print(f"Celkem {n2} pozice, kde je cerny v matu")
- print(f"Celkem {n3} pozice, kde je cerny v patu")
- print(f"Celkem {n4} pozice, kde cerny muze vzit vez")
- return p, q, ozn_dict
- def main():
- pieces = ['K', 'k', 'Q', 'B']
- p, q, ozn_dict = generate_positions()
- tahy = 0
- while tahy < 500:
- tahy += 1
- n2 = 0
- if tahy % 2 != 0:
- for i in range(64):
- for j in range(64):
- for k in range(64):
- if p[i, j, k] == 0:
- y1, x1 = divmod(i, 8)
- y2, x2 = divmod(j, 8)
- y3, x3 = divmod(k, 8)
- lzemat = 0
- for t1 in range(-1, 2):
- for t2 in range(-1, 2):
- if t1 != 0 or t2 != 0:
- x4, y4 = x1 + t1, y1 + t2
- if 0 <= x4 < 8 and 0 <= y4 < 8:
- if q[y4 * 8 + x4, y2 * 8 + x2, y3 * 8 + x3] == -1001 + tahy:
- lzemat = 1
- for s1 in range(-1, 2):
- for s2 in range(-1, 2):
- if (s1 == 0 or s2 == 0 or s1 == s2 or s1 == -s2) and (s1 != 0 or s2 != 0):
- x4, y4 = x3, y3
- tahu = 1
- while tahu:
- x4 += s1
- y4 += s2
- if x4 < 0 or x4 >= 8 or y4 < 0 or y4 >= 8 or (x1 == x4 and y1 == y4):
- tahu = 0
- elif q[y1 * 8 + x1, y2 * 8 + x2, y4 * 8 + x4] == -1001 + tahy:
- lzemat = 1
- if lzemat:
- n2 += 1
- p[i, j, k] = 1000 - tahy
- else:
- for i in range(64):
- for j in range(64):
- for k in range(64):
- if q[i, j, k] == 0:
- y1, x1 = divmod(i, 8)
- y2, x2 = divmod(j, 8)
- y3, x3 = divmod(k, 8)
- lzemat = 0
- tahu = 0
- for t1 in range(-1, 2):
- for t2 in range(-1, 2):
- if t1 != 0 or t2 != 0:
- x4, y4 = x2 + t1, y2 + t2
- if 0 <= x4 < 8 and 0 <= y4 < 8 and (abs(x4 - x1) > 1 or abs(y4 - y1) > 1):
- if p[y1 * 8 + x1, y4 * 8 + x4, y3 * 8 + x3] >= 0:
- tahu += 1
- if p[y1 * 8 + x1, y4 * 8 + x4, y3 * 8 + x3] >= 1000 - tahy:
- lzemat += 1
- if lzemat == tahu:
- n2 += 1
- q[i, j, k] = -1000 + tahy
- print(f"V hloubce {tahy} nalezeno {n2} novych reseni")
- if n2 == 0:
- break
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement