List<MoveDirection> find_route(NRJPOINT target){ // Est / west : if (target.posx < meX) { for (int i=0; i<Math.Abs(target.posx) ; i++){ route.Add(MoveDirection.East); } } if (target.posx > meX) { for (int i=0; i<Math.Abs(target.posx) ; i++){ route.Add(MoveDirection.West); } } if (target.posy < meY) { for (int i=0; i<Math.Abs(target.posy) ; i++){ route.Add(MoveDirection.North); } } if (target.posy > meY) { for (int i=0; i<Math.Abs(target.posy) ; i++){ route.Add(MoveDirection.South); } } return route ; }
/// <summary> /// Résultat du scan /// </summary> /// <param name="distance">Distance.</param> /// <param name="informations">Informations.</param> public void AreaInformation(byte distance, byte[] informations) { if (distance == 0) { return; } int radar_nrj = 0; List <NRJPOINT> NRJ_list = new List <NRJPOINT>(); Console.WriteLine($"Area: {distance}"); int index = 0; for (int i = 0; i < distance; i++) { for (int j = 0; j < distance; j++) { if (informations[index] == (byte)CaseState.Energy) { radar_nrj++; NRJPOINT n = new NRJPOINT(); n.posx = j; n.posy = i; NRJ_list.Add(n); } if (informations[index] == (byte)CaseState.Ennemy) { meX = j; meY = i; } index++; } } // Find route for each nrgpoint : List <List <MoveDirection> > routes = new List <List <MoveDirection> >(); foreach (NRJPOINT p in NRJ_list) { route = find_route(p); if (check_route(route)) { routes.Add(route); } } //mytarget = find_nearest_energy(NRJ_list); //route = find_best_route(mytarget); }
NRJPOINT find_nearest_energy(List<NRJPOINT> pliste){ // Let's compute distance & find the nearest Energy point // pour chaque nrjtpoint appelé 'p' de nrj_list : // distance = valeur absolue (meX - nrjpoint.posx)+ abs(meY-nrjpoint.posy) NRJPOINT target = new NRJPOINT(); target.distance= 9999; foreach (NRJPOINT p in pliste){ p.get_distance(meX,meY); if (p.distance < target.distance){ target = p; target.posx=target.posx-meX; target.posy=target.posy-meY; } } return (target); }
/// <summary> /// Résultat du scan /// </summary> /// <param name="distance">Distance.</param> /// <param name="informations">Informations.</param> public void AreaInformation(byte distance, byte[] informations) { if (distance == 0) { return; } int radar_nrj = 0; int meY = 0; int meX = 0; List <NRJPOINT> NRJ_list = new List <NRJPOINT>(); Console.WriteLine($"Area: {distance}"); int index = 0; for (int i = 0; i < distance; i++) { for (int j = 0; j < distance; j++) { if (informations[index] == (byte)CaseState.Energy) { radar_nrj++; NRJPOINT n = new NRJPOINT(); n.posx = j; n.posy = i; NRJ_list.Add(n); } if (informations[index] == (byte)CaseState.Ennemy) { meX = j; meY = i; } Console.Write(informations[index++]); } Console.WriteLine(); } //pour chaque NRJ point de NRJ list calculer distance //distance = valeurs absole(meX - nrjpoint.posX) + abs(meY-nrjpoint.posy) NRJPOINT target = new NRJPOINT(); target.distance = 9999; foreach (NRJPOINT p in NRJ_list) { p.get_distance(meX, meY); if (p.distance < target.distance) { target = p; target.posx = target.posx - meX; target.posy = target.posy - meY; } Console.WriteLine($"{p.posx} {p.posy} = {p.distance}"); Console.WriteLine($"targetv = { target.posx} {target.posy} = {target.distance}"); } if (target.posx < 0) { for (int i = 0; i < Math.Abs(target.posx); i++) { route.Add(MoveDirection.East); } } if (target.posx > 0) { for (int i = 0; i < Math.Abs(target.posx); i++) { route.Add(MoveDirection.West); } } if (target.posy > 0) { for (int i = 0; i < Math.Abs(target.posx); i++) { route.Add(MoveDirection.South); } } if (target.posy < 0) { for (int i = 0; i < Math.Abs(target.posx); i++) { route.Add(MoveDirection.North); } } Console.WriteLine("ROUTE = "); foreach (MoveDirection d in route) { Console.WriteLine(d); } //Console.WriteLine($"NRJ : {radar_nrj}"); //Console.WriteLine($"Me x : {meX}"); //Console.WriteLine($"Me y : {meY}"); }