public void RegreseMove(int selRobot, Vector2D moveTo, Core.Robot[] a, Core.Robot[] b) { Bod robo; Bod prekazka; Bod prekazka2; Bod cil; List <RobotDistance> lis = new List <RobotDistance>(); robo = new Bod(a[selRobot].Position.X, a[selRobot].Position.Y); cil = new Bod(moveTo.X, moveTo.Y); //hledani prekazek v ceste robota for (int i = 0; i < 5; i++) { prekazka = new Bod(b[i].Position.X, b[i].Position.Y); prekazka2 = new Bod(a[i].Position.X, a[i].Position.Y); try { if (IsObstacle(robo, prekazka, cil)) { lis.Add(new RobotDistance(new Bod(prekazka.x, prekazka.y), distanceTwoPoints(robo, prekazka))); } if (IsObstacle(robo, prekazka2, cil) && i != selRobot) { lis.Add(new RobotDistance(new Bod(prekazka2.x, prekazka2.y), distanceTwoPoints(robo, prekazka2))); } } catch { }; } int offset = 10; //objeti prekazky smerem k cili kterym je MoveTo if (lis.Count > 0) { try { var sort = from s in lis orderby s.vzdalenost select s; PolynomialRegresion regrese = new PolynomialRegresion(robo, new Bod(sort.ElementAt(0).bod.x, sort.ElementAt(0).bod.y), cil); List <Bod> body = regrese.polynom(true); if (cil.x > robo.x) { a[selRobot].PositionMove = new Vector2D(body[Convert.ToInt32(robo.x + offset) + 110].x, body[Convert.ToInt32(robo.x + offset) + 110].y); } else { a[selRobot].PositionMove = new Vector2D(body[Convert.ToInt32(robo.x - offset) + 110].x, body[Convert.ToInt32(robo.x - offset) + 110].y); } lis.RemoveAll(item => item.vzdalenost > 0); //Debug.Log(mirror + " - " + selRobot + " PREKAZKA pri MoveTo"); } catch { } } }
public void regrese(Core.Robot[] a, Core.Robot[] b) { Bod robo; Bod prekazka; Bod prekazka2; Bod cil; List <RobotDistance> lis = new List <RobotDistance>(); for (int j = 0; j < 5; j++) { robo = new Bod(a[j].Position.X, a[j].Position.Y); cil = new Bod(a[j].PositionMove.X, a[j].PositionMove.Y); //cil = new Bod(ball.Position.X,ball.Position.Y); for (int i = 0; i < 5; i++) { prekazka = new Bod(b[i].Position.X, b[i].Position.Y); prekazka2 = new Bod(a[i].Position.X, a[i].Position.Y); try { if (IsObstacle(robo, prekazka, cil)) { lis.Add(new RobotDistance(new Bod(prekazka.x, prekazka.y), distanceTwoPoints(robo, prekazka))); } if (IsObstacle(robo, prekazka2, cil) && i != j) { lis.Add(new RobotDistance(new Bod(prekazka2.x, prekazka2.y), distanceTwoPoints(robo, prekazka2))); } } catch { }; } if (lis.Count > 0) { try { var sort = from s in lis orderby s.vzdalenost select s; PolynomialRegresion regrese = new PolynomialRegresion(robo, new Bod(sort.ElementAt(0).bod.x, sort.ElementAt(0).bod.y), cil); List <Bod> body = regrese.polynom(true); if (cil.x > robo.x) { a[j].PositionMove = new Vector2D(body[Convert.ToInt32(robo.x + 1) + 110].x, body[Convert.ToInt32(robo.x + 1) + 110].y); } else { a[j].PositionMove = new Vector2D(body[Convert.ToInt32(robo.x - 1) + 110].x, body[Convert.ToInt32(robo.x - 1) + 110].y); } lis.RemoveAll(item => item.vzdalenost > 0); } catch { } } } }
public void RegreseOne(int selRobot, Core.Ball ball, Core.Robot[] a, Core.Robot[] b) { Bod robo; Bod prekazka; Bod prekazka2; Bod cil; List <RobotDistance> lis = new List <RobotDistance>(); //for (int j = 0; j < 5; j++) { robo = new Bod(a[selRobot].Position.X, a[selRobot].Position.Y); //cil = new Bod(a[selRobot].PositionMove.X, a[selRobot].PositionMove.Y); cil = new Bod(ball.Position.X, ball.Position.Y); //hledani prekazek v ceste robota for (int i = 0; i < 5; i++) { prekazka = new Bod(b[i].Position.X, b[i].Position.Y); prekazka2 = new Bod(a[i].Position.X, a[i].Position.Y); try { if (IsObstacle(robo, prekazka, cil)) { lis.Add(new RobotDistance(new Bod(prekazka.x, prekazka.y), distanceTwoPoints(robo, prekazka))); } if (IsObstacle(robo, prekazka2, cil) && i != selRobot) { lis.Add(new RobotDistance(new Bod(prekazka2.x, prekazka2.y), distanceTwoPoints(robo, prekazka2))); } } catch { }; } int offset = 10; //objeti prekazky smerem k cili kterym je micek if (lis.Count > 0) { //if(!mirror) // Debug.Log(selRobot + " PREKAZKA"); try { var sort = from s in lis orderby s.vzdalenost select s; PolynomialRegresion regrese = new PolynomialRegresion(robo, new Bod(sort.ElementAt(0).bod.x, sort.ElementAt(0).bod.y), cil); List <Bod> body = regrese.polynom(true); if (cil.x > robo.x) { a[selRobot].PositionMove = new Vector2D(body[Convert.ToInt32(robo.x + offset) + 110].x, body[Convert.ToInt32(robo.x + offset) + 110].y); } else { a[selRobot].PositionMove = new Vector2D(body[Convert.ToInt32(robo.x - offset) + 110].x, body[Convert.ToInt32(robo.x - offset) + 110].y); } lis.RemoveAll(item => item.vzdalenost > 0); } catch { } } //mezi mickem a robotem neni prekazka, zmenit cil za branku a prolozit mickem else { try { PolynomialRegresion regrese; List <Bod> body; if (mirror) { //micek je pred robotem if (robo.x > ball.Position.X) { cil = new Bod(-110, 0); regrese = new PolynomialRegresion(robo, new Bod(ball.Position.X, ball.Position.Y), cil); body = regrese.polynom(false); } //micek je za robotem else { cil = new Bod(110, 0); regrese = new PolynomialRegresion(robo, new Bod(ball.Position.X, ball.Position.Y), cil); body = regrese.polynom(true); } if (cil.x > robo.x) { a[selRobot].PositionMove = new Vector2D(body[Convert.ToInt32(robo.x + offset) + 110].x, body[Convert.ToInt32(robo.x + offset) + 110].y); } else { a[selRobot].PositionMove = new Vector2D(body[Convert.ToInt32(robo.x - offset) + 110].x, body[Convert.ToInt32(robo.x - offset) + 110].y); } } else { //micek je za robotem if (robo.x > ball.Position.X) { cil = new Bod(-110, 0); regrese = new PolynomialRegresion(robo, new Bod(ball.Position.X, ball.Position.Y), cil); body = regrese.polynom(true); } //micek je pred robotem else { cil = new Bod(110, 0); regrese = new PolynomialRegresion(robo, new Bod(ball.Position.X, ball.Position.Y), cil); body = regrese.polynom(false); } if (cil.x > robo.x) { a[selRobot].PositionMove = new Vector2D(body[Convert.ToInt32(robo.x + offset) + 110].x, body[Convert.ToInt32(robo.x + offset) + 110].y); } else { a[selRobot].PositionMove = new Vector2D(body[Convert.ToInt32(robo.x - offset) + 110].x, body[Convert.ToInt32(robo.x - offset) + 110].y); } } } catch { } } } }