Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # python 3.4.3
- # c960 - print out all 960 starting positions for Bobby Fischer's chess variant called Chess960.
- from itertools import permutations
- counter = 0
- board = "BBNNQRKR" #first valid position starting from BBKNNQRR
- possible_board = ""
- ##########################################################################
- # test if king is between the rooks
- def rkr_test(pb):
- pb = pb.replace("B", "")
- pb = pb.replace("N", "")
- pb = pb.replace("Q", "")
- if(pb == "RKR"):
- return(True)
- else:
- return(False)
- ##########################################################################
- # test if bishops are on opposite colors
- def bishop_test(pb):
- first_bishop = pb.find("B")
- second_bishop = pb.find("B", first_bishop + 1)
- if ((second_bishop - first_bishop) % 2 == 1):
- return(True)
- else:
- return(False)
- ##########################################################################
- perms = [''.join(i) for i in permutations(board)]
- sorted_unique_perms = sorted(set(perms))
- print()
- for i in range(0, len(sorted_unique_perms)):
- possible_board = sorted_unique_perms[i]
- if(rkr_test(possible_board)):
- if(bishop_test(possible_board)):
- counter += 1
- print(counter, "\t", possible_board)
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement