Download presentation
Presentation is loading. Please wait.
Published byShavonne Long Modified over 9 years ago
1
Crossword Puzzle Solver Michael Keefe
2
Solver structure
3
UI structure
4
Let Q be a copy of puzzle constraints Let arc be a binary constraint Let xi,xj,xk be Variables with domains initialized to all words that fit void AC3(Puzzle p) { While Q not empty Remove an arc (xi xj) from Q; If arc-reduce(xi, xj) then If the domain of xi is empty return failure; else Add to Q all arcs (xk xi), with k different than i and j, that are in the CS-Problem; return success; } ARC Reduction and backtracking
5
Arc reduce private static bool arcReduce(Puzzle p, Variable xi, Variable xj) bool change = false; var c = getConstraint(p, xi, xj); string word = string.Empty; // if the constraint was inverted var swapped = c.CellA.Variable != xi; var y = swapped ? c.CellA.Index - 1 : c.CellB.Index - 1; var x = swapped ? c.CellB.Index - 1 : c.CellA.Index - 1; //For each value u in the domain of xi for (int i = xi.Domain.Count - 1; i >= 0; i--) { bool exists = false; word = xi.Domain[i]; exists = xj.Domain.Any(w => w[y] == word[x]); if (!exists) //If there is no such v, remove u from the domain of xi & set Change to true; xi.Domain.RemoveAt(i); change = true; } return change; }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.