|
|
|
#define OLC_PGE_APPLICATION
|
|
|
|
#include "pixelGameEngine.h"
|
|
|
|
#include "olcutils.h"
|
|
|
|
|
|
|
|
using namespace olc;
|
|
|
|
|
|
|
|
struct Blueprint{
|
|
|
|
int oreRobotCost,clayRobotCost,obsidianRobotCost1,obsidianRobotCost2,geodeRobotCost1,geodeRobotCost2;
|
|
|
|
};
|
|
|
|
|
|
|
|
int runSimulation(Blueprint print){
|
|
|
|
int minute=0;
|
|
|
|
int ore=0,clay=0,obsidian=0,geodes=0;
|
|
|
|
int oreRobots=1/*We start with 1 free ore robot*/,clayRobots=0,obsidianRobots=0,geodeRobots=0;
|
|
|
|
|
|
|
|
int oreRequired=print.oreRobotCost+print.clayRobotCost+print.obsidianRobotCost1+print.geodeRobotCost1;
|
|
|
|
int clayRequired=print.obsidianRobotCost2;
|
|
|
|
int obsidianRequired=print.geodeRobotCost2;
|
|
|
|
int geodeRequired=print.geodeRobotCost2;
|
|
|
|
|
|
|
|
int totalRequired=oreRequired+clayRequired+obsidianRequired+1;
|
|
|
|
|
|
|
|
float oreRatio=(float)oreRequired/totalRequired;
|
|
|
|
float clayRatio=(float)clayRequired/totalRequired;
|
|
|
|
float obsidianRatio=(float)obsidianRequired/totalRequired;
|
|
|
|
float geodeRatio=(float)1/totalRequired;
|
|
|
|
|
|
|
|
float orePct=0;
|
|
|
|
float clayPct=0;
|
|
|
|
float obsidianPct=0;
|
|
|
|
float geodePct=0;
|
|
|
|
|
|
|
|
for (int i=0;i<24;i++){
|
|
|
|
//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
|
|
|
|
ore+=oreRobots;
|
|
|
|
clay+=clayRobots;
|
|
|
|
obsidian+=obsidianRobots;
|
|
|
|
geodes+=geodeRobots;
|
|
|
|
|
|
|
|
if (oreRobots>0){
|
|
|
|
std::cout<<"Collected "<<oreRobots<<" ore ("<<ore<<")."<<std::endl;
|
|
|
|
}
|
|
|
|
if (clayRobots>0){
|
|
|
|
std::cout<<"Collected "<<clayRobots<<" clay ("<<clay<<")."<<std::endl;
|
|
|
|
}
|
|
|
|
if (obsidianRobots>0){
|
|
|
|
std::cout<<"Collected "<<obsidianRobots<<" obsidian ("<<obsidian<<")."<<std::endl;
|
|
|
|
}
|
|
|
|
if (geodeRobots>0){
|
|
|
|
std::cout<<"Collected "<<geodeRobots<<" geodes ("<<geodes<<")."<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
int totalProduction=oreRobots+clayRobots+obsidianRobots+geodeRobots;
|
|
|
|
|
|
|
|
orePct=(float)oreRobots/totalProduction;
|
|
|
|
clayPct=(float)clayRobots/totalProduction;
|
|
|
|
obsidianPct=(float)obsidianRobots/totalProduction;
|
|
|
|
geodePct=(float)geodeRobots/totalProduction;
|
|
|
|
|
|
|
|
std::cout<<"Resource distribution (Ore/Clay/Obsidian/Geode) ("<<orePct<<"/"<<clayPct<<"/"<<obsidianPct<<"/"<<geodePct<<")"<<std::endl;
|
|
|
|
std::cout<<" Target distribution (Ore/Clay/Obsidian/Geode) ("<<oreRatio<<"/"<<clayRatio<<"/"<<obsidianRatio<<"/"<<geodeRatio<<")"<<std::endl;
|
|
|
|
|
|
|
|
if (ore>=print.geodeRobotCost1&&obsidian>=print.geodeRobotCost2&&geodePct<geodeRatio){
|
|
|
|
geodeRobots++;
|
|
|
|
ore-=print.geodeRobotCost1;
|
|
|
|
obsidian-=print.geodeRobotCost2;
|
|
|
|
std::cout<<" Built a geode robot ("<<geodeRobots<<" total)"<<std::endl;
|
|
|
|
} else
|
|
|
|
if (ore>=print.obsidianRobotCost1&&clay>=print.obsidianRobotCost2&&obsidianPct<obsidianRatio){
|
|
|
|
//We can make an obsidian bot, so do so!
|
|
|
|
obsidianRobots++;
|
|
|
|
ore-=print.obsidianRobotCost1;
|
|
|
|
clay-=print.obsidianRobotCost2;
|
|
|
|
std::cout<<" Built an obsidian robot ("<<obsidianRobots<<" total)"<<std::endl;
|
|
|
|
} else
|
|
|
|
if(ore>=print.oreRobotCost&&orePct<oreRatio){
|
|
|
|
//Make an ore bot.
|
|
|
|
oreRobots++;
|
|
|
|
ore-=print.oreRobotCost;
|
|
|
|
std::cout<<" Built an ore robot ("<<oreRobots<<" total)"<<std::endl;
|
|
|
|
} else
|
|
|
|
if (ore>=print.clayRobotCost&&clayPct<clayRatio){
|
|
|
|
//Make a clay bot.
|
|
|
|
clayRobots++;
|
|
|
|
ore-=print.clayRobotCost;
|
|
|
|
std::cout<<" Built a clay robot ("<<clayRobots<<" total)"<<std::endl;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
std::cout<<" Decided not to make anything this turn..."<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return geodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
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<blueprints.size();i++){
|
|
|
|
sum+=(i+1)*runSimulation(blueprints[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|