from npuzzle_mod import Board npuzzle1 = [] npuzzle1.append([1, 2, 3]) npuzzle1.append([8, 0, 4]) npuzzle1.append([7, 6, 5]) board1 = Board(npuzzle1) npuzzle2 = [] npuzzle2.append([8, 2, 5]) npuzzle2.append([3, 7, 4]) npuzzle2.append([0, 6, 1]) board2 = Board(npuzzle2) print("board1: {}".format(board1.board)) print("board2: {}".format(board2.board)) print("board1 is goal state: {}".format(board1.is_goal_state())) print("board2 is goal state: {}".format(board2.is_goal_state()))
from npuzzle_mod import Board npuzzle = [] npuzzle.append([2, 0, 5]) npuzzle.append([8, 1, 4]) npuzzle.append([7, 6, 3]) board = Board(npuzzle) goal = board.goal_state() print("npuzzle: {}".format(npuzzle)) print("goal state: {}".format(goal.board)) print("out of row and column: {}".format(board.out_of_row_and_column()))
from npuzzle_mod import Board npuzzle1 = [] npuzzle1.append([1, 2, 3]) npuzzle1.append([8, 0, 4]) npuzzle1.append([7, 6, 5]) board1 = Board(npuzzle1) npuzzle2 = [] npuzzle2.append([1, 2, 3]) npuzzle2.append([8, 0, 4]) npuzzle2.append([7, 6, 5]) board2 = Board(npuzzle2) npuzzle3 = [] npuzzle3.append([8, 2, 5]) npuzzle3.append([3, 7, 4]) npuzzle3.append([0, 6, 1]) board3 = Board(npuzzle3) print("board1: {}".format(board1.board)) print("board2: {}".format(board2.board)) print("board3: {}".format(board3.board)) print("board1 equals board2: {}".format(board1.equals(board2))) print("board2 equals board1: {}".format(board2.equals(board1))) print("board1 equals board3: {}".format(board1.equals(board3)))
from npuzzle_mod import Board npuzzle = [] npuzzle.append([2, 1, 5]) npuzzle.append([8, 6, 4]) npuzzle.append([7, 0, 3]) board = Board(npuzzle) goal = board.goal_state() print("npuzzle: {}".format(npuzzle)) print("goal state: {}".format(goal.board)) print("manhattan distance: {}".format(board.manhattan_distance()))
from npuzzle_mod import Board npuzzle = [] npuzzle.append([2, 1, 5]) npuzzle.append([8, 6, 4]) npuzzle.append([7, 0, 3]) board = Board(npuzzle) goal = board.goal_state() print("npuzzle: {}".format(npuzzle)) print("goal state: {}".format(goal.board))
from npuzzle_mod import Board npuzzle = [] npuzzle.append([1, 2, 3]) npuzzle.append([8, 0, 4]) npuzzle.append([7, 6, 5]) board = Board(npuzzle) print(board.board_spiral_translate())
from npuzzle_mod import Board npuzzle = [] npuzzle.append([1, 5, 7]) npuzzle.append([2, 0, 6]) npuzzle.append([3, 8, 4]) board = Board(npuzzle) print("npuzzle: {}, inversions: {}".format(board, board.count_inversions())) npuzzle1 = [] npuzzle1.append([1, 2, 3]) npuzzle1.append([8, 0, 4]) npuzzle1.append([7, 6, 5]) board1 = Board(npuzzle1) print("npuzzle1: {}, inversions: {}".format(board1, board1.count_inversions()))
try: board_size = int(sys.argv[3]) start_board_array = generate_random_board(board_size) except ValueError: board_size = None start_board_array = None if not start_board_array: validation_error = True else: usage_error = True if sys.argv[2] in heuristics: heuristic_key = heuristics.index(sys.argv[2]) + 1 elif not usage_error: usage_error = True else: usage_error = True if (not usage_error) and (not validation_error): start_board = Board(start_board_array) if start_board.is_solvable(): solve_puzzle.sovle_puzzle(start_board.board, heuristic_key) else: sys.stderr.write("Puzzle can not be solved\n") solve_puzzle.display_state(start_board.board, 0) elif validation_error: sys.stderr.write("Error\n") elif usage_error: sys.stderr.write( "Error\nUsage: main.py -f|-r heuristic npuzzle.txt|random_puzzle_size\nheuristic = manhattan OR hamming OR row_and_column\n" )
from npuzzle_mod import Board npuzzle = [] npuzzle.append([2, 1, 5]) npuzzle.append([8, 6, 4]) npuzzle.append([7, 0, 3]) board = Board(npuzzle) goal = board.goal_state() print("npuzzle: {}".format(npuzzle)) print("goal state: {}".format(goal.board)) print("hamming distance: {}".format(board.hamming_distance()))