CS480 Assignment-3
CS480 Assignment-3
Analysis: -
The below code is available at git repo =>
https://github.com/ashishodu2023/CrosswordsolverAi.git with readme files with all
the instructions on how to execute the cross wore puzzle. The medium and hard
crossword puzzle uses Forward Checking as of the Heuristics to reduce the domain
and search space. The execution time for each of the puzzle is given after code
completion with results of each of the execution.
Forward checking detects the inconsistency earlier than simple backtracking and
thus it allows branches of the search tree that will lead to failure to be pruned
earlier than with simple backtracking. This reduces the search tree and the overall
amount of work done.
Folder Structure: -
Grid Medium Structure: -
##-------###
##-#####-##-
##-#####-##-
##-##-----#-
##-####-###-
####-##-----
####-##-#-#-
#-#-----#-##
#-##-##-#-##
------###-##
#-##-####-##
ReadMe :-
Tiny Puzzle
import time
return False
def main():
# Example crossword grid and word data
crossword_grid = [
[" ", " ", " ", " ", " "],
["#", "#", " ", "#", " "],
["#", " ", " ", " ", " "],
[" ", "#", " ", " ", " "],
[" ", " ", " ", " ", " "],
[" ", "#", "#", " ", "#"],
]
word_data = [
("1ACROSS", [(0, 0)], {"HOSES", "LASER", "SAILS",
"SHEET", "STEER"}),
("4ACROSS", [(2, 1)], {"HEEL", "HIKE", "KEEL", "KNOT",
"LINE"}),
("7ACROSS", [(3, 2)], {"AFT", "ALE", "EEL", "LEE",
"TIE"}),
("8ACROSS", [(4, 0)], {"HOSES", "LASER", "SAILS",
"SHEET", "STEER"}),
("2DOWN", [(0, 2)], {"HOSES", "LASER", "SAILS",
"SHEET", "STEER"}),
("3DOWN", [(0, 4)], {"HOSES", "LASER", "SAILS",
"SHEET", "STEER"}),
("5DOWN", [(2, 3)], {"HEEL", "HIKE", "KEEL", "KNOT",
"LINE"}),
("6DOWN", [(3, 0)], {"AFT", "ALE", "EEL", "LEE",
"TIE"}),
]
if __name__ == '__main__':
main()
Medium Puzzle
import time
unassigned.sort(key=lambda x: len(x.domain))
return unassigned[0]
if length > 1:
domain = []
for word in words:
if len(word) == length:
domain.append(word)
variables.append(Variable(
"horizontal",
row,
col,
length,
domain
))
if row == 0 or board[row - 1][col] == "#":
length = 0
for i in range(row, len(board)):
if board[i][col] == "-":
length += 1
else:
break
if length > 1:
domain = []
for word in words:
if len(word) == length:
domain.append(word)
variables.append(Variable(
"vertical",
row,
col,
length,
domain
))
return variables
if __name__ == "__main__":
start_time = time.time()
main()
print("\n---Time taken for code execution %s seconds ---" %
(time.time() - start_time))
import time
import nltk
from collections import deque
return all_words.intersection(english_words)
return True
if SolvePuzzleBacktracking(board, dictionary,
remaining_words):
return True
return False
# Update the set of remaining words for each empty cell on the
board
def UpdateWords(board, remaining_words, dictionary):
for i in range(len(board)):
for j in range(len(board[0])):
if board[i][j] == 0:
remaining_words[i][j] = GetValidWords(board, i,
j, dictionary)
return valid_words
if __name__ == "__main__":
start_time = time.time()