Skip to content
Snippets Groups Projects
solution testing.py 2.73 KiB
Newer Older
Michael Mutote's avatar
Michael Mutote committed
import Search_Algorithms
Michael Mutote's avatar
Michael Mutote committed
import Sucessors
import is_goal
Michael Mutote's avatar
Michael Mutote committed
import Heuristics
Michael Mutote's avatar
Michael Mutote committed


Michael Mutote's avatar
Michael Mutote committed
# Maze Problem, note, the maze is fixed in the allowed state.
Michael Mutote's avatar
Michael Mutote committed
print(Search_Algorithms.BreadthFirstSearch((4, 0), Sucessors.maze_successor, is_goal.is_goal_maze))
Michael Mutote's avatar
Michael Mutote committed

Michael Mutote's avatar
Michael Mutote committed
# Sudoku
Michael Mutote's avatar
Michael Mutote committed
grid = ((5, 3, 0, 0, 7, 0, 0, 0, 0),
        (6, 0, 0, 1, 9, 5, 0, 0, 0),
        (0, 9, 8, 0, 0, 0, 0, 6, 0),
        (8, 0, 0, 0, 6, 0, 0, 0, 3),
        (4, 0, 0, 8, 0, 3, 0, 0, 1),
        (7, 0, 0, 0, 2, 0, 0, 0, 6),
        (0, 6, 0, 0, 0, 0, 2, 8, 0),
        (0, 0, 0, 4, 1, 9, 0, 0, 5),
Michael Mutote's avatar
Michael Mutote committed
        (0, 0, 0, 0, 8, 0, 0, 0, 0))

Michael Mutote's avatar
Michael Mutote committed
sln = (Search_Algorithms.BreadthFirstSearch(grid, Sucessors.sudoku_successor, is_goal.is_goal_sudoku)[-1])
Michael Mutote's avatar
Michael Mutote committed

Michael Mutote's avatar
Michael Mutote committed
for rows in sln:
    print(rows)
print("--------------------------------")
sln = (Search_Algorithms.DepthFirstSearch(
     grid, Sucessors.sudoku_successor, is_goal.is_goal_sudoku)[-1])
Michael Mutote's avatar
Michael Mutote committed
#
Michael Mutote's avatar
Michael Mutote committed
for rows in sln:
    print(rows)
Michael Mutote's avatar
Michael Mutote committed

# N Queens
board = ((False, False, False, False, False, False, False, False, False),
         (False, False, False, False, False, False, False, False, False),
         (False, False, False, False, False, False, False, False, False),
         (False, False, False, False, False, False, False, False, False),
         (False, False, False, False, False, False, False, False, False),
         (False, False, False, False, False, False, False, False, False),
         (False, False, False, False, False, False, False, False, False),
         (False, False, False, False, False, False, False, False, False),
         (False, False, False, False, False, False, False, False, False))


Michael Mutote's avatar
Michael Mutote committed
sln = (Search_Algorithms.BreadthFirstSearch(board, Sucessors.queens_successor, is_goal.is_goal_queens)[-1])

Michael Mutote's avatar
Michael Mutote committed
# sln = (Search_Algorithms.DepthFirstSearch(
#     board, Sucessors.queens_successor, is_goal.is_goal_queens)[-1])
Michael Mutote's avatar
Michael Mutote committed

output_tuple = tuple(tuple("Q" if value else "." for value in sln)
                     for sln in sln)
for rows in output_tuple:
    print(rows)
Michael Mutote's avatar
Michael Mutote committed

tnbeats's avatar
tnbeats committed

# Sliding Puzzle
initial_puzzle = (
    (7, 2, 4),
    (5, 0, 6),
    (8, 3, 1)
)
Michael Mutote's avatar
Michael Mutote committed

sln = (Search_Algorithms.BreadthFirstSearch(initial_puzzle, Sucessors.puzzle_successor, is_goal.is_goal_puzzle)[-1])

if sln:
    for rows in sln:
        print(rows)
else:
    print("No solution found")
Michael Mutote's avatar
Michael Mutote committed

Michael Mutote's avatar
Michael Mutote committed
#
# sln = (Search_Algorithms.DepthFirstSearch(initial_puzzle, Sucessors.puzzle_successor, is_goal.is_goal_puzzle)[-1])
#
# if sln:
#     for rows in sln:
#         print(rows)
# else:
#     print("No solution found")

Michael Mutote's avatar
Michael Mutote committed
# print(Search_Algorithms.A_StarSearch((4, 0), Sucessors.maze_successor, is_goal.is_goal_maze, Heuristics.maze_opt))

sln = (Search_Algorithms.A_StarSearch(grid, Sucessors.sudoku_successor,
                                      is_goal.is_goal_sudoku, Heuristics.sudoku_opt))[-1]

for rows in sln:
    print(rows)
tnbeats's avatar
tnbeats committed