Text Twist Sean Devlin & Timothy Licata University of Notre Dame CSE 331 Data Structures Final Project Abstract Text Twist is a single player game designed to be fun to play from the viewpoint of the user while being as efficient as possible from the standpoint of the deisgn. Various data structures were tested against each other to see which was faster and more fitting for the situation of handling all the data. This project used these data structures in combination with an algorithm of choice to load, sort, and check data against user input in the most efficient manner possible. Key Terms Anagram A word that can be made up using only and all of the letters in another word. In the case of this project, anagram is to mean any word that can be spelled using only the letters of another word, but not necessarily using all of the letters. Vector C++ Standard Library class List C++ Standard Library class GUI Graphical User Interface Motivation and Goals Text Twist is a single player game in which the player is shown six letters that, when rearranged, can make up at least one sixletter word and many other words between three and six letters in length. The objective of the player is to guess the six letter word (or any other of the sixletter words, it is impossible to distinguish the two) before time runs out. The player accumulates points by guessing words with increased point value for longer words. When time has run out, the player will advance to the next level if he or she correctly guessed the current sixletter word. Each next level presents the player with a new sixletter word in jumbled form and the process is repeated. The motivation for Text Twist was an already existing version of the game found online. The gameplay and underlying data processing was intriguing and it seemed a perfect fit for a project that sought to integrate several data structures and algorithms into a computer program. The goal was to recreate the existing game in the most efficient manner by exploring many different structures to hold the data and several algorithms for processing it. Finally, the underlying goal/motivation for Text Twist was to complete the requirements of CSE 331 and, in doing so, avoid having to take it again next semester. Functionality, Platform, and Users The desired functionality for Text Twist is that is has enjoyable and userfriendly gameplay. This requires that the code run flawlessly as to be transparent to the user. The target platform is Microsoft Windows since the GUI was created with Win32 API which will only run on Windows operating systems. The group of potential users is comprised of people who sometimes become bored while sitting at a computer and desire something quick and fun to rid them of this boredom. A UML based overview of the program framework The following is the UML of Text Twist. One class (Text Twist) was used and it contained several private data members. Class TextTwist Public: TextTwist(); Void loadWordList(string); Void populateMaps(); Int mapSize(int); Map<string, bool> getList(int); String getKey(int); Private: Vector<string> word_list; Map<string, map<string, bool> > word_map; However, much of the functionality is located in the GUI and therefore is not part of the class. Many of the program functions are triggered on specific user actions and are coded as such in the GUI, and not in the TextTwist class. Key Data Structures and Algorithms The structure that was going to hold the words that were going to be loaded from a text file would need to be easily resizeable and provide easy access to all elemets. The C++ standard class Vector fit the situation perfectly since is had the operation push_back which allows easy appendages to the structure and the elements could be easily accessed using the syntax vector[i] Other options were Array and List but array did not possess dynamic resizing and the list, which specializes in quick insertion and deletion from the interior of the structure, could also not offer any benefits. Once the word list was loaded, the six letter words were marked and then the program found all the anagrams of that sixletter word and stored the results in a Map with a String as its key and another Map as its value (map<string, map<string, bool> >). This structure was selected because the outer Map would have each sixletter word as its keys, and then the inner Map would have each anagram of the sixletter word as a key with a boolean as its value. The boolean was used later for GUI purposes and gameplay visuals. This Map structure would be the largest and main structure since each new level and all user guesses would search the maps for new sixletter words and anagrams, respectively. This allowed for efficieny in looking up words and program clarity from a design perspective. In addition to the map, the tree structure was considered for this role. The binary tree would allow for quicker search times if constructed properly. However, due to the alphabetical order of our word list, significant work would need to be done to perfectly balance the trees and this extra processing would be necessary. The fact that the slightly faster search times would have been negated by the extra processing showed that the map was the structure most suited for the task. The rest of the data structures were smaller vectors and arrays involved with the storing and processing of user input. Users are provided with the characters in the word they are yet to guess and the words they have correctly guessed are placed on the screen. User input was put into a vector for since it could be resized easily to account for the entering or deletion of a character. Arrays were used to hold the sixletter words that were jumbled since the size would be constant throughout the program. Performance/Efficiency of Data Structures Vector can insert elements at the end of the vector with constant time O(1). This is very good for reading the words in from the text file. Vector can also search with an order of O(n) or access elements directly with O(1). The best competition for the vector in this case was list, which also inserts with constant time O(1), but lacks the ability to access elements directly. Due to this, list always has an average search time of O(n/2), which is slower than the vector for accessing elements. Map was selected because n items can be inserted with an average time of O(log (n)). The automatic sorting feature of the map made for easy lookup by key value. Also, the efficiency of the insert and find functions of map is not affected by the manner which the elements are inserted. This is compared to the binary tree which does not fit the situation as well because it is more difficult to associate the the sixletter word (the key) with its anagrams (the value) and relies on proper insertion of elements in order to be most efficient. Error Handling Mechanisms No explicit error handling mechanisms were necessary since user input was limited to pushing buttons that the program made either active or inactive. Without the opportunity for the user to provide faulty input, no potential input errors existed. However, some implicit error handling occurred while coding the GUI. In any state of the game there exists, at most, eight buttons for the user to press. At each state, the GUI controls what each button can do or cannot do and this prevents the program from doing anything undesireable due to foreign input. All controls are handled internally and, therefore, act as inherent error handling. Conclusions The goal when starting project Text Twist was to create a fun, userfriendly game that would have respectable gameplay and utilize data structures in an efficient manner. The group feels this was accomplished both by the explanations listed above and by playing the game for hours upon hours. The group feels that future improvements to Text Twist could be made by allowing user input from the keyboard and locating a better word list to lessen the occurrence of unusual words. Both of these slow gameplay slightly and would enhance the playing experience if improved upon. Finally, much was learned about the Win32 API and several C++ data structures. References Ford, William, and William Topp. Data Structures Using C++. 2nd ed. : Prentice Hall, 2001. http://www.cppreference.com C++ reference http://www.mentalis.org/apilist/apilist.php Win32 API reference Biographies Sean Devlin is a junior CS major at Notre Dame. When he is not making TextTwist, he is in the marching band and NROTC. Tim Licata is also junior Computer Science major at the University of Notre Dame. He is employed by Dome Designs, a web design company run by students, and probably spends too much of his time on nonacademic things.
© Copyright 2026 Paperzz