1 / 5

Crossword Puzzle Solver

Crossword Puzzle Solver. Michael Keefe. Solver structure. UI structure. ARC Reduction and backtracking. 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

keelia
Download Presentation

Crossword Puzzle Solver

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Crossword Puzzle Solver Michael Keefe

  2. Solver structure

  3. UI structure

  4. ARC Reduction and backtracking 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; }

  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; }

More Related