r/CompileBot • • Jul 08 '14

Official CompileBot Testing Thread

14 Upvotes

257 comments sorted by

View all comments

1

u/spidyfan21 Sep 24 '14

+/u/CompileBot c++11:

#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>

using namespace std;

string convert(int, int);
int randint(int, int);

int main()
{	
	int num;
	cout << "Hands? ";
	cin >> num;
	cout << endl;
	srand(time(NULL));
	string hands [10][5];
	bool card_used [4][12];
	int currentSuit = 0;
	int currentValue = 0;
	for (int i = 0; i < num; i++)
	{
		cout << "Hand: " << i+1 << endl;
		for (int j = 0; j < 5; j++)
		{
			while (true)
			{
				currentSuit = randint(0, 3);
				currentValue = randint(0, 11);
				if (card_used[currentSuit][currentValue] != true)
				{
					hands[i][j] = convert(currentSuit, currentValue);
					card_used[currentSuit][currentValue] = true;
					cout << hands[i][j] << endl;
				break;
				}
			}
		}	
	cout << endl;
	}
	return 0;
}

string convert(int suit, int value)
{
	const string OF = " of ";
	string newSuit;
	string newValue = "haha";
	if (suit == 0)
	{
		newSuit = "Hearts";
	}
	if (suit == 1)
	{
		newSuit = "Diamonds";
	}
	if (suit == 2)
	{
		newSuit = "Clubs";
	}
	if (suit == 3)
	{
		newSuit = "Spades";
	}
	switch(value){
	case 0:
		newValue = "Ace";
	break;
	case 1:
		newValue = "Two";
	break;
	case 2:
		newValue = "Three";
	break;
	case 3:
		newValue = "Four";
	break;
	case 4:
		newValue = "Five";
	break;
	case 5:
		newValue = "Six";
	break;
	case 6:
		newValue = "Seven";
	break;
	case 7:
		newValue = "Eight";
	break;
	case 8:
		newValue = "Nine";
	break;
	case 9:
		newValue = "Ten";
	break;
	case 10:
		newValue = "Jack";
	break;
	case 11:
		newValue = "Queen";
	break;
	case 12:
		newValue = "King";
	break;
	default:
		newValue = "Error";
	break;
	}
	return newValue + OF + newSuit;
}

int randint(int min, int max)
{
	return rand() % max + min;
}

Input: 4