// TODO: use inheritance from Problem and abstract method Solve static public void SolveAll2(int limit = 1, bool runTooSlow = false) { using (StreamWriter sw = new StreamWriter("results.txt")) { Assembly assembly = Assembly.GetExecutingAssembly(); List <Type> types = GetTypesInNamespace(assembly, "ProjectEuler") .Where(x => x.Name.StartsWith("Problem") && x.GetMethods().Any(y => y.Name == "Solve")) .Select(x => new { number = Convert.ToInt32(x.Name.Substring(7)), type = x }) .Where(x => x.number >= limit) .OrderBy(x => x.number) .Select(x => x.type).ToList(); foreach (Type type in types) { try { object problem = assembly.CreateInstance(type.FullName); MethodInfo solve = type.GetMethod("Solve"); UnderConstruction underConstruction = Attribute.GetCustomAttribute(solve, typeof(UnderConstruction)) as UnderConstruction; TooSlow tooSlow = Attribute.GetCustomAttribute(solve, typeof(TooSlow)) as TooSlow; if (underConstruction == null && (tooSlow == null || runTooSlow)) { string result; TimeSpan begin = Process.GetCurrentProcess().TotalProcessorTime; if (solve.GetParameters().Length > 0) { string parameter = Path.Combine(@"D:\GitHub\ProjectEuler\Datas", String.Format("{0}.txt", type.Name.ToLower())); result = solve.Invoke(problem, new object[] { parameter }).ToString(); } else { result = solve.Invoke(problem, null).ToString(); } TimeSpan end = Process.GetCurrentProcess().TotalProcessorTime; Console.WriteLine("{0}: {1:0}ms -> {2}", type.Name, (end - begin).TotalMilliseconds, result); sw.WriteLine("{0}: {1:0}ms -> {2}", type.Name, (end - begin).TotalMilliseconds, result); } else { Console.WriteLine("{0}: {1}", type.Name, underConstruction == null ? "too slow" : "under construction"); sw.WriteLine("{0}: {1}", type.Name, underConstruction == null ? "too slow" : "under construction"); } } catch (Exception ex) { Console.WriteLine("{0}: exception {1}", type.Name, ex.ToString()); sw.WriteLine("{0}: exception {1}", type.Name, ex.ToString()); } sw.Flush(); } } }
public void BuildShip(UnderConstruction f, Empire e) { InstantiateFleet fleet = new InstantiateFleet(); CreateConstruction b = new CreateConstruction(f, e); e.construction.Add(b); b.Start(); //e.underConstruction.Remove(f); }
public void Finish() { UnderConstruction cr = entity.getComponent <UnderConstruction>(); for (int x = 0; x < size.X; x++) { for (int y = 0; y < size.Y; y++) { cr.RemoveConstructionRenderer(new Vector2(x, y)); } } }
static public void SolveAll(bool runTooSlow = false) { using (StreamWriter sw = new StreamWriter("results.txt")) { Assembly assembly = Assembly.GetExecutingAssembly(); Type problemBaseType = typeof(ProblemBase); List <ProblemBase> problems = GetTypesInNamespace(assembly, "ProjectEuler") .Where(x => x.IsSubclassOf(problemBaseType)) .Select(x => assembly.CreateInstance(x.FullName) as ProblemBase) .OrderBy(x => x.Id).ToList(); foreach (ProblemBase problem in problems) { Type type = problem.GetType(); try { MethodInfo solve = type.GetMethod("Solve"); UnderConstruction underConstruction = Attribute.GetCustomAttribute(solve, typeof(UnderConstruction)) as UnderConstruction; TooSlow tooSlow = Attribute.GetCustomAttribute(solve, typeof(TooSlow)) as TooSlow; if (underConstruction == null && (tooSlow == null || runTooSlow)) { string result; TimeSpan begin = Process.GetCurrentProcess().TotalProcessorTime; if (solve.GetParameters().Length > 0) { string parameter = Path.Combine(@"D:\GitHub\ProjectEuler\Datas", String.Format("{0}.txt", type.Name.ToLower())); result = solve.Invoke(problem, new object[] { parameter }).ToString(); } else { result = solve.Invoke(problem, null).ToString(); } TimeSpan end = Process.GetCurrentProcess().TotalProcessorTime; Console.WriteLine("{0}: {1:0}ms -> {2}", type.Name, (end - begin).TotalMilliseconds, result); sw.WriteLine("{0}: {1:0}ms -> {2}", type.Name, (end - begin).TotalMilliseconds, result); } else { Console.WriteLine("{0}: {1}", type.Name, underConstruction == null ? "too slow" : "under construction"); sw.WriteLine("{0}: {1}", type.Name, underConstruction == null ? "too slow" : "under construction"); } } catch (Exception ex) { Console.WriteLine("{0}: exception {1}", type.Name, ex); sw.WriteLine("{0}: exception {1}", type.Name, ex); } sw.Flush(); } } }
public CreateConstruction(UnderConstruction f, Empire e) { float modifier = 0; under = f.f; emp = e; system = emp.getHomeworldPlanet().getSystem(); InstantiateFleet fleet = new InstantiateFleet(); id = f.id; name = f.f.name + "-" + id; type = f.f.name; model = f.f.model; acceleration = f.f.acceleration; maxSpeed = f.f.maxSpeed; targetSpeed = f.f.targetSpeed; level = f.f.level; maxCrew = f.f.maxCrew; firepower = f.f.firepower * (f.f.level + 1); horsepower = f.f.horsepower; TransportCap = f.f.TransportCap * (f.f.level + 1);; maintenance = f.f.maintenance * (f.f.level + 1); if (emp.hasAttribute(32)) { float mod2 = Attributes.getAttribute(32).attrValue2; maintenance += maintenance * mod2; } cost = f.f.cost * (f.f.level + 1); maxHealth = f.f.maxHealth * (f.f.level + 1); if (emp.hasAttribute(66)) { float mod2 = Attributes.getAttribute(66).attrValue; maxHealth += Mathf.RoundToInt(maxHealth * mod2); } daysToBuild = f.f.daysToBuild; health = maxHealth; crew = maxCrew; marines = 0; army = 0; rotateModel = f.f.rotateModel; shipClass = f.f.shipClass; }
public bool IsConstructed(Vector2 tilePosition, bool isWorldSpace) { if (isWorldSpace) { tilePosition = WorldSpaceToLocalSpace(tilePosition); } UnderConstruction underConstruction = entity.getComponent <UnderConstruction>(); if (underConstruction == null) { return(true); } return(underConstruction.IsTileBuilt(tilePosition, false)); }
public ActionResult UnderConstruction(UnderConstruction model) { return(RedirectToAction("Index")); /*if (ModelState.IsValid) * { * if (!string.IsNullOrEmpty(model.EmailAddress)) * { * _underConstructionService.Add(model); * this.SuccessNotification("Thank You for Subscribing. You will receive an email with updates very soon."); * } * else * { * this.ErrorNotification("The email address entered is invalid"); * } * } * * return View();*/ }