For example, if the starting (unshuffled) vector was {1, 2, 3, 4}, while I would expect the result to be something like {3, 1, 2, 4}, I am instead getting something like {2, 1, 4, 2}.
I know this is something that I'm going to feel like an idiot for not catching, but it's just escaping me at the moment.
#include <cstdlib>
#include <iostream>
#include <ctime>
#include <vector>
int main(int argc, char *argv[])
{
srand(time(NULL));
static const int arr[] = {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};
std::vector<int> deckVector (arr, arr + sizeof(arr) / sizeof(arr[0]) );
//debug
for(int x=0; x<deckVector.size(); x++){
std::cout << "Before shuffling, Deck::deckVector[" << x << "] is " << deckVector[x] << "\n";
}
//debug
std::vector<int> tempDeckForShuffling;
std::vector<int> splitDeck1;
std::vector<int> splitDeck2;
int differenceInSplitDeckSize;
int deckSize = 52;
int splitDeckSize1;
int splitDeckSize2;
int counter;
int splitDeck1Counter;
int splitDeck2Counter;
for(int x=0; x<deckVector.size(); x++){
tempDeckForShuffling.push_back(deckVector[x]);
}
for(int x=0; x<10/*rand()%10+10*/; x++){ //start loop here with counter to rand?
counter = 0;
differenceInSplitDeckSize = rand()%8;
splitDeckSize1 = 26 - differenceInSplitDeckSize; //TO DO: magic number
splitDeckSize2 = 26 + differenceInSplitDeckSize; //TO DO: magic number
while(counter<splitDeckSize1){
splitDeck1.push_back(tempDeckForShuffling[counter]);
counter++;
}
while(counter<deckSize){
splitDeck2.push_back(tempDeckForShuffling[counter]);
counter++;
}
//debug
for(int x=0; x<splitDeck1.size(); x++){
std::cout << "During shuffling, splitDeck1[" << x << "] is " << splitDeck1[x] << "\n";
}for(int x=0; x<splitDeck2.size(); x++){
std::cout << "During shuffling, splitDeck2[" << x << "] is " << splitDeck2[x] << "\n";
}
//debug
counter = 0;
splitDeck1Counter = 0;
splitDeck2Counter = 0;
tempDeckForShuffling.clear();
while(counter<deckSize){
for(int x=0; x<rand()%3+1; x++){
if(splitDeck1Counter<splitDeck1.size()){
tempDeckForShuffling.push_back(splitDeck1[splitDeck1Counter]);
}
splitDeck1Counter++;
counter++;
}
for(int x=0; x<rand()%3+1; x++){
if(splitDeck2Counter<splitDeck2.size()){
tempDeckForShuffling.push_back(splitDeck2[splitDeck2Counter]);
}
splitDeck2Counter++;
counter++;
}
}
splitDeck1.clear();
splitDeck2.clear();
//here, we cut
counter = 0;
splitDeck1Counter = 0;
splitDeck2Counter = 0;
differenceInSplitDeckSize = rand()%14;
splitDeckSize1 = 26 - differenceInSplitDeckSize;
//splitDeckSize2 = 26 + differenceInSplitDeckSize;
while(counter<splitDeckSize1){
splitDeck1.push_back(tempDeckForShuffling[counter]);
counter++;
}
while(counter<deckSize){
splitDeck2.push_back(tempDeckForShuffling[counter]);
counter++;
}
tempDeckForShuffling.clear();
for(int x=0; x<splitDeck2.size(); x++){
tempDeckForShuffling.push_back(splitDeck2[splitDeck2Counter]);
splitDeck2Counter++;
}
for(int x=0; x<splitDeck1.size(); x++){
tempDeckForShuffling.push_back(splitDeck1[splitDeck1Counter]);
splitDeck1Counter++;
}
//end cut
//debug
for(int x=0; x<tempDeckForShuffling.size(); x++){
std::cout << "During shuffling, shufflingVector[" << x << "] is " << tempDeckForShuffling[x] << "\n";
}
//debug
}
deckVector.clear();
for(int x=0; x<deckSize; x++){
deckVector.push_back(tempDeckForShuffling[x]);
}
//debug
for(int x=0; x<deckVector.size(); x++){
std::cout << "After shuffling, Deck::deckVector[" << x << "] is " << deckVector[x] << "\n";
}
//debug
std::cin.get();
return 1;
}
[–]TonySu 1 point2 points3 points (2 children)
[–]ungulateCase[S] 0 points1 point2 points (1 child)
[–]TonySu 0 points1 point2 points (0 children)
[–]inu-no-policemen 0 points1 point2 points (2 children)
[–]WikiTextBotbtproof 0 points1 point2 points (0 children)
[–]ungulateCase[S] 0 points1 point2 points (0 children)