Package: nqueenplay
nqueenplay12345678---------------------------------8|||Q||||||8---------------------------------7|||||Q||||7---------------------------------6||||||||Q|6---------------------------------5||||Q|||||5---------------------------------4|Q||||||||4---------------------------------3|||||||Q||3---------------------------------2||Q|||||||2---------------------------------1||||||Q|||1---------------------------------12345678nqueenplayis N-Queens puzzle player. This tool will generate randomly or randomly locked puzzle, you may use this as "a boxing bag" to practice problem solving algorithm.InstallationThis python package available on pip installation usingpip install nqueenplayRequirementsAvailable on Python 3DocumentationA to Z explanations to use this toolGenerate Random PuzzleTo generate a random puzzle you can do:N=4# any integernqueens=NQueen(N)orN=4# any integernqueens=NQueen(n=N,number_lock=0)# 0 = no lockGenerate Random Locked PuzzleRandom locked mean the distribution of queen is randomize, and there is locking mechanism to make sure the queen position won't change for another run. To generate a random locked puzzle you can do:N=4# any integerlock=1# any integernqueens=NQueen(n=N,number_lock=lock)Get Number of QueensTo get number of queen:N=4nqueens=NQueen(n=N,number_lock=1)number_of_queen=nqueens.get_number_of_queens()Output:print(number_of_queen)# 4Get Queens PositionTo get queen position:N=4nqueens=NQueen(n=N,number_lock=1)positions=nqueens.get_queen_positions()Output:print(positions)# [(1, 1), (2, 4), (3, 3), (4, 2)]Each tuple is The Queen coordinate, there is 4 attack pairsCheck Number of Attack PairsTo check how many attack pairs in the current board:N=4nqueens=NQueen(n=N,number_lock=1)pairs=nqueens.get_attack_pairs()Output:print(pairs)# [[(1, 1), (3, 3)], [(2, 4), (3, 3)], [(2, 4), (4, 2)], [(3, 3), (4, 2)]]Each tuple is The Queen coordinate, there is 4 attack pairsShow The BoardTo show the current board:N=4nqueens=NQueen(n=N,number_lock=1)nqueens.show()output:1234-----------------4||Q|||4-----------------3|||Q||3-----------------2||||Q|2-----------------1|Q||||1-----------------1234Show The Attack PairsTo show the current board attack pairs:N=4nqueens=NQueen(n=N,number_lock=1)nqueens.show_attack_pairs()output# attack_pairs [(1, 3), (2, 3), (2, 4), (3, 4)]# Number of attacking pair(s): 4Move The QueenQueen is column locked, so you can only move one queen to a different rowMove the queen upsideMove Queen to upside with specific range:N=4nqueens=NQueen(n=N,number_lock=1)nqueens.show()nqueens.move_up(queen_pos=1,movement_length=2)nqueens.show()output:1234-----------------4||Q|||4-----------------3|||Q||3-----------------2||||Q|2-----------------1|Q||||1-----------------12341234-----------------4||Q|||4-----------------3|Q||Q||3-----------------2||||Q|2-----------------1|||||1-----------------1234Move the queen downsideMove Queen to downside with specific range:N=4nqueens=NQueen(n=N,number_lock=1)nqueens.show()nqueens.move_down(queen_pos=2,movement_length=2)nqueens.show()output:1234-----------------4||Q|||4-----------------3|||Q||3-----------------2||||Q|2-----------------1|Q||||1-----------------12341234-----------------4|||||4-----------------3|||Q||3-----------------2||Q||Q|2-----------------1|Q||||1-----------------1234Move the queen on specific neighborMove Queen to a specific neighbor by neighbor row position:N=4nqueens=NQueen(n=N,number_lock=1)nqueens.show()nqueens.move_to(queen_pos=2,target_pos=1)nqueens.show()output:1234-----------------4||Q|||4-----------------3|||Q||3-----------------2||||Q|2-----------------1|Q||||1-----------------12341234-----------------4|||||4-----------------3|||Q||3-----------------2||||Q|2-----------------1|Q|Q|||1-----------------1234Move the queen to a random placementMove Queen to random place in the column:N=4nqueens=NQueen(n=N,number_lock=1)nqueens.show()nqueens.move_random(queen_pos=3)nqueens.show()output:1234-----------------4||Q|||4-----------------3|||Q||3-----------------2||||Q|2-----------------1|Q||||1-----------------12341234-----------------4||Q|||4-----------------3|||||3-----------------2|||Q|Q|2-----------------1|Q||||1-----------------1234CopyrightFree to use! Under MIT License.