Advertisement
lryu1

Untitled

Nov 30th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. /**
  2. * BogglePlayer class conforming to the BaseBogglePlayer interface.
  3. *
  4. * Utilizes a simple vector for storing the board.
  5. */
  6. class BogglePlayer : public BaseBogglePlayer {
  7. public:
  8. /**
  9. * Constructs a BogglePlayer with an uninitialized board and lexicon.
  10. * Both must be initialized with data before use.
  11. */
  12. BogglePlayer();
  13.  
  14. /**
  15. * Deconstructor for BogglePlayer
  16. */
  17. ~BogglePlayer();
  18.  
  19. /**
  20. * Initializes the BogglePlayer's Lexicon using the supplied word
  21. * list. Words are inserted in a case-insensitive manner.
  22. */
  23. void buildLexicon(const std::set<std::string> &word_list);
  24.  
  25. /**
  26. * Initializes the BogglePlayer's internal board representation
  27.  
  28. */
  29. void setBoard(unsigned int rows, unsigned int cols,
  30. std::string **diceArray);
  31.  
  32. /**
  33. * Populates the supplied set with the words in the BogglePlayer's
  34. * lexicon that appear on the board and are longer than
  35. * minimum_word_length.
  36. *
  37. * Returns false if either the board or the lexicon has not been
  38. * initialized. Returns true otherwise.
  39. */
  40. bool getAllValidWords(unsigned int minimum_word_length,
  41. std::set<std::string> *words);
  42.  
  43. /**
  44. * Determines if the given word is in the BogglePlayer's lexicon.
  45. * The lexicon is searched in a case-insensitive fashion.
  46. *
  47. * Returns true if the word is in the lexicon, and false if not.
  48. */
  49. bool isInLexicon(const std::string &word_to_check);
  50.  
  51. /**
  52. * Determines if the given word is on the BogglePlayer's board.
  53. * The board is searched in a case-insensitive fashion.
  54. *
  55. * Returns a vector of integers representing the positions on the board
  56. * that make up the word, if the word exists on the board. Otherwise,
  57. * returns an empty vector.
  58. */
  59. std::vector<int> isOnBoard(const std::string &word_to_check);
  60.  
  61. /**
  62. * Returns a custom board for the boggle ui. The board is loaded
  63. * from the file custboard.txt in the current working directory.
  64. * The input format is expected to follow that outlined in README_brd.
  65. */
  66. void getCustomBoard(std::string **&new_board,
  67. unsigned int *rows, unsigned int *cols);
  68.  
  69.  
  70. private:
  71. /**
  72. * Vector representing the boggle board.
  73. */
  74. std::vector<BoardPos> board;
  75.  
  76.  
  77. /**
  78. * Number of rows and columns on the boggle board.
  79. */
  80. int rows;
  81. int cols;
  82.  
  83. /**
  84. * Whether the boggle board has been initialized or not.
  85. */
  86. bool board_built;
  87.  
  88. /**
  89. * Lexicon
  90. */
  91. Trie lexicon;
  92.  
  93. /**
  94. * Whether lexicon has been built
  95. */
  96. bool lexiconBuilt;
  97.  
  98. /**
  99. * Set of all words in lexicon that appear on the board and are longer
  100. * than minimum word length
  101. */
  102. std::set<std::string> all_words;
  103.  
  104. /**
  105. * Returns a lowercase string of passed in string
  106. */
  107. std::string toLowerCase( std::string str);
  108.  
  109. /**
  110. * Recursive function to find word on board
  111. */
  112. bool findWord(int row, int col, const std::string &word, unsigned int cur,
  113. vector<int> * positions);
  114. /**
  115. * Compares string on a die to selected letters of word.
  116. * Returns true if match, else false
  117. * Used in findWord
  118. */
  119. bool compareFace(const std::string word, const std::string neighbor,
  120. int cur);
  121.  
  122. /**
  123. * Given the starting position of search, find all words that start there
  124. * and exist in lexicon. Valid words are added to the set poitned to by
  125. * words
  126. */
  127. bool searchForWords(int row, int col, std::set<std::string>* words,
  128. unsigned int min_word_length, std::string word);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement