Exemplo n.º 1
0
def main():
    print("""
    Please give me board; width and height;
    """)

    len_x = take_counts("Board width ", True)
    len_y = take_counts("Board height ", True)

    print("""
    Please give me pieces' counts;
    """)

    pieces_counts = {}
    pieces_counts.setdefault(KING, take_counts("King count? "))
    pieces_counts.setdefault(QUEEN, take_counts("Queen count? "))
    pieces_counts.setdefault(ROOK, take_counts("Rook count? "))
    pieces_counts.setdefault(KNIGHT, take_counts("Knight count? "))
    pieces_counts.setdefault(BISHOP, take_counts("Bishop count? "))

    board = Board(len_x, len_y)
    pieces = []

    for piece in PIECES_ORDER:
        pieces.extend([piece] * pieces_counts[piece])

    board.place_them_all(pieces=pieces)
    board.show_combinations(limit=10)
    print("Combinations found in '{}'".format(board.spend_time))
Exemplo n.º 2
0
 def test_locate_king(self):
     board = Board(3, 3)
     pieces_counts = {"K": 4, "Q": 0, "B": 0, "N": 0, "R": 0}
     pieces = []
     for piece in PIECES_ORDER:
         pieces.extend([piece] * pieces_counts[piece])
     board.place_them_all(pieces=pieces)
     self.assertEqual(len(board.combinations), 1)
     self.assertEqual(
         set([0, 2, 6, 8]), set(map(lambda x: int(x.split("_")[1]), list(board.combinations)[0].split(",")))
     )
Exemplo n.º 3
0
 def test_locate_queen(self):
     board = Board(3, 3)
     pieces_counts = {"K": 0, "Q": 2, "B": 0, "N": 0, "R": 0}
     pieces = []
     for piece in PIECES_ORDER:
         pieces.extend([piece] * pieces_counts[piece])
     board.place_them_all(pieces=pieces)
     self.assertEqual(len(board.combinations), 8)
     board.reset()
     board.combinations = set([])
     pieces_counts = {"K": 0, "Q": 3, "B": 0, "N": 0, "R": 0}
     pieces = []
     for piece in PIECES_ORDER:
         pieces.extend([piece] * pieces_counts[piece])
     board.place_them_all(pieces=pieces)
     self.assertEqual(len(board.combinations), 0)