generated from sigonasr2/CPlusPlusProjectTemplate
Part 1 done!
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
d2a9653834
commit
a72d6b72e2
Binary file not shown.
123
main.cpp
123
main.cpp
@ -8,95 +8,64 @@ struct Blueprint{
|
|||||||
int oreRobotCost,clayRobotCost,obsidianRobotCost1,obsidianRobotCost2,geodeRobotCost1,geodeRobotCost2;
|
int oreRobotCost,clayRobotCost,obsidianRobotCost1,obsidianRobotCost2,geodeRobotCost1,geodeRobotCost2;
|
||||||
};
|
};
|
||||||
|
|
||||||
int runSimulation(Blueprint print){
|
enum Priority{
|
||||||
int minute=0;
|
OREROBOT,
|
||||||
int ore=0,clay=0,obsidian=0,geodes=0;
|
CLAYROBOT,
|
||||||
int oreRobots=1/*We start with 1 free ore robot*/,clayRobots=0,obsidianRobots=0,geodeRobots=0;
|
OBSIDIANROBOT,
|
||||||
|
};
|
||||||
|
|
||||||
int oreRequired=print.oreRobotCost+print.clayRobotCost+print.obsidianRobotCost1+print.geodeRobotCost1;
|
std::string prioToName(Priority p){
|
||||||
int clayRequired=print.obsidianRobotCost2;
|
switch(p){
|
||||||
int obsidianRequired=print.geodeRobotCost2;
|
case OREROBOT:{
|
||||||
int geodeRequired=print.geodeRobotCost2;
|
return "Ore Robot";
|
||||||
|
}break;
|
||||||
|
case CLAYROBOT:{
|
||||||
|
return "Clay Robot";
|
||||||
|
}break;
|
||||||
|
case OBSIDIANROBOT:{
|
||||||
|
return "Obsidian Robot";
|
||||||
|
}break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int totalRequired=oreRequired+clayRequired+obsidianRequired+1;
|
std::string bestHistory="";
|
||||||
|
|
||||||
float oreRatio=(float)oreRequired/totalRequired;
|
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){
|
||||||
float clayRatio=(float)clayRequired/totalRequired;
|
for (;minute<32;minute++){
|
||||||
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.
|
//Find out total robots needed for one geode robot.
|
||||||
//Geode: 2ore:19obsidian
|
//Geode: 2ore:19obsidian
|
||||||
//Obsidian 4ore:7clay
|
//Obsidian 4ore:7clay
|
||||||
//Clay 4ore
|
//Clay 4ore
|
||||||
//Ore 4ore
|
//Ore 4ore
|
||||||
std::cout<<"Minute "<<i+1<<std::endl;
|
//std::cout<<" Minute "<<i+1<<std::endl;
|
||||||
|
|
||||||
//14ore:7clay:19obsidian 30
|
//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;
|
ore+=oreRobots;
|
||||||
clay+=clayRobots;
|
clay+=clayRobots;
|
||||||
obsidian+=obsidianRobots;
|
obsidian+=obsidianRobots;
|
||||||
geodes+=geodeRobots;
|
geodes+=geodeRobots;
|
||||||
|
|
||||||
if (oreRobots>0){
|
history+="->WAIT";
|
||||||
std::cout<<"Collected "<<oreRobots<<" ore ("<<ore<<")."<<std::endl;
|
|
||||||
}
|
}
|
||||||
if (clayRobots>0){
|
if (geodes>bestGeodes){
|
||||||
std::cout<<"Collected "<<clayRobots<<" clay ("<<clay<<")."<<std::endl;
|
bestGeodes=geodes;
|
||||||
|
bestHistory=history;
|
||||||
}
|
}
|
||||||
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()
|
int main()
|
||||||
@ -147,9 +116,15 @@ int main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
int sum=0;
|
int sum=0;
|
||||||
for (int i=0;i<blueprints.size();i++){
|
for (int i=0;i<3;i++){
|
||||||
sum+=(i+1)*runSimulation(blueprints[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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user