generated from sigonasr2/CPlusPlusProjectTemplate
Basic framework setup
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
29e05ef75f
commit
d2a9653834
Binary file not shown.
30
input
Normal file
30
input
Normal file
@ -0,0 +1,30 @@
|
||||
Blueprint 1: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 7 clay. Each geode robot costs 2 ore and 19 obsidian.
|
||||
Blueprint 2: Each ore robot costs 2 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 20 clay. Each geode robot costs 4 ore and 18 obsidian.
|
||||
Blueprint 3: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 20 clay. Each geode robot costs 2 ore and 10 obsidian.
|
||||
Blueprint 4: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 19 clay. Each geode robot costs 2 ore and 12 obsidian.
|
||||
Blueprint 5: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 20 clay. Each geode robot costs 3 ore and 14 obsidian.
|
||||
Blueprint 6: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 15 clay. Each geode robot costs 3 ore and 7 obsidian.
|
||||
Blueprint 7: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 2 ore and 19 clay. Each geode robot costs 2 ore and 20 obsidian.
|
||||
Blueprint 8: Each ore robot costs 2 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 13 clay. Each geode robot costs 2 ore and 20 obsidian.
|
||||
Blueprint 9: Each ore robot costs 2 ore. Each clay robot costs 2 ore. Each obsidian robot costs 2 ore and 8 clay. Each geode robot costs 2 ore and 14 obsidian.
|
||||
Blueprint 10: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 11 clay. Each geode robot costs 3 ore and 14 obsidian.
|
||||
Blueprint 11: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 5 clay. Each geode robot costs 4 ore and 8 obsidian.
|
||||
Blueprint 12: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 2 ore and 16 clay. Each geode robot costs 2 ore and 18 obsidian.
|
||||
Blueprint 13: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 11 clay. Each geode robot costs 2 ore and 10 obsidian.
|
||||
Blueprint 14: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 14 clay. Each geode robot costs 3 ore and 17 obsidian.
|
||||
Blueprint 15: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 19 clay. Each geode robot costs 3 ore and 17 obsidian.
|
||||
Blueprint 16: Each ore robot costs 2 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 20 clay. Each geode robot costs 2 ore and 17 obsidian.
|
||||
Blueprint 17: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 14 clay. Each geode robot costs 4 ore and 8 obsidian.
|
||||
Blueprint 18: Each ore robot costs 2 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 9 clay. Each geode robot costs 3 ore and 9 obsidian.
|
||||
Blueprint 19: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 10 clay. Each geode robot costs 3 ore and 14 obsidian.
|
||||
Blueprint 20: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 2 ore and 13 clay. Each geode robot costs 3 ore and 12 obsidian.
|
||||
Blueprint 21: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 4 ore and 15 clay. Each geode robot costs 4 ore and 9 obsidian.
|
||||
Blueprint 22: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 20 clay. Each geode robot costs 2 ore and 12 obsidian.
|
||||
Blueprint 23: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 4 ore and 19 clay. Each geode robot costs 4 ore and 12 obsidian.
|
||||
Blueprint 24: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 15 clay. Each geode robot costs 3 ore and 8 obsidian.
|
||||
Blueprint 25: Each ore robot costs 2 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 11 clay. Each geode robot costs 2 ore and 16 obsidian.
|
||||
Blueprint 26: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 17 clay. Each geode robot costs 3 ore and 7 obsidian.
|
||||
Blueprint 27: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 7 clay. Each geode robot costs 3 ore and 20 obsidian.
|
||||
Blueprint 28: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 10 clay. Each geode robot costs 2 ore and 10 obsidian.
|
||||
Blueprint 29: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 17 clay. Each geode robot costs 2 ore and 13 obsidian.
|
||||
Blueprint 30: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 4 ore and 20 clay. Each geode robot costs 4 ore and 8 obsidian.
|
||||
216
main.cpp
216
main.cpp
@ -4,86 +4,152 @@
|
||||
|
||||
using namespace olc;
|
||||
|
||||
class Example : public olc::PixelGameEngine
|
||||
{
|
||||
public:
|
||||
Example()
|
||||
{
|
||||
sAppName = "Example";
|
||||
}
|
||||
|
||||
public:
|
||||
bool RayVsRect(const vf2d ray_origin, const vf2d ray_dir, const olc::utils::geom2d::rect<float> target, vf2d&contact_point, vf2d&contact_normal, float&t_hit_near){
|
||||
|
||||
contact_normal = { 0, 0 };
|
||||
contact_point = { 0, 0 };
|
||||
|
||||
vf2d t_near = {(target.pos.x - ray_origin.x) / ray_dir.x, (target.pos.y - ray_origin.y) / ray_dir.y};
|
||||
vf2d t_far = {(target.pos.x + target.size.x - ray_origin.x) / ray_dir.x, (target.pos.y + target.size.y - ray_origin.y) / ray_dir.y};
|
||||
|
||||
if (t_near.x > t_far.x) {float b; b = t_near.x; t_near.x = t_far.x; t_far.x = b;};
|
||||
if (t_near.y > t_far.y) {float b; b = t_near.y; t_near.y = t_far.y; t_far.y = b;};
|
||||
|
||||
if (t_near.x > t_far.y || t_near.y > t_far.x) return false;
|
||||
|
||||
t_hit_near = fmax(t_near.x, t_near.y);
|
||||
float t_hit_far = fmin(t_far.x, t_far.y);
|
||||
|
||||
if (t_hit_far < 0) return false;
|
||||
|
||||
contact_point.x = ray_origin.x + t_hit_near * ray_dir.x;
|
||||
contact_point.y = ray_origin.y + t_hit_near * ray_dir.y;
|
||||
|
||||
if (t_near.x > t_near.y)
|
||||
if ( 1.0f / ray_dir.x < 0)
|
||||
contact_normal = { 1, 0 };
|
||||
else
|
||||
contact_normal = { -1, 0};
|
||||
else
|
||||
if ( t_near.x < t_near.y)
|
||||
if ( 1.0f / ray_dir.y < 0)
|
||||
contact_normal = { 0, 1 };
|
||||
else
|
||||
contact_normal = { 0, -1 };
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
vf2d originPoint={16,16};
|
||||
bool OnUserCreate() override
|
||||
{
|
||||
// Called once at the start, so create things here
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OnUserUpdate(float fElapsedTime) override
|
||||
{
|
||||
vf2d velocity={(GetKey(D).bHeld-GetKey(A).bHeld)*20*fElapsedTime,(GetKey(S).bHeld-GetKey(W).bHeld)*20*fElapsedTime};
|
||||
vf2d contact_point;
|
||||
vf2d contact_normal;
|
||||
float t_hit_near;
|
||||
|
||||
Clear(Pixel(64,64,255));
|
||||
if (!olc::utils::geom2d::overlaps(olc::utils::geom2d::circle<float>{originPoint+velocity,5},olc::utils::geom2d::rect<float>{{32,32},{64,32}})) {
|
||||
originPoint+=velocity;
|
||||
DrawCircle(originPoint,5);
|
||||
} else {
|
||||
DrawCircle(originPoint,5,RED);
|
||||
}
|
||||
DrawLine(originPoint,GetMousePos());
|
||||
|
||||
DrawRect({32,32},{64,32},RayVsRect(originPoint, GetMousePos()-originPoint, olc::utils::geom2d::rect<float>{{32,32},{64,32}},contact_point,contact_normal,t_hit_near)&&t_hit_near<1?YELLOW:WHITE);
|
||||
return true;
|
||||
}
|
||||
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()
|
||||
{
|
||||
Example demo;
|
||||
if (demo.Construct(128, 120, 8, 8))
|
||||
demo.Start();
|
||||
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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user