コード例 #1
0
 def test_safely_put_one_more_queen_on_a_board_with_knight_pattern_starting_from_h8(self):
     board = get_board(["h8", "g6", "f4", "e2"])
     column_d = ["d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8"]
     board, queen_position = safely_put_one_more_queen(board, column_d)
     self.assertEquals(5, count_queen(board))
     self.assertTrue(validate_board(board))
     self.assertTrue(is_queen(board, "d7"))
コード例 #2
0
 def test_safely_put_one_more_queen_on_a_board_with_knight_pattern_starting_from_a1(self):
     board = get_board(["a1", "b3", "c5", "d7"])
     column_e = ["e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8"]
     board, queen_position = safely_put_one_more_queen(board, column_e)
     self.assertEquals(5, count_queen(board))
     self.assertTrue(validate_board(board))
     self.assertTrue(is_queen(board, "e2"))
コード例 #3
0
def validate_board(board):
    rows_valid = True
    for row in range(1,9):
        row_valid = validate_row(str(row), board) 
        rows_valid = rows_valid and row_valid
    columns_valid = True
    columns = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
    for column in columns:
        column_valid = validate_column(column, board)
        columns_valid = columns_valid and column_valid
    queen_positions = [ position for position in all_positions if is_queen(board, position) ]
    diagonally_valid = True
    for queen_position in queen_positions:
        diagonally_valid = diagonally_valid and validate_diagonally(queen_position, board)
    return rows_valid and columns_valid and diagonally_valid
コード例 #4
0
ファイル: eight_queen.py プロジェクト: juacompe/eight_queen
def find_queen_positions(board):
    queen_positions = [ position for position in all_positions if is_queen(board, position) ]
    return queen_positions 
コード例 #5
0
 def test_solve_puzzle_starting_at_middle_of_the_board(self):
     starting_point = "d5"
     board = solve_puzzle(starting_point)
     self.assertTrue(is_queen(board, "d5"))
     self.assertTrue(validate_board(board))
     self.assertEquals(8, count_queen(board))
コード例 #6
0
 def test_solve_puzzle_starting_at_top_left_corner(self):
     starting_point = "a8"
     board = solve_puzzle(starting_point)
     self.assertTrue(is_queen(board, "a8"))
     self.assertTrue(validate_board(board))
     self.assertEquals(8, count_queen(board))
コード例 #7
0
 def test_solve_puzzle_starting_at_bottom_right_corner(self):
     starting_point = "h1"
     board = solve_puzzle(starting_point)
     self.assertTrue(is_queen(board, "h1"))
     self.assertTrue(validate_board(board))
     self.assertEquals(8, count_queen(board))
コード例 #8
0
 def test_h1_is_not_queen(self):
     """
     test the right row, wrong column 
     """
     result = is_queen(board_with_queen_at_a1, "h1")
     self.assertFalse(result)
コード例 #9
0
 def test_a8_is_not_queen(self):
     """
     test the right column, wrong row
     """
     result = is_queen(board_with_queen_at_a1, "a8")
     self.assertFalse(result)
コード例 #10
0
 def test_a1_is_queen(self):
     """
     test the right column, the right row
     """
     result = is_queen(board_with_queen_at_a1, "a1")
     self.assertTrue(result)
コード例 #11
0
def validate_diagonally(position, board):
    positions = get_diagonal_positions(position) 
    positions.append(position)
    queen_positions = [ position for position in positions if is_queen(board, position) ]
    return len(queen_positions) <= 1