[ create a new paste ] login | about

Link: http://codepad.org/DJ2i2HNQ    [ raw code | fork ]

C++, pasted on Sep 15:
//step 1: play towers
//step 2: play elites
//step 3: play dragons
//step 4: play eaters if have 3 or more
//step 5: play fahrenheit if not active
//step 6: play eaters
//test out 1 fahrenheit, 2 fahrenheit
//test out various speeds of winning
//shield advantages balance out the poison survivability
//assume opponent not healing, bouncing, killing, changing your mana, etc

#include <iostream>
#include <cstdlib>

using namespace std;

int play(int, int, int); //number of elites, fahrenheit, eaters

//0 is tower, 1 is elites, 2 is regular dragon, 3 is fahrenheit, 4 is eaters
int randomdeck[30]; //I don't want to recreate this every time I run play
int turn; //same thing, rand() is expensive
short data[7][4][7][1000];
int final[7][4][7];

int main()
{
	for (int trials = 0; trials <= 999; trials++)
	{
		//generation
		for (int incrementor = 0; incrementor <= 29; incrementor++)
			randomdeck[incrementor] = (rand() >> 4) % (30 - incrementor);
		turn = (rand() >> 4) % 2;

		for (int elites = 0; elites <= 6; elites++)
			for (int fahrenheit = 0; fahrenheit <= 3; fahrenheit++)
				for (int eaters = 0; eaters <= 6; eaters++)
					data[elites][fahrenheit][eaters][trials] = play(elites, fahrenheit, eaters);
	}

	//displaying
	for (int elites = 0; elites <= 6; elites++)
		for (int fahrenheit = 0; fahrenheit <= 3; fahrenheit++)
			for (int eaters = 0; eaters <= 6; eaters++)
			{
				for (int trials = 0; trials <= 999; trials++)
					final[elites][fahrenheit][eaters] += data[elites][fahrenheit][eaters][trials];
				cout << elites << " elites, " << fahrenheit << " fahrenheits, " << eaters << " eaters | " << final[elites][fahrenheit][eaters] << '\n';
			}

	cin.get();
}

int play(int elites, int fahrenheit, int eaters)
{
	int dragons = 6 - elites;
	int deck[30];
	int hand[5] = {0, 0, 0, 0, 0}; //same as above
	int tempholder;
	int incrementor;
	for (incrementor = 0; incrementor <= 29; incrementor++)
	{
		if (randomdeck[incrementor] < elites)
		{
			deck[incrementor] = 1;
			elites--;
		}
		else if (randomdeck[incrementor] < elites + dragons)
		{
			deck[incrementor] = 2;
			dragons--;
		}
		else if (randomdeck[incrementor] < elites + dragons + fahrenheit)
		{
			deck[incrementor] = 3;
			fahrenheit--;
		}
		else if (randomdeck[incrementor] < elites + dragons + fahrenheit + eaters)
		{
			deck[incrementor] = 4;
			eaters--;
		}
		else deck[incrementor] = 0;
	}

	//starting the game
	int currentposition; //you are going to draw card 22, in terms of the array
	for (incrementor = 0; incrementor < 7; incrementor++)
	{
		hand[deck[incrementor]]++;
	}

	//turncount = 22 - turn - currentposition
	if (turn) //draw another card
	{
		hand[deck[22]]++;
		currentposition = 21;
	}
	else {
		currentposition = 22;
	}

	int quantums = 0;
	int generators = 1; //the mark
	int damage = 0;
	int fahrenactive = 0; //is fahrenheit active?

	//iteration
	for (int lifepoints = 100; lifepoints > 0;)
	{
		//remove extra fahrenheits
		hand[3] = hand[3] && (!fahrenactive);

		//play the towers first
		while (hand[0])
		{
			quantums++;
			generators++;
			hand[0]--;
		}

		//play an elite if possible
		if (quantums >= 12 && hand[1])
		{
			quantums -= 12;
			damage += 15;
		}
		//play a regular dragon if possible
		else if (quantums >= 10 && hand[2])
		{
			quantums -= 10;
			damage += 12;
		}
		//play eaters if have 3 or more
		while (quantums >= 3 && hand[4] >= 3)
		{
			quantums -= 3;
			generators += 3;
			damage += 6;
		}
		//play the fahrenheit
		if (hand[3] && quantums >= 3)
		{
			quantums -= 3;
			fahrenactive = 1;
		}
		//play rest of the eaters
		while (hand[4] && quantums)
		{
			quantums -= 1;
			generators += 1;
			damage += 2;
		}

		//generate quantums
		quantums += generators;
		//if hand is full, toss a dragon if you have 3 or more, or else an ash eater
		//two fahrenheits is not possible
		if (hand[0] + hand[1] + hand[2] + hand[3] == 8)
		{
			if (hand[1] + hand[2] >= 3)
			{
				if (hand[2])
					hand[2]--;
				else hand[1]--;
			}
			else hand[3]--;
		}

		//draw and update decksize
		hand[deck[currentposition]]++;
		currentposition--;

		//attack (fahrenheit works after quantum generation)
		lifepoints -= damage;
		if (fahrenactive)
			lifepoints -= 5 + int(quantums / 5);
	}
	return 22 - turn - currentposition;
}


Create a new paste based on this one


Comments: