diff --git a/C++ProjectTemplate b/C++ProjectTemplate index c1aa29d..273b5a0 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/input b/input new file mode 100644 index 0000000..242b6dd --- /dev/null +++ b/input @@ -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. diff --git a/main.cpp b/main.cpp index 8ab7e53..45c4e3c 100644 --- a/main.cpp +++ b/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 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; +struct Blueprint{ + int oreRobotCost,clayRobotCost,obsidianRobotCost1,obsidianRobotCost2,geodeRobotCost1,geodeRobotCost2; +}; - 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; +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 "<0){ + std::cout<<"Collected "<0){ + std::cout<<"Collected "<0){ + std::cout<<"Collected "<0){ + std::cout<<"Collected "<{originPoint+velocity,5},olc::utils::geom2d::rect{{32,32},{64,32}})) { - originPoint+=velocity; - DrawCircle(originPoint,5); + 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) ("<=print.geodeRobotCost1&&obsidian>=print.geodeRobotCost2&&geodePct=print.obsidianRobotCost1&&clay>=print.obsidianRobotCost2&&obsidianPct=print.oreRobotCost&&orePct=print.clayRobotCost&&clayPct{{32,32},{64,32}},contact_point,contact_normal,t_hit_near)&&t_hit_near<1?YELLOW:WHITE); - return true; - } -}; - + } + return geodes; +} int main() { - Example demo; - if (demo.Construct(128, 120, 8, 8)) - demo.Start(); + std::ifstream file("input"); + std::vectorblueprints; + while (file.good()){ + std::string line; + std::getline(file,line); + std::cout<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 "<