Skip to content

Commit

Permalink
project 2.0 complete
Browse files Browse the repository at this point in the history
finished the requirements for project 2.0 implemented a bloom filter for user occurrence, a tree for a recursive sort.  A recursive  function ( the war loop) .
  • Loading branch information
jasojone committed Jun 6, 2021
1 parent 03856ce commit c202e91
Show file tree
Hide file tree
Showing 46 changed files with 2,630 additions and 347 deletions.
723 changes: 555 additions & 168 deletions LineCounterApp/input1.txt

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion LineCounterApp/nbproject/private/private.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
</data>
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group/>
<group>
<file>file:/C:/Users/Jason/OneDrive/Documents/GitHub/Cis17c2021/LineCounterApp/main.cpp</file>
</group>
</open-files>
</project-private>
Binary file removed cis17cLabBloomFilter1.1.zip
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion cis17cLabBloomFilter1.1/nbproject/private/private.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<data xmlns="http://www.netbeans.org/ns/make-project-private/1">
<activeConfTypeElem>1</activeConfTypeElem>
<activeConfIndexElem>0</activeConfIndexElem>
<activeConfIndexElem>1</activeConfIndexElem>
</data>
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
Expand Down
4 changes: 3 additions & 1 deletion cis17cProject1.5/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ void Game::gameLoop()
do
{


//p1.printHand();
//cpu.printHand();

countAces(p1);
// Output the card total for each player.
cout << "You have " << p1.cardsWon.size()+p1.handInPlay.size() << " cards total\n";
Expand Down
Binary file modified cis17cProject1.5/dist/Debug/Cygwin-Windows/cis17cproject1.5
Binary file not shown.
70 changes: 70 additions & 0 deletions cis17cProject2.0/BloomFilter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* File: BloomFilter.cpp
* Author: Jason
*
* Created on May 31, 2021, 6:43 PM
*/
#include "BloomFilter.h"
/******************************************************************************\
bloomFilterPush
\******************************************************************************/
bool BloomFilter::bfSearch(string s)
{
return (bitarray[ELFHash(s) % BFarrSize] && bitarray[APHash(s) % BFarrSize]);
}

/******************************************************************************\
bloomFilterPush
\******************************************************************************/
void BloomFilter::bfPush(string s)
{
bitarray[ELFHash(s) % BFarrSize] = true;
bitarray[APHash(s) % BFarrSize] = true;
}

unsigned int BloomFilter::ELFHash(const std::string& str)
{
unsigned int hash = 0;
unsigned int x = 0;

for (std::size_t i = 0; i < str.length(); i++)
{
hash = (hash << 4) + str[i];
if ((x = hash & 0xF0000000L) != 0)
{
hash ^= (x >> 24);
}
hash &= ~x;
}

return hash;
}

unsigned int BloomFilter::APHash(const std::string& str)
{
unsigned int hash = 0xAAAAAAAA;

for (std::size_t i = 0; i < str.length(); i++)
{
hash ^= ((i & 1) == 0) ? ((hash << 7) ^ str[i] * (hash >> 3)) :
(~((hash << 11) + (str[i] ^ (hash >> 5))));
}

return hash;
}

void BloomFilter::getBloomData()
{
ifstream file ("bloomFilter.bin", ios::binary|ios::in);
file.read(reinterpret_cast<char *>(bitarray), sizeof(bool) * BFarrSize);
file.close();
}

void BloomFilter::pushBloomData()
{
ofstream file ("bloomFilter.bin", ios::binary|ios::out);
file.write(reinterpret_cast<char *>(bitarray), sizeof(bool) * BFarrSize);
file.close();
}
57 changes: 57 additions & 0 deletions cis17cProject2.0/BloomFilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* File: BloomFilter.h
* Author: Jason
*
* Created on May 31, 2021, 6:42 PM
*/


#ifndef BLOOMFILTER_H
#define BLOOMFILTER_H
#include "Game.h"


/******************************************************************************\
BloomFilter Class
This Class will check to see if a player has played the game before by
storing all usernames in a bloom filter bit vector. If the user has played
a welcome back will be displayed. If the user has not played the rules
menu option will be encouraged
\******************************************************************************/
#define BFarrSize 512

class BloomFilter
{

private:
bool *bitarray;
void getBloomData();//reads the bloom filter form text file
void pushBloomData();//pushes bloom data to the file

public:
BloomFilter();
~BloomFilter();
void setBFname(string s);
// search the bloom filter for user case
bool bfSearch(string s);
// set the bloom filter in the event there is a new user case
void bfPush(string s);
unsigned int ELFHash(const std::string& str);
unsigned int APHash(const std::string& str);
};

inline BloomFilter::BloomFilter()
{
bitarray = new bool[BFarrSize];
for (int i = 0; i < BFarrSize; i++)
bitarray[i] = false;
getBloomData();
}
inline BloomFilter::~BloomFilter()
{
pushBloomData();
delete[] bitarray;
}

#endif /* BLOOMFILTER_H */

1 change: 1 addition & 0 deletions cis17cProject2.0/Card.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct Card
{
string suit; // cards suit
int cPower; // power of the card to determine who will win the round
Card() {}
Card(string s, int p)// assign the power and suit when card is created
{
suit = s;
Expand Down
99 changes: 89 additions & 10 deletions cis17cProject2.0/Deck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
*/
#include "Deck.h"

/*****************************************************************************\
* Deck Constructor *
* The default constructor will create the 52 cards using the card class *
* elements *
\*****************************************************************************/
/*****************************************************************************\
Deck Constructor
The default constructor will create the 52 cards using the card class
elements
\*****************************************************************************/
Deck::Deck()
{
// Due to the decks private variable of suits being a list an iterator
Expand All @@ -29,15 +29,19 @@ Deck::Deck()
}
}
// once the deck is populated it is then shuffled for play.

//Sort using a recurisive mergeSort
mergeSort(currDeck, 0, currDeck.size()-1);

// using the random access iterator
random_shuffle(currDeck.begin(), currDeck.end());
}

/*****************************************************************************\
* dealCards *
* This function will take the deck of 52 cards and populate each players hand *
* with 26 cards each. *
\*****************************************************************************/
/*****************************************************************************\
dealCards
This function will take the deck of 52 cards and populate each players hand
with 26 cards each.
\*****************************************************************************/
void Deck::dealCards(Player &currPlayer)
{
// for loop deals the cards to each player 26 to each player
Expand All @@ -50,3 +54,78 @@ void Deck::dealCards(Player &currPlayer)
}
}

/*****************************************************************************\
merge
Merges two subvectorss of vec[] First subvectors is vec[l..m] Second subvectors is
vec[m+1..r]
\*****************************************************************************/
void Deck::merge(vector<Card> &vec, int l, int m, int r)
{
int n1 = m - l + 1;
int n2 = r - m;

// Create temp vectors
vector<Card> L(n1);
vector<Card> R(n2);

// Copy data to temp vectors
for (int i = 0; i < n1; i++)
L[i] = vec[l + i];
for (int j = 0; j < n2; j++)
R[j] = vec[m + 1 + j];

// Merge the temp vectors back into vec[l..r]

// Initial index of first subvectors
int i = 0;

// Initial index of second subvectors
int j = 0;

// Initial index of merged subvectors
int k = l;

while (i < n1 && j < n2) {
if (L[i].cPower <= R[j].cPower) {
vec[k] = L[i];
i++;
}
else {
vec[k] = R[j];
j++;
}
k++;
}

// Copy the remaining elements of
// L[], if there are any
while (i < n1) {
vec[k] = L[i];
i++;
k++;
}

// Copy the remaining elements of
// R[], if there are any
while (j < n2) {
vec[k] = R[j];
j++;
k++;
}
}


/*****************************************************************************\
mergeSort
l is for left index and r is right index of the subvectors of vec to be sorted
\*****************************************************************************/
void Deck::mergeSort(vector<Card> &vec, int l, int r) {
if (l < r)
{
int m = l + (r - l) / 2;
mergeSort(vec, l, m);
mergeSort(vec, m + 1, r);
merge(vec, l, m, r);
}
}
2 changes: 2 additions & 0 deletions cis17cProject2.0/Deck.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class Deck
public:
Deck(); // default constructor will create the deck when instantiated.
void dealCards(Player &currPlayer); // deals the card 26 per player.
void merge(vector<Card> &vec, int l, int m, int r);
void mergeSort(vector<Card> &vec, int l, int r);
};
#endif /* DECK_H */

Loading

0 comments on commit c202e91

Please sign in to comment.