|
|
|
#define OLC_PGE_APPLICATION
|
|
|
|
#include "pixelGameEngine.h"
|
|
|
|
#include "olcutils.h"
|
|
|
|
|
|
|
|
using namespace olc;
|
|
|
|
|
|
|
|
struct Blueprint{
|
|
|
|
int oreRobotCost,clayRobotCost,obsidianRobotCost1,obsidianRobotCost2,geodeRobotCost1,geodeRobotCost2;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Priority{
|
|
|
|
OREROBOT,
|
|
|
|
CLAYROBOT,
|
|
|
|
OBSIDIANROBOT,
|
|
|
|
};
|
|
|
|
|
|
|
|
std::string prioToName(Priority p){
|
|
|
|
switch(p){
|
|
|
|
case OREROBOT:{
|
|
|
|
return "Ore Robot";
|
|
|
|
}break;
|
|
|
|
case CLAYROBOT:{
|
|
|
|
return "Clay Robot";
|
|
|
|
}break;
|
|
|
|
case OBSIDIANROBOT:{
|
|
|
|
return "Obsidian Robot";
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string bestHistory="";
|
|
|
|
|
|
|
|
void runSimulation(Blueprint print, int minute, int ore, int clay, int obsidian, int geodes, int oreRobots, int clayRobots, int obsidianRobots, int geodeRobots, int&bestGeodes, std::string history){
|
|
|
|
for (;minute<32;minute++){
|
|
|
|
//Find out total robots needed for one geode robot.
|
|
|
|
//Geode: 2ore:19obsidian
|
|
|
|
//Obsidian 4ore:7clay
|
|
|
|
//Clay 4ore
|
|
|
|
//Ore 4ore
|
|
|
|
//std::cout<<" Minute "<<i+1<<std::endl;
|
|
|
|
|
|
|
|
//14ore:7clay:19obsidian 30
|
|
|
|
|
|
|
|
if (ore>=print.geodeRobotCost1&&obsidian>=print.geodeRobotCost2){
|
|
|
|
runSimulation(print,minute+1,ore-print.geodeRobotCost1+oreRobots,clay+clayRobots,obsidian-print.geodeRobotCost2+obsidianRobots,geodes+geodeRobots,oreRobots,clayRobots,obsidianRobots,geodeRobots+1,bestGeodes,history+"->GEO");
|
|
|
|
} else
|
|
|
|
if (ore>=print.obsidianRobotCost1&&clay>=print.obsidianRobotCost2){
|
|
|
|
runSimulation(print,minute+1,ore-print.obsidianRobotCost1+oreRobots,clay-print.obsidianRobotCost2+clayRobots,obsidian+obsidianRobots,geodes+geodeRobots,oreRobots,clayRobots,obsidianRobots+1,geodeRobots,bestGeodes,history+"->OBS");
|
|
|
|
} else {
|
|
|
|
if(ore>=print.oreRobotCost){
|
|
|
|
runSimulation(print,minute+1,ore-print.oreRobotCost+oreRobots,clay+clayRobots,obsidian+obsidianRobots,geodes+geodeRobots,oreRobots+1,clayRobots,obsidianRobots,geodeRobots,bestGeodes,history+"->ORE");
|
|
|
|
}
|
|
|
|
if (ore>=print.clayRobotCost){
|
|
|
|
runSimulation(print,minute+1,ore-print.clayRobotCost+oreRobots,clay+clayRobots,obsidian+obsidianRobots,geodes+geodeRobots,oreRobots,clayRobots+1,obsidianRobots,geodeRobots,bestGeodes,history+"->CLA");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ore+=oreRobots;
|
|
|
|
clay+=clayRobots;
|
|
|
|
obsidian+=obsidianRobots;
|
|
|
|
geodes+=geodeRobots;
|
|
|
|
|
|
|
|
history+="->WAIT";
|
|
|
|
}
|
|
|
|
if (geodes>bestGeodes){
|
|
|
|
bestGeodes=geodes;
|
|
|
|
bestHistory=history;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
std::ifstream file("input");
|
|
|
|
std::vector<Blueprint>blueprints;
|
|
|
|
while (file.good()){
|
|
|
|
std::string line;
|
|
|
|
std::getline(file,line);
|
|
|
|
std::cout<<line<<std::endl;
|
|
|
|
if (line.length()>0){
|
|
|
|
Blueprint newBlueprint;
|
|
|
|
int marker=0;
|
|
|
|
for (int i=0;i<6;i++){
|
|
|
|
marker=line.find(' ',marker+1);
|
|
|
|
}
|
|
|
|
newBlueprint.oreRobotCost=std::atoi(line.substr(marker+1,line.find(' ',marker+1)-marker).c_str());
|
|
|
|
for (int i=0;i<6;i++){
|
|
|
|
marker=line.find(' ',marker+1);
|
|
|
|
}
|
|
|
|
newBlueprint.clayRobotCost=std::atoi(line.substr(marker+1,line.find(' ',marker+1)-marker).c_str());
|
|
|
|
for (int i=0;i<6;i++){
|
|
|
|
marker=line.find(' ',marker+1);
|
|
|
|
}
|
|
|
|
newBlueprint.obsidianRobotCost1=std::atoi(line.substr(marker+1,line.find(' ',marker+1)-marker).c_str());
|
|
|
|
for (int i=0;i<3;i++){
|
|
|
|
marker=line.find(' ',marker+1);
|
|
|
|
}
|
|
|
|
newBlueprint.obsidianRobotCost2=std::atoi(line.substr(marker+1,line.find(' ',marker+1)-marker).c_str());
|
|
|
|
for (int i=0;i<6;i++){
|
|
|
|
marker=line.find(' ',marker+1);
|
|
|
|
}
|
|
|
|
newBlueprint.geodeRobotCost1=std::atoi(line.substr(marker+1,line.find(' ',marker+1)-marker).c_str());
|
|
|
|
for (int i=0;i<3;i++){
|
|
|
|
marker=line.find(' ',marker+1);
|
|
|
|
}
|
|
|
|
newBlueprint.geodeRobotCost2=std::atoi(line.substr(marker+1,line.find(' ',marker+1)-marker).c_str());
|
|
|
|
|
|
|
|
std::cout<<"Blueprint "<<blueprints.size()+1<<std::endl;
|
|
|
|
std::cout<<"Ore Robot Ore Cost: "<<newBlueprint.oreRobotCost<<std::endl;
|
|
|
|
std::cout<<"Clay Robot Ore Cost: "<<newBlueprint.clayRobotCost<<std::endl;
|
|
|
|
std::cout<<"Obsidian Robot Ore Cost: "<<newBlueprint.obsidianRobotCost1<<std::endl;
|
|
|
|
std::cout<<"Obsidian Robot Clay Cost: "<<newBlueprint.obsidianRobotCost2<<std::endl;
|
|
|
|
std::cout<<"Geode Robot Ore Cost: "<<newBlueprint.geodeRobotCost1<<std::endl;
|
|
|
|
std::cout<<"Geode Robot Obsidian Cost: "<<newBlueprint.geodeRobotCost2<<std::endl;
|
|
|
|
|
|
|
|
blueprints.push_back(newBlueprint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int sum=0;
|
|
|
|
for (int i=0;i<3;i++){
|
|
|
|
int highest=0;
|
|
|
|
bestHistory="";
|
|
|
|
std::cout<<"Running Blueprint "<<i+1<<std::endl;
|
|
|
|
runSimulation(blueprints[i],0,0,0,0,0,1,0,0,0,highest,"");
|
|
|
|
sum+=(i+1)*highest;
|
|
|
|
std::cout<<" Highest Geode Returns: "<<highest<<" ("<<bestHistory<<")"<<std::endl;
|
|
|
|
}
|
|
|
|
std::cout<<"Sum: "<<sum<<std::endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|