static void Main(string[] args) { string[] inputs; int projectCount = int.Parse(Console.ReadLine()); for (int i = 0; i < projectCount; i++) { var projects = Molecules.Parse(Console.ReadLine().Split(' '), 0); } // game loop while (true) { var gs = new GameState(); for (int i = 0; i < 2; i++) { inputs = Console.ReadLine().Split(' '); gs.Robots.Add(Robot.Parse(i, inputs)); } inputs = Console.ReadLine().Split(' '); gs.Available = Molecules.Parse(inputs, 0); int sampleCount = int.Parse(Console.ReadLine()); for (int i = 0; i < sampleCount; i++) { inputs = Console.ReadLine().Split(' '); gs.Samples.Add(Sample.Parse(inputs)); } // Write an action using Console.WriteLine() // To debug: Console.Error.WriteLine("Debug messages..."); var r = gs.Robots[0]; var robotBank = r.Storage + r.Expertise; foreach (var sample in r.PrioritySamples(gs)) { if (robotBank.CanSubtract(sample.Cost)) { Console.Error.WriteLine($"take {sample.Cost}"); robotBank -= sample.Cost; } else { var deficit = robotBank.Deficit(sample.Cost); Console.Error.WriteLine($"deficit: {deficit}"); } } var decision = Minimax.DecideMove(gs); if (decision == null) { Console.WriteLine("WAIT"); } else { decision.Execute(gs); } } }
// IF THE ABOVE REFUSE TO WORK AT ALL: OLD CODE //private void AddFixedJoint(GameObject connectedObject, int connections) //{ // FixedJoint fx = gameObject.AddComponent<FixedJoint>(); // fx.breakForce = 2000; // fx.breakTorque = 2000; // //----- her ------ // // is this needed? // //connectedObject.transform.position = transform.position; // fx.autoConfigureConnectedAnchor = true; // fx.enableCollision = false; // fx.connectedBody = connectedObject.GetComponent<Rigidbody>(); //} void OnJointBreak(float breakForce) { GameObject go = GameObject.Find("SingletonController"); Molecules other = (Molecules)go.GetComponent(typeof(Molecules)); int connections = other.GetBindingConnections(gameObject.GetInstanceID()); other.SetBindingConnections(--connections, gameObject.GetInstanceID()); gameObject.GetComponent <FixedJoint>().enableCollision = true; // This is why we need to check which atom or joint that is broken. quick fix is done here atm(maybe) // This maybe even need to be in update function or something, // the join may not be broken her yet... they will be null when broken if (fixedJoint_right == null) { hasConnectionRight = false; } if (fixedJoint_left == null) { hasConnectionLeft = false; } GetComponent <Rigidbody>().velocity = new Vector3(0, 0, 0); GetComponent <Rigidbody>().angularVelocity = new Vector3(0, 0, 0); }
private void ReleaseObject() { if (GetComponent <FixedJoint>()) { GetComponent <FixedJoint>().connectedBody = null; Destroy(GetComponent <FixedJoint>()); } if (objectInHand.tag == "Atom" || objectInHand.tag == "Binding") { objectInHand.GetComponent <Rigidbody>().velocity = Vector3.zero; objectInHand.GetComponent <Rigidbody>().angularVelocity = Vector3.zero; } else { objectInHand.GetComponent <Rigidbody>().velocity = mController.velocity; objectInHand.GetComponent <Rigidbody>().angularVelocity = mController.angularVelocity; } GameObject go = GameObject.Find("SingletonController"); Molecules other = (Molecules)go.GetComponent(typeof(Molecules)); other.stopMovement(); objectInHand = null; }
public virtual IEnumerable <IMoleculeStartValue> AllPresentMoleculeValues() { var moleculeNames = Molecules.Select(x => x.Name); return(MoleculeStartValues.Where(msv => moleculeNames.Contains(msv.MoleculeName)) .Where(msv => msv.IsPresent)); }
public void TestItShouldFind28RingsInCubane() { IAtomContainer cubane = Molecules.CreateCubane(); var rings = finder.FindRings(cubane); Assert.AreEqual(28, rings.Count()); }
public void TestItShouldFindThreeRingsInNaphthalene() { IAtomContainer naphthalene = Molecules.CreateNaphthalene(); var rings = finder.FindRings(naphthalene); Assert.AreEqual(3, rings.Count()); }
public void TestItShoudFindOneRingInBenzene() { IAtomContainer benzene = Molecules.CreateBenzene(); var rings = finder.FindRings(benzene); Assert.AreEqual(1, rings.Count()); }
private void AddNewMols() { while (AllAtoms.Count(a => a.Parent == null) > 0) { Atom seed = AllAtoms.First(a => a.Parent == null); Molecule m = new Molecule(seed); Molecules.Add(m); } }
public Molecules Deficit(Molecules o) { return(new Molecules { A = (sbyte)Math.Min(0, A - o.A), B = (sbyte)Math.Min(0, B - o.B), C = (sbyte)Math.Min(0, C - o.C), D = (sbyte)Math.Min(0, D - o.D), E = (sbyte)Math.Min(0, E - o.E), }); }
public static Robot Parse(int id, string[] inputs) { return(new Robot { Id = id, Target = (LocationId)Enum.Parse(typeof(LocationId), inputs[0]), Eta = int.Parse(inputs[1]), Score = int.Parse(inputs[2]), Storage = Molecules.Parse(inputs, 3), Expertise = Molecules.Parse(inputs, 8), }); }
public static Sample Parse(string[] inputs) { return(new Sample { Id = int.Parse(inputs[0]), CarriedBy = int.Parse(inputs[1]), Rank = int.Parse(inputs[2]), ExpertiseGain = inputs[3].ParseMoleculeId(), Health = int.Parse(inputs[4]), Cost = Molecules.Parse(inputs, 5), }); }
public bool IsMoleculesFull(DataFile df) { bool ret = true; Molecules.ForEach(m => { if (m.Quantity + ExpertiseList.Find(ex => ex.Genre == m.Genre).Value < df.Molecules.Find(mm => mm.Genre == m.Genre).Quantity) { ret = false; } }); return(ret); }
/// <summary> /// Refereshes molecules, leaving those already assigned intact /// </summary> public void RefreshMolecules() { foreach (Molecule molecule in Molecules.ToList()) { if (molecule.Atoms.Count == 0) { //it's empty, trash it Molecules.Remove(molecule); } else { molecule.Refresh(); } } AddNewMols(); }
/// <summary> /// Regenerates molecule collections from the bottom up /// /// </summary> public void RebuildMolecules() { foreach (Atom atom in AllAtoms) { atom.Parent = null; } foreach (Bond bond in AllBonds) { bond.Parent = null; } Molecules.Clear(); AddNewMols(); }
public MobilityCellViewModel() { Restart(); Observable .Interval(TimeSpan.FromMilliseconds(50)) .Subscribe(_ => { foreach(var molecule in Molecules) { molecule.Move(); } var cellGasMolecules = Molecules.OfType<NeutralMolecule>(); foreach (var ion in Molecules.OfType<ChargedMolecule>()) { if (cellGasMolecules.Any(mol => mol.CollidesWith(ion))) { ion.Velocity = new Vector(0, ion.Velocity.Y); } } }); }
void Update() { if (TimeMan.timeScale != 1 || updateEnergy || SelectZoomLevelGUI.selectedButton != 0) { lifeBar = (ptype == ProjectileType.G ? 1 : curEnergy / originalEnergy); updateEnergy = false; } speedReading = theSpeed * (1f + lifeBar) * 0.5f; chanceToInteract = interactionsPerAtom[(int)ptype]; energyReading = (ptype == ProjectileType.G ? originalEnergy : curEnergy); // TODO replace this with particleSystem shuriken stuff ? VelocityOverLifetime? // if(SelectZoomLevelGUI.selectedButton == 1) { // Particle[] ps0 = trail0.particles; // Particle[] ps1 = trail1.particles; // //float max = 0; // for(int i = 0; i < ps1.Length; i++) { // //Color c1 = ps1[i].color; // //Vector3 orig = new Vector3((c1.r*1000f)-500f, (c1.g*1000f)-500f, (c1.b*1000f)-500f); // //if(i == 50 || i == 100 || i == 150 || i == 200 || i == 250 || i == 300 || i == 350) { // //Debug.Log(c1.r + ", " + c1.g + ", " + c1.b + ", :: " + orig); // //Debug.DrawLine(ps0[i].position, ps1[i].position); // //} // bool late = ps1[i].startEnergy - ps1[i].energy > 5; // Vector3 delta = ps0[i].position - ps1[i].position; // float mag = delta.magnitude; // if(mag != 0) delta /= mag; // ps1[i].velocity = Vector3.Lerp(ps1[i].velocity, delta*0.2f, Time.deltaTime * (0.001f + Mathf.Clamp01(1f/(mag*5))*(late ? 0.0008f : 0))); // ps1[i].velocity = Vector3.Lerp(ps1[i].velocity, Vector3.zero, Time.deltaTime * (late ? ps1[i].velocity.magnitude*0.3f + 0.002f : 0)+0.001f); // if(mag < 0.001f && late) { // ps0[i].position = Vector3.zero; // ps1[i].position = Vector3.zero; // ps0[i].velocity = Vector3.zero; // ps1[i].velocity = Vector3.zero; // } // //if(mag > max) max = mag; // } // //Debug.Log(max); // trail0.particles = ps0; // trail1.particles = ps1; // } if (curEnergy <= 0) { curEnergy = 0; if (!hasWinkedOut) { StartCoroutine(WinkOut()); hasWinkedOut = true; } //foreach(Transform t in graphic) { // Destroy(t.gameObject); //} //trail0.emit = false; //trail1.emit = false; return; } int cm1i = (int)(cm1 * 5.5f); if (cm1i != lastCM1 && ptype == ProjectileType.G) { //Debug.Log("" + cm1i +"-"+ lastCM1); int delta = cm1i - lastCM1; while (delta > 0) { if (Random.value > 0.907f) { GammaHit(); return; } delta--; } lastCM1 = cm1i; } Vector3 dir = transform.forward; Vector3 point = transform.position; float dist = theSpeed * speedReading * speedMult[SelectZoomLevelGUI.selectedButton] * speedScale; float density = (ptype == ProjectileType.E ? 0.01f : 0.001f); for (int i = 0; i < currentMedium.Count; i++) { density = currentMedium[i].density; } float loss = dist * density * energyLossPerDensityPerUnit; MaterialZones.SolidMaterial check = MaterialZones.SolidMaterial.Air; //MaterialZones.Check(transform.position, true); noFastForward = isNewBeta || (check != MaterialZones.SolidMaterial.Air) || Physics.Raycast(point, dir, dist / speedScale, ~(1 << 2)) || curEnergy - loss <= 0; if (lifeBar < 0.01f) { noFastForward = false; } if (check == MaterialZones.SolidMaterial.Chamber) { if (ptype != ProjectileType.G) { if (enteredChamberState == 0) { enteredChamberState = 1; enteredChamberPos = point; } else if (enteredChamberState == 1 && (enteredChamberPos - point).sqrMagnitude > (ptype == ProjectileType.E && !isNewBeta ? 37 : 3)) { enteredChamberState = 2; GeigerCounter.Beep(); } } else { loss *= 100; } } else { if (enteredChamberState == 1) { enteredChamberState = 2; GeigerCounter.Beep(); } } fastForward2 = (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)); TimeMan.timeScale = (fastForward1 || fastForward2 ? 15 : 1); speedScale = (SelectZoomLevelGUI.selectedButton == 0 && ((fastForward1 || fastForward2) && !noFastForward) ? 50 : 1); if (ptype == ProjectileType.P && SelectZoomLevelGUI.selectedButton != 2 && density > 0.5f) { loss *= 0.02f; } if (SelectZoomLevelGUI.selectedButton == 1) { Vector3 disPos = trail0.transform.position; float val = Random.Range(0.2f * loss * emissionPerEnergyLost * (ptype == ProjectileType.G ? 0 : 1), 1.8f * loss * emissionPerEnergyLost * (ptype == ProjectileType.G ? 0 : 1)) * Time.deltaTime; var mainModule0 = trail0.main; var mainModule1 = trail1.main; //var velocityModule0 = trail0.velocityOverLifetime; //var velocityModule1 = trail1.velocityOverLifetime; while (val > 0) { if (val > Random.value) { Vector3 pp = Vector3.Lerp(lastPos, disPos, Random.value); Vector3 emVel = dir * dist; Vector3 spew = emVel * 0.17f + Vector3.Scale(new Vector3(1, 0, 1), Random.insideUnitSphere * dist * electronSpew); float energy = Random.Range(mainModule0.startLifetime.constantMin, mainModule0.startLifetime.constantMax); var params0 = new ParticleSystem.EmitParams(); params0.position = pp; params0.velocity = Vector3.zero; params0.startSize = Random.Range(mainModule0.startSize.constantMin, mainModule0.startSize.constantMax); params0.startLifetime = energy; params0.startColor = Color.white; var params1 = new ParticleSystem.EmitParams(); params1.position = pp; params1.velocity = spew; params1.startSize = Random.Range(mainModule1.startSize.constantMin, mainModule1.startSize.constantMax); params1.startLifetime = energy; params1.startColor = Color.white; trail0.Emit(params0, 1); trail1.Emit(params1, 1); } val -= 1; } lastPos = disPos; } speedometer = dist; dist *= Time.deltaTime; loss *= Time.deltaTime; cm1 += loss; if (ptype != ProjectileType.G) { curEnergy -= loss; } if (curEnergy < 0) { dist += curEnergy / (density * energyLossPerDensityPerUnit); } /* * Vector3 pos = Vector3.zero; * RaycastHit[] hits1 = Physics.RaycastAll(point , dir, dist, ~(1<<2)); * RaycastHit[] hits2 = Physics.RaycastAll(point+dir*dist, -dir, dist, ~(1<<2)); * for(int i = 0; i < hits1.Length + hits2.Length; i++) { * RaycastHit hit = i < hits1.Length ? hits1[i] : hits2[i-hits1.Length]; * if((hit.point - pos).sqrMagnitude > 0.00001f) { * pos = hit.point; * if(Vector3.Dot(hit.normal,dir) < 0) { * MediumInfo medium = hit.collider.GetComponent<MediumInfo>(); * } * MacroModeGUI.NewLine(hit.point, null, curLineMode); * } * } */ //List<MediumInfo> oldList = currentMedium; string lastName = ""; for (int i = 0; i < currentMedium.Count; i++) { lastName = currentMedium[i].name; } currentMedium = new List <MediumInfo>(); RaycastHit[] hits3 = Physics.RaycastAll(point, Vector3.down, 100, (1 << 14)); //RaycastHit[] hits2 = Physics.RaycastAll(point+dir*dist, -dir, dist, (1<<14)); for (int i = 0; i < hits3.Length; i++) { RaycastHit hit = hits3[i]; MediumInfo medium = hit.collider.GetComponent <MediumInfo>(); //Debug.Log(hit.textureCoord.y); if (medium.name == "Flesh" && hit.textureCoord.y < MaterialZones.i.skinWidthFudge && hit.textureCoord.y > 0.05f) { MediumInfo nm = null; nm = gameObject.GetComponent <MediumInfo>(); if (!nm) { nm = gameObject.AddComponent <MediumInfo>(); } nm.name = "Epidermis"; nm.density = (SelectZoomLevelGUI.selectedButton == 1 ? 3 : 1.3f); currentMedium.Add(nm); } else if (hit.textureCoord.y < 0.05f) { //Debug.Log(hit.textureCoord.y); currentMedium.Add(medium); } } string name1 = ""; for (int i = 0; i < currentMedium.Count; i++) { name1 = currentMedium[i].name; } if (name1 != lastName && !((name1 == "Epidermis" && lastName == "Flesh") || (lastName == "Epidermis" && name1 == "Flesh"))) { //Debug.Log("was in: " + lastName + ", now in: " + name1); MacroModeGUI.NewLine(point, (currentMedium.Count > 0 ? currentMedium[currentMedium.Count - 1] : null), curLineMode); } Molecules.Collide(transform.position, transform.position + dir * dist); transform.localPosition += transform.parent.InverseTransformDirection(dir) * dist * 0.01f; }
public static Top FromFile(string path, List <string> defines) { List <string> lines = new List <string>(HFile.ReadAllLines(path)); List <LineElement> elements = new List <LineElement>(); //List<Tuple<string,List<LineElement>>> elementgroup = new List<Tuple<string, List<LineElement>>>(); //Dictionary<int,Atom> atoms = new Dictionary<int, Atom>(); //List<Bond> bonds = new List<Bond>(); //List<Pair> pairs = new List<Pair>(); //List<Angle> angles = new List<Angle>(); string type = null; while (lines.Count > 0) //for(int i=0; i<lines.Length; i++) { string line = lines[0]; lines.RemoveAt(0); //LineElement element = new LineElement(lines[i]); string typei = LineElement.GetType(line); if (typei != null) { type = typei; //elementgroup.Add(new Tuple<string, List<LineElement>>(type, new List<LineElement>())); continue; } { line = line.Trim(); if (line.EndsWith("\\")) { while (lines.Count > 0) { line = line + "\n" + lines[0].Trim(); lines.RemoveAt(0); if (line.EndsWith("\\") == false) { break; } } //line = ""; //for(; i<lines.Length; i++) //{ // string lline = lines[i].Trim(); // line = line + lline + "\n"; // if(lline.EndsWith("\\") == false) // break; //} } line = (line.IndexOf(';') == -1) ? line.Trim() : line.Substring(0, line.IndexOf(';')).Trim(); if (line.Length == 0) { continue; } if (line[0] == '*') { continue; } if (line.StartsWith("#define")) { string define = line.Replace("#define", "").Trim(); defines.Add(define); continue; } if (line.StartsWith("#include")) { string includepath; { includepath = line.Replace("#include", "").Trim().Replace("\"", "").Trim(); if (HFile.Exists(includepath) == false) { includepath = @"C:\Program Files (x86)\Gromacs\share\gromacs\top\" + line.Replace("#include", "").Trim().Replace("\"", "").Trim(); } if (HFile.Exists(includepath) == false) { includepath = HDirectory.GetParent(path).FullName + "\\" //path.Substring(0, path.LastIndexOf('/')+1) + line.Replace("#include", "").Trim().Replace("\"", "").Trim(); } HDebug.Assert(HFile.Exists(includepath)); } Top includetop = FromFile(includepath, defines); elements.AddRange(includetop.elements); type = null; continue; } if (line.StartsWith("#ifdef")) { FromFile_ifdef(defines, lines, line); continue; } if (line.StartsWith("#")) { HDebug.Assert(false); } if (type == "moleculetype") { LineElement element = new Moleculetype(line, path); elements.Add(element); continue; } if (type == "atoms") { LineElement element = new Atom(line, path); elements.Add(element); continue; } if (type == "bonds") { LineElement element = new Bond(line, path); elements.Add(element); continue; } if (type == "pairs") { LineElement element = new Pair(line, path); elements.Add(element); continue; } if (type == "angles") { LineElement element = new Angle(line, path); elements.Add(element); continue; } if (type == "dihedrals") { LineElement element = new Dihedral(line, path); elements.Add(element); continue; } if (type == "cmap") { LineElement element = new Cmap(line, path); elements.Add(element); continue; } if (type == "position_restraints") { LineElement element = new Position_restraints(line, path); elements.Add(element); continue; } if (type == "system") { LineElement element = new System(line, path); elements.Add(element); continue; } if (type == "molecules") { LineElement element = new Molecules(line, path); elements.Add(element); continue; } if (type == "defaults") { LineElement element = new Defaults(line, path); elements.Add(element); continue; } if (type == "atomtypes") { LineElement element = new Atomtypes(line, path); elements.Add(element); continue; } if (type == "pairtypes") { LineElement element = new Pairtypes(line, path); elements.Add(element); continue; } if (type == "bondtypes") { LineElement element = new Bondtypes(line, path); elements.Add(element); continue; } if (type == "constrainttypes") { LineElement element = new Constrainttypes(line, path); elements.Add(element); continue; } if (type == "angletypes") { LineElement element = new Angletypes(line, path); elements.Add(element); continue; } if (type == "dihedraltypes") { LineElement element = new Dihedraltypes(line, path); elements.Add(element); continue; } if (type == "implicit_genborn_params") { LineElement element = new Implicit_genborn_params(line, path); elements.Add(element); continue; } if (type == "cmaptypes") { LineElement element = new Cmaptypes(line, path); elements.Add(element); continue; } if (type == "settles") { LineElement element = new Settles(line, path); elements.Add(element); continue; } if (type == "exclusions") { LineElement element = new Exclusions(line, path); elements.Add(element); continue; } HDebug.Assert(false); } } Top top = new Top(); top.elements = elements.ToArray(); return(top); }
public virtual IEnumerable <IMoleculeBuilder> AllPresentMolecules() { return(Molecules.AllPresentFor(MoleculeStartValues)); }
private void OnCollisionEnter(Collision collision) { GameObject go = GameObject.Find("SingletonController"); Molecules other = (Molecules)go.GetComponent(typeof(Molecules)); int connections = other.GetBindingConnections(gameObject.GetInstanceID()); //------------------------------------------------------------------------------------------------------ // SUPER SAFETY CHECK DELUXE, IGNORE FOR NOW if (fixedJoint_right == null) { hasConnectionRight = false; } if (fixedJoint_left == null) { hasConnectionLeft = false; } //----------------------------------------------------------------------------------------- if (collision.gameObject.tag == "Atom" && connections < MaxConnections) { // Calculate right/left intersection of the collision var relativePosition = transform.InverseTransformPoint(collision.contacts[0].point); // When checking this, check the model that is being used, it could be another axis that is the // Models "side". need to check, my test program used the Z-direction. Seems the interBinding uses X-AXIS it seems. // Also check the relative position numbers, could also be different, they will be printed in the debug. // Collision is on the "right of the object" if (relativePosition.x >= 0.35 && relativePosition.x <= 0.5) { // REMEMBER: left and right depends on which side of the object you stand. // it would be smarter to say: negative side, and positive side. The important part // is that they are at different side, and we can always find this side. Debug.Log("The object is to the right"); // handy for testing Debug.Log(relativePosition); // handy for testing // If the right connection is available. if (hasConnectionRight == false) { fixedJoint_right = AddFixedJoint(collision.gameObject, connections); // need the id, when we remove this one. Must happen in the molecule script i believe. // the bools should probably be there and we use the molecule script for controll, reason: // we need to know which molecule that is getting taken off. I am trying with teh fixedjoint reference as a work around hasConnectionRight = true; other.SetBindingConnections(++connections, gameObject.GetInstanceID()); } } // Collision is on the "left of the object" else if (relativePosition.x <= -0.3 && relativePosition.x >= -0.5) { Debug.Log("The object is to the left"); // handy for testing Debug.Log(relativePosition); // handy for testing if (hasConnectionLeft == false) { fixedJoint_left = AddFixedJoint(collision.gameObject, connections); hasConnectionLeft = true; other.SetBindingConnections(++connections, gameObject.GetInstanceID()); } } // else we cancel out immediatly, may be removed? else { return; } } else if (collision.gameObject.name != "Controller (right)" && collision.gameObject.name != "Controller(left)") { GetComponent <Rigidbody>().velocity = new Vector3(0, 0, 0); GetComponent <Rigidbody>().angularVelocity = new Vector3(0, 0, 0); } }
public bool CanSubtract(Molecules o) { return(A >= o.A && B >= o.B && C >= o.C && D >= o.D && E >= o.E); }