Boggle TrieProject incorporates a TRIE structure containing a word list. The "Boggle" portion presents a 4x4 matrix of characters. The game is played in 2 phases.WE WILL ONLY FOCUS ON PHASE 2 FOR THIS...

1 answer below »


Boggle Trie


Project incorporates a TRIE structure containing a word list. The "Boggle" portion presents a 4x4 matrix of characters. The game is played in 2 phases.






WE WILL ONLY FOCUS ON PHASE 2 FOR THIS ASSIGNMENT. We will simulate by having a loop ask a "user" for a word to check (instead of building a word from the Boggle game).

The response is simply "Yes/No" as to whether the user-supplied
word
is present.






  • Phase 1: The player attempts to construct a word by using adjacent characters in the grid. Each character may be used only once in the word. These words are then scored as +3 point if they are in a word list/dictionary and -1 if they are not (to discourage wild guesses). Each word attempt must be minimally 3 characters long. Repeated words will not be scored (only the first attempt scores).


  • Phase 2: The player's "guessing phase" is over. This phase consists of the game constructing all the possible words the playershould have foundin the supplied matrix. This display will only show those words not already guessed by the player.





Intro to Swift Trie Tree Data structure built to store data Allows for searching Basic structure Root node Each [parent] node can have 0 or more children nodes Each node has only a single parent node Various tree structures exist Different rules regarding the number of nodes or the placement of node (based on values) Selection of the appropriate tree is based on storage or lookup needs Can have a profound efficiency impact Trie Tree structure used for search and retrieval Pronounced “try” or “try-ee” Binary trees used full key comparison Each node contain the key Searching for a value results in finding the entire value or key What if you only have a partial value? Trie Is a ‘prefix’ B-tree Portion of the key required in order to follow the path Each key is a sequence of characters 3 Characteristics Each node has up to n children nodes If we’re storing word strings, then up to 26 nodes in the English alphabet Each node stores a character (‘char’) type Root node is designated as a special character ( we can us ‘^’, the caret) It’s how we know we’re looking at the root node Each word (string) inserted into our Trie can be found by tracing a path from the root node to another node Not necessarily a leaf node End of string is noted with a character value other than A-Z or ^ (a character not part of the alphabet we’re using) We treat this character as ‘sentinel data’ Visually depicting the Trie Adding the words (strings) to the Trie results in the following: ARM ARC ARMED JAZZ JAWS Two strings having the same common prefix ARM, ARMED ARc, ARm, ARmed, ARming, ARmies, ARmy Prefix is only stored once Big O Search, insert, delete for any string s O(m)where m is the length of s Structure is used largely for searching Insertion might be costly, but outweighed by search savings Usage Using our Dictionary as a basis We move the word list to the Trie We can now search to see if a word exists Search character by character Match each character to a child node of the current node A child node is a “$” (or the terminating indicator) character Otherwise it’s not a word in our structure What about a partial word? We know whether or not to keep looking If the current node has more than one child (including the terminating indicator) Another possibility exists Prefix( ) method Finds the ‘prefix’ Match every character in the string to node values in a path of nodes, starting with the root It ends when there is no longer a match Returns the last node that matched Prefix(“JA”)returns “A” (and 2 child nodes) public Node Prefix(string s) { var currentNode = _root; var result = currentNode; foreach (var c in s) { currentNode = currentNode.FindChildNode(c); if (currentNode == null) break; result = currentNode; } return result; } Insert( ) method Relies on Prefix( ) We follow the node path until we hit the last matching node We return that node Insert the appropriate node value and new terminator Delete method Find the complete path to the node Work backward Delete any leaf nodes (no children) Deleting “JAWS” Still leaves us with the “JA” prefix Part of another string Search( ) method Relies on the Prefix( ) method Returns a match (or not) based on the prefix passed to it Only if the “prefix” (what you’re searching for) is a complete word The depth must match the length of the prefix string One of the children must be the sentinel value for a word ending Another child can still be there… it’s a word, but also part of another word! public bool Search(string s) { var prefix = Prefix(s); return prefix.Depth == s.Length && prefix.FindChildNode('$') != null; } Partial( ) method Based on the Prefix() method Looks for the prefix, which returns the last node matched in the prefix Depth must be the length of the prefix string Where Search relied on one of the children being the sentinel (‘$’) character Partial word relies on at least one child value other than the ‘$’ value While it can be a word, there should be at least one other child letter value Returning ‘true’ Partial(“JA”) Partial(“JAZ”) Partial(“JAW”) Returning ‘false’ Partial(“JAWS”) Node Char value is a character in the alphabet The ‘root’ node has a special character “sentinel” value‘^’ The value of the node (a child node) indicating the end of a word also is a special character “sentinel” value‘$’ Boggle How do we get to the “Boggle” game? Add user interaction on the form Clickable object (buttons, labels or textboxes) Each one has a character displayed When selected, we can indicate to the user that it’s selected Change the fore or back color, or disable it, etc… Arrange letters on the form in a 4x4 grid We use the grid to allow users to form a word to check Enforce the rules of the game Minimum of 3 letters Letters selected must be adjacent Cannot select the same position letter more than once Boggle Add internal structure to remember the words found Use this to tell the player it’s already been found, and not to score it again Add internal structure to hold the words which could’ve been found on that grid Use this to display the words to the player Listboxes can be used to display these word listings Create a ‘shadow’ grid Use this version for the backtracking algorithm in finding all possible words Must contain the value of the character Must contain an indicator of whether it’s been used in the construction of the word To avoid using it again Boggle User interaction Added a 4x4 grid of buttons Behind the scenes Create a collection (array) of Control type to hold these buttons Implemented a method to populate the array of Control type with the buttons Create a “Ltr” class Represents a letter on the grid Properties Charthe letter to be displayed Booleanwas the letter previously selected to form the current word Created an array of Ltr as a ‘shadow’ collection to the visible grid This will be used to backtrack Randomly generated characters Based on ASCII values from 65-91 for A-Z Assign these letters to the “letter” objects in the shadow collection Assign these letters to the faces of the buttons on the grid (each button’s “text” property) Boggle Arrays Can be single dimensional or two dimensional You simply keep track of which ‘row’ and ‘column’ User selects a letter Toggle the selection as ‘visited’ or ‘selected’ Don’t let the user select the same letter again in the word Keep track of the letters and “build” the word (prefix) to search Only allow adjacent unused letters to be used to build the word Allow the user to “undo” only the last letter selected Undo the letter in the ‘prefix’ being build as well Backtracking Use the ‘shadow’ structure to try all possible words Array shown has ‘border’ elements which are null or sentinel values Allows to decide if neighbor exists Need to make a ‘FindNeighbors’ method Selects all adjacent letters which are not already selected Consistent search Start with same position (‘North’) and then go clockwise Border can facilitate the algorithm But not necessary Example Start with a limited and known set of letters Take each letter, one at a time Start with the upper left corner (the position and not the letter itself) Add the position to the stack of positions (1,1) Select the letter and mark it as “selected” (C”) Add that letter to the word to seek (“C”) Is it a partial word? Yes Find all neighbors (the positions!) Not already selected? Add it to the stack of positions 2,1 2,2 1,2 1,1 Node+ value: char+depth ():integer+children:List+parent:Node &c 'd 'em 'll 'm 'mid 'midst 'mongst 'prentice 're 's 'sblood 'sbodikins 'sdeath 'sfoot 'sheart 'shun 'slid 'slife 'slight 'snails 'strewth 't 'til 'tis 'twas 'tween 'twere 'twill 'twixt 'twould 'un 've 1080 10th 1st 2 2nd 3rd 4th 5th 6th 7th 8th 9th a a' a's a/c a1 aa aaa aah aahed aahing aahs aal aalii aaliis aals aam aardvark aardvarks aardwolf aardwolves aargh aaron aaronic aarrgh aarrghh aas aasvogel aasvogels ab aba abac abaca abacas abacate abacaxi abacay abaci abacinate abacination abacisci abaciscus abacist aback abacli abacot abacterial abactinal abactinally abaction abactor abaculi abaculus abacus abacuses abada abaddon abadejo abadengo abadia abaff abaft abaisance abaised abaiser abaisse abaissed abaka abakas abalation abalienate abalienated abalienating abalienation abalone abalones abamp abampere abamperes abamps aband abandon abandonable abandoned abandonedly abandonee abandoner abandoners abandoning abandonment abandonments abandons abandum abanet abanga abannition abapical abaptiston abaptistum abarthrosis abarticular abarticulation abas abase abased abasedly abasedness abasement abasements abaser abasers abases abash abashed abashedly abashedness abashes abashing abashless abashlessly abashment abashments abasia abasias abasic abasing abasio abask abassi abastard abastardize abastral abatable abatage abate abated abatement abatements abater abaters abates abatic abating abatis abatised abatises abatjour abatjours abaton abator abators abattage abattis abattised abattises abattoir abattoirs abattu abattue abature abaue abave abaxial abaxile abay abayah abaze abb abba abbacies abbacomes abbacy abbandono abbas abbasi abbasid abbassi abbate abbatial abbatical abbatie abbaye abbe abbes abbess abbesses abbest abbevillian abbey abbey's abbeys abbeystead abbeystede abboccato abbogada abbot abbot's abbotcies abbotcy abbotnullius abbotric abbots abbotship abbotships abbott abbozzo abbr abbrev abbreviatable abbreviate abbreviated abbreviately abbreviates abbreviating abbreviation abbreviations abbreviator abbreviators abbreviatory abbreviature abbroachment abby abc abcess abcissa abcoulomb abd abdal abdali abdaria abdat abdest abdicable abdicant abdicate abdicated abdicates abdicating abdication abdications abdicative abdicator abditive abditory abdom abdomen abdomen's abdomens abdomina abdominal abdominales abdominalia abdominalian abdominally abdominals abdominoanterior abdominocardiac abdominocentesis abdominocystic abdominogenital abdominohysterectomy abdominohysterotomy abdominoposterior abdominoscope abdominoscopy abdominothoracic abdominous abdominovaginal abdominovesical abduce abduced abducens abducent abducentes abduces abducing abduct abducted abducting abduction abduction's abductions abductor abductor's abductores abductors abducts abeam abear abearance abecedaire abecedaria abecedarian abecedarians abecedaries abecedarium abecedarius abecedary abed abede abedge abegge abeigh abel abele abeles abelian abelite abelmosk abelmosks abelmusk abeltree abend abends abenteric abepithymia aberdavine aberdeen aberdevine aberduvine abernethy aberr aberrance aberrancies aberrancy aberrant aberrantly aberrants aberrate aberrated aberrating aberration aberrational aberrations aberrative aberrator aberrometer aberroscope aberuncate aberuncator abesse abessive abet abetment abetments abets abettal abettals abetted abetter abetters abetting abettor abettors abevacuation abey abeyance abeyances abeyancies abeyancy abeyant abfarad abfarads abhenries abhenry abhenrys abhinaya abhiseka abhominable abhor abhorred abhorrence abhorrences abhorrency abhorrent abhorrently abhorrer abhorrers abhorrible abhorring abhors abib abichite abidal abidance abidances abidden abide abided abider abiders abides abidi abiding abidingly abidingness abiegh abience abient abietate abietene abietic abietin abietineous abietinic abietite abigail abigails abigailship abigeat abigei abigeus abilao abilene abiliment abilitable abilities ability ability's abilla abilo abime abintestate abiogeneses abiogenesis abiogenesist abiogenetic abiogenetical abiogenetically abiogenist abiogenous abiogeny abiological abiologically abiology abioses abiosis abiotic abiotical abiotically abiotrophic abiotrophy abir abirritant abirritate abirritated abirritating abirritation abirritative abiston abit abiuret abject abjectedness abjection abjections abjective abjectly abjectness abjoint abjudge abjudged abjudging abjudicate abjudicated abjudicating abjudication abjudicator abjugate abjunct abjunction abjunctive abjuration abjurations abjuratory abjure abjured abjurement abjurer abjurers abjures abjuring abkar abkari abkary abl ablach ablactate ablactated ablactating ablactation ablaqueate ablare ablastemic ablastin ablastous ablate ablated ablates ablating ablation ablations ablatitious ablatival ablative ablatively ablatives ablator ablaut ablauts ablaze able ableeze ablegate ablegates ablegation ablend ableness ablepharia ablepharon ablepharous ablepsia ablepsy ableptical ableptically abler ables ablesse ablest ablet ablewhackets ablings ablins ablock abloom ablow ablude abluent abluents ablush ablute abluted ablution ablutionary ablutions abluvion ably abmho abmhos abmodalities abmodality abn abnegate abnegated abnegates abnegating abnegation abnegations abnegative abnegator abnegators abner abnerval abnet abneural abnormal abnormalcies abnormalcy abnormalise abnormalised abnormalising abnormalism abnormalist abnormalities abnormality abnormalize abnormalized abnormalizing abnormally abnormalness abnormals abnormities abnormity abnormous abnumerable abo aboard aboardage abococket abodah abode abode's aboded abodement abodes aboding abody abogado abogados abohm abohms aboideau aboideaus aboideaux aboil aboiteau aboiteaus aboiteaux abolete abolish abolishable abolished abolisher abolishers abolishes abolishing abolishment abolishment's abolishments abolition abolitionary abolitionise abolitionised abolitionising abolitionism abolitionist abolitionists abolitionize abolitionized abolitionizing abolla abollae aboma abomas abomasa abomasal abomasi abomasum abomasus abomasusi abominability abominable abominableness abominably abominate abominated abominates abominating abomination abominations abominator abominators abomine abondance abonne abonnement aboon aborad aboral aborally abord aboriginal aboriginality aboriginally aboriginals aboriginary aborigine aborigine's aborigines aborning aborsement aborsive abort aborted aborter aborters aborticide abortient abortifacient abortin aborting abortion abortion's abortional abortionist abortionists abortions abortive abortively abortiveness abortogenic aborts abortus abortuses abos abote abouchement aboudikro abought aboulia aboulias aboulic abound abounded abounder abounding aboundingly abounds about abouts above aboveboard abovedeck aboveground abovementioned aboveproof aboves abovesaid abovestairs abow abox abp abr abracadabra abrachia abrachias abradable abradant abradants abrade abraded abrader abraders abrades abrading abraham abraid abranchial abranchialism abranchian abranchiate abranchious abrasax abrase abrased abraser abrash abrasing abrasiometer abrasion abrasion's abrasions abrasive abrasively abrasiveness abrasives abrastol abraum abraxas abray abrazite abrazitic abrazo abrazos abreact abreacted abreacting abreaction abreactions abreacts abreast abreed abrege abreid abrenounce abrenunciate abrenunciation abreption abret abreuvoir abri abrico abricock abricot abridgable abridge abridgeable abridged abridgedly abridgement abridgements abridger abridgers abridges abridging abridgment abridgments abrim abrin abrine abris abristle abroach abroad abrocome abrogable abrogate abrogated abrogates abrogating abrogation abrogations abrogative abrogator abrogators abronia abrood abrook abrosia abrosias abrotanum abrotin abrotine abrupt abruptedly abrupter abruptest abruptio abruption abruptiones abruptly abruptness abs absampere absarokite abscam abscess abscessed abscesses abscessing abscession abscessroot abscind abscise abscised abscises abscising abscisins abscision absciss abscissa abscissa's abscissae abscissas abscisse abscissin abscission abscissions absconce abscond absconded abscondedly abscondence absconder absconders absconding absconds absconsa abscoulomb abscound absee abseil abseiled abseiling abseils absence absence's absences absent absentation absented absentee absentee's absenteeism absentees absenteeship absenter absenters absentia absenting absently absentment absentminded absentmindedly absentmindedness absentness absents absey absfarad abshenry absinth absinthe absinthes absinthial absinthian absinthiate absinthiated absinthiating absinthic absinthiin absinthin absinthine absinthism absinthismic absinthium absinthol absinthole absinths absis absist
Answered Same DayDec 21, 2022

Answer To: Boggle TrieProject incorporates a TRIE structure containing a word list. The "Boggle" portion...

Karthi answered on Dec 21 2022
30 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here