public AgentCutaway(AgentType agTy, Int32 ID, Coordinates pos_, AgentState state_) { type = agTy; agentID = ID; pos = pos_; state = state_; }
public static Segment randomSeg() { Coordinates beg = new Coordinates((float)randGen.NextDouble(), (float)randGen.NextDouble()); Coordinates end = (new Coordinates((float)randGen.NextDouble(), (float)randGen.NextDouble())).normalize(); end = (end * 0.1f) + beg; return new Segment(beg, end); }
public static bool segmentCircleIntersection(Segment seg, Coordinates center, float radius, ref Coordinates a, ref Coordinates b) { bool rez = false; //shift segment Segment newSeg = seg; newSeg.beg = newSeg.beg - center; newSeg.end = newSeg.end - center; //vector Coordinates newC = seg.end - seg.beg; if (Math.Abs(newC.x) < float.Epsilon) { rez = segCirInt(1f, 0f, newSeg.beg.x, radius, ref a, ref b); } else { newC.x = newC.y/newC.x; newC.y = (-1.0f); float C = -(newC.x * newSeg.beg.x + newC.y * newSeg.beg.y); rez = segCirInt(newC.x, newC.y,C, radius,ref a, ref b); } if (rez) { a = a + center; b = b + center; } return rez; }
public AgentInfo(Color colour_, float radius_, AgentType agType_, Int32 ID_, AgentState state_, float communicateRad_, Coordinates coord_, float speed_, float viewRadius_) { agentID = ID_; agentColor = colour_; agentRadius = radius_; agentType = agType_; agentState = state_; communicteRadius = communicateRad_; coord = coord_; speed = speed_; viewRadius = viewRadius_; }
public static bool segCirInt(float A, float B, float C, float radius, ref Coordinates first, ref Coordinates second) { float x0 = -A * C / (A * A + B * B), y0 = -B * C / (A * A + B * B); if (C * C >= radius * radius * (A * A + B * B) + float.Epsilon) { return false; } else { float d = radius * radius - C * C / (A * A + B * B); float mult = (float)Math.Sqrt(d / (A * A + B * B)); first.x = x0 + B * mult; first.y = y0 - A * mult; second.x = x0 - B * mult; second.y = y0 + A * mult; return true; } }
public mainForm() { InitializeComponent(); ViewRange.Checked = true; board = new Board(ref Field,ref ViewRange, ref showMatrix); Coordinates pos = new Coordinates(0.2f, 0.2f); //bill1 = board.createDummy1(); AgentEnv bill2 = board.createFinder1(); AgentEnv nancy = board.createLittleGirl1(); //bill1.setCoord(pos); bill2.setCoord(pos* 4.9f); AgentEnv iggy; nancy.setCoord(new Coordinates(0.49f, 0.51f)); //Console.WriteLine(pos.norm().ToString()); for (int i = 0; i < 5; i++) { //board.addWall(Segment.randomSeg()); iggy = board.createFinder1(); iggy.setCoord(new Coordinates(0.6f, 0.4f)); } board.addWall(new Segment(0f, 0.5f, 0.3f, 0.5f)); board.addWall(new Segment(0.5f, 1f, 0.7f, 0.3f)); }
public void setCoord(Coordinates coord_) { info.coord.safeAssign(coord_.x, coord_.y); }
private bool isPathLegal(Coordinates start, Coordinates finish) { //Checks if an agent can make step from start to finish postion bool noWalls = !wallList.haveIntersections(new Segment(start, finish)); bool inRange = (finish.x < 1.0f && finish.x > 0.0f && finish.y < 1.0f && finish.y > 0.0f); return noWalls && inRange; }
public Segment(float begX, float begY, float endX, float endY) { beg = new Coordinates(begX, begY); end = new Coordinates(endX, endY); }
public Segment(Coordinates beg_, Coordinates end_) { beg = beg_; end = end_; }
//make step in direction 'vec', using 'speedPerc' of your speed protected bool makeStep(Coordinates vec, float speedPerc) { return env.getBoard().askStep(vec, speedPerc, ref env); }
private bool genAim() { aim = cells.getUndiscoveredCell(); return true; //TODO: Delete this comment }
private void setAim(Coordinates coord) { aim = coord; }
private static int compareByY(Coordinates a, Coordinates b) { if (a.y < b.y) { return -1; } else { return 1; } }
private static Segment middleSeg(Coordinates beg, Coordinates end, Coordinates a, Coordinates b) { //Возвращает отрезок образованный двумя средними точками из указанных трёх List<Coordinates> list = new List<Coordinates>(); list.Add(beg); list.Add(end); list.Add(a); list.Add(b); if (Math.Abs(beg.x - end.x) < float.Epsilon) { list.Sort(compareByY); } else { list.Sort(compareByX); } return new Segment(list[1], list[2]); }
private static int compareByX(Coordinates a, Coordinates b) { if (a.x < b.x) { return -1; } else { return 1; } }
public List<Wall> wallsAroundPoint(Coordinates center, float radius) { List<Wall> rez = new List<Wall>(); Coordinates a = new Coordinates(); Coordinates b = new Coordinates(); Segment deleteThis = new Segment(); foreach (Wall wall in list.Values) { if (segmentCircleIntersection(wall.seg, center, radius, ref a, ref b)) { //rez.Add(new Wall(middleSeg(wall.seg.beg, wall.seg.end, a,b), wall.type)); deleteThis = middleSeg(wall.seg.beg, wall.seg.end, a, b); rez.Add(new Wall(deleteThis,wall.type)); //Console.WriteLine("So"); //Console.WriteLine("Center: " + center.ToString() + ", Radius =" + radius.ToString()); //Console.WriteLine("Wall:" + wall.seg.ToString()); //Console.WriteLine("Result:" +); } } return rez; }
private bool workWithObjectsAround() { List<AgentCutaway> cuts = lookAround(); bool found = false; bool communicate = false; foreach (AgentCutaway cut in cuts) { if (cut.state == AgentState.Find_Me) { aim = cut.pos; found = grabObject(cut.agentID); return found; } else if (cut.type == AgentType.Finder && cellsUpdated) { sendCellMatrix(cut.agentID); communicate = true; } } if (communicate && cellsUpdated) { cellsUpdated = false; } return false; }
bool canTouch1(Coordinates point, ref AgentEnv client) { //Checks if one agent is in proper distance to pick up another agent Coordinates pos = client.getCoord(); return (isPathLegal(pos, point) && ((pos - point).norm() < touchDist)); }
bool IAgentFunctions.canTouch(Coordinates point, ref AgentEnv client) { //Check if the agent can grab object in specific point return canTouch1(point, ref client); }
private bool canSee(Coordinates start, Coordinates finish) { //Checks if there is line of sight between two points bool noWalls = !wallList.haveIntersections(new Segment(start, finish)); bool inRange = finish.x < 1.0f && finish.x > 0.0f && finish.y < 1.0f && finish.y > 0.0f; return noWalls && inRange; }
protected bool canTouch(Coordinates pos) { return env.getBoard().canTouch(pos, ref env); }
private void genAim() { Coordinates coord = new Coordinates((float)randGen.NextDouble(), (float)randGen.NextDouble()); setAim(coord); }
public bool setCell(Coordinates coord) { Int16 x = (Int16)(coord.x * width); Int16 y = (Int16)(coord.y * height); return setCell(x, y); }
public static float area(Coordinates a, Coordinates b, Coordinates c) { return (b.x - a.x) * (c.y - a.y) * (b.y - a.y) * (c.x - a.x); }
bool IAgentFunctions.askStep(Coordinates direction, float speedPercent, ref AgentEnv client) { //Try to make step in specific direction. The length = max(speedPercent,1) * maxSpeed Coordinates pos = client.getCoord(), des; float perc = Math.Min(Math.Max(0.0f, speedPercent), 1.0f); des = pos + (direction.normalize()) * (perc * client.getSpeed()); if (isPathLegal(pos, des)) { client.setCoord(des); return true; } else { return false; } }