-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathletterrush.h
180 lines (152 loc) · 4.63 KB
/
letterrush.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// Letter Rush, a personal project by Daniel Nguyen
// https://github.com/danielvnguyen/LetterRush
#pragma once
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm> // for count
#include <stdlib.h> // for rand, srand
#include <time.h> // for sleep
#include <unistd.h> // for difftime
using namespace std;
// hashTable class to hold all of the valid words/strings:
class hashTable
{
private:
// dynamic string array to hold the dictionary
string* stringArray;
// max size of the underlying array
int arraySize;
// current size of the underlying array
int currentSize;
/*
We are using a double hashing method for open
addressing and dealing with collisions. this
value will be used in the second hash function.
*/
int hashTwoValue;
// Helper functions:
/*
PARAM: value - an integer number
POST: returns true if the given value is a prime number, false otherwise.
*/
bool isPrime(int value);
/*
PARAM: value - an integer number
POST: returns the next prime number greater than the given value
*/
int findGreaterPrime(int value);
/*
PARAM:
inputstring - a <string> object representing a word/characters
value - an integer number
POST: returns a value corresponding to the input string. Uses
Horner's Method and the modulo operator to avoid overflow.
*/
int hornerMethod(string inputString, int value);
/*
PARAM: inputString - a <string> object representing a word/characters
POST: returns string value of the input string as an integer
*/
int hashFunctionOne(string inputString);
/*
PARAM: inputString - a <string> object representing a word/characters
POST: returns an integer used to deal with collisions in the hash table
*/
int hashFunctionTwo(string inputString);
/*
PARAM: inputString - a <string> object representing a word/characters
POST: a function that helps insert the input string into the correct position in the array
*/
void insertHelper(string inputString);
public:
/*
PARAM: N/A
POST: initializes all of the attributes for a hash table object
*/
hashTable();
/*
PARAM: size - an integer number
POST: initializes all of the attributes for a hash table object, with a specific size
*/
hashTable(int size);
/*
PARAM: N/A
POST: deallocates the space for the underlying array attribute
*/
~hashTable();
/*
PARAM: inputstring - a <string> object representing a word/characters
POST: inserts the given string into the correct position in the underlying array
of the calling object. If the load factor is above 0.50, the size will be
doubled and every current string will be repositioned.
*/
void insert(string inputString);
/*
PARAM: inputstring - a <string> object representing a word/characters
POST: returns true if the given string is found in the hash table, false otherwise.
*/
bool find(string inputString);
/*
PARAM: N/A
POST: returns load factor of the hash table
*/
double loadFactor();
/*
PARAM: N/A
POST: prints every element in the hash table, along with the index position
*/
void printTable();
/*
PARAM: N/A
POST: returns a random element within the hash table
*/
string chooseRandom();
};
// Player class
class Player
{
private:
public:
int lives;
int score;
string nickname;
/*
PARAM: N/A
POST: initializes the attributes for the player object
*/
Player();
/*
PARAM: playerName - a <string> object representing the player's nickname
POST: initializes the attributes for the player object, along with a nickname
*/
Player(string playerName);
};
// Game helper functions:
/*
PARAM:
usedWords - a string vector reference object
inputstring - a <string> object representing a word/characters
POST: checks if the given input string is already in the vector object
*/
bool duplicateCheck(vector<string> & usedWords, string inputString);
/*
PARAM: N/A
POST: returns true if the player would like to continue to another round, false otherwise.
*/
bool nextRoundCheck();
/*
PARAM:
list - a pointer to a Player object
size - an integer number
POST: returns true if theres sufficient players remaining, false otherwise.
*/
bool checkPlayers(Player* list, int size);
/*
PARAM:
inputstring - a <string> object representing a word/characters
character - a <string> object representing a word/characters
POST: checks if the input string contains the given character(s)
*/
bool characterCheck(string inputString, string character);