private void fillSampleListRandom( string method ) { Configuration conf; switch (method) { case "Random": #region RandomSampleFilling for (int i = 0; i < numberOfSample; i++) samples.Add(getFreeConfiguration()); break; #endregion case "AroundObstacles": #region AroundObstaclesSampleFilling for (int i = 0; i < numberOfSample; i++) { conf = getRandomConfig(); Agent a = new Agent(game, spriteBatch, texture, conf.X, conf.Y, conf.Width, conf.Height, conf.Rotation,"a"+i.ToString()); if (a.config.isOnObstacle(scenario.obstacles)) { Vector2 randomDirection; do { randomDirection = new Vector2((float)rand.NextDouble() * 2 - 1, (float)rand.NextDouble() * 2 - 1); } while (randomDirection.X == 0 && randomDirection.Y == 0); do { a.config.ChangePosition(randomDirection.X, randomDirection.Y); } while (a.config.isOnObstacle(scenario.obstacles)); samples.Add(a.config); } else samples.Add(getFreeConfiguration()); // Eğer sample boşlukta çıktıysa direk alınır. } break; #endregion case "OnlyAroundObstacles": #region OnlyAroundObstacles for (int i = 0; i < numberOfSample; i++) { conf = getRandomConfig(); Agent a = new Agent(game, spriteBatch, texture, conf.X, conf.Y, conf.Width, conf.Height, conf.Rotation,"a"+i.ToString()); if (a.config.isOnObstacle(scenario.obstacles)) { Vector2 randomDirection; do { randomDirection = new Vector2((float)rand.NextDouble() * 2 - 1, (float)rand.NextDouble() * 2 - 1); } while (randomDirection.X == 0 && randomDirection.Y == 0); do { a.config.ChangePosition(randomDirection.X, randomDirection.Y); } while (a.config.isOnObstacle(scenario.obstacles)); samples.Add(a.config); } } break; #endregion case "Special1": Agent c = new Agent(game, spriteBatch, texture, 30, 60, 5, 5, 0.0f,"a1"); samples.Add(c.config); c = new Agent(game, spriteBatch, texture, 90, 20, 5, 5, 0.0f, "a2"); samples.Add(c.config); c = new Agent(game, spriteBatch, texture, 100, 70, 5, 5, 0.0f, "a3"); samples.Add(c.config); c = new Agent(game, spriteBatch, texture, 90, 120, 5, 5, 0.0f, "a4"); samples.Add(c.config); c = new Agent(game, spriteBatch, texture, 280, 320, 5, 5, 0.0f, "a5"); samples.Add(c.config); c = new Agent(game, spriteBatch, texture, 320, 280, 5, 5, 0.0f, "a6"); samples.Add(c.config); c = new Agent(game, spriteBatch, texture, 330, 310, 5, 5, 0.0f, "a7"); samples.Add(c.config); c = new Agent(game, spriteBatch, texture, 320, 350, 5, 5, 0.0f, "a8"); samples.Add(c.config); break; } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load<SpriteFont>("myFont"); t = Content.Load<Texture2D>("Square"); obstacleTexture = Content.Load<Texture2D>("randomPosition"); scenario = new Scenario(this, spriteBatch, t, "DuzDarBogaz"); roadmap = new Roadmap(this, graphics, spriteBatch, t, scenario, 100, 5, 20, 60); dijsktra = new Dijkstra(roadmap); agent = new Agent(this, spriteBatch, t, 0, 0, 20, 60, 0.0F, Color.Yellow,dijsktra,"deneme"); roadmap.Enabled = true; agent.Enabled = true; this.Components.Add(agent); this.Components.Add(roadmap); // TODO: use this.Content to load your game content here }
private void fillSampleListAroundObstacles() { Configuration conf; for (int i = 0; i < numberOfSample; i++) { conf = getRandomConfig(); Agent a = new Agent(game, spriteBatch, texture, conf.X, conf.Y, conf.Width, conf.Height, conf.Rotation,"a"+i.ToString()); if (a.config.isOnObstacle(scenario.obstacles)) { Vector2 randomDirection; do { randomDirection = new Vector2((float)rand.NextDouble() * 2 - 1, (float)rand.NextDouble() * 2 - 1); } while (randomDirection.X == 0 && randomDirection.Y == 0); do { a.config.ChangePosition(randomDirection.X, randomDirection.Y); } while (a.config.isOnObstacle(scenario.obstacles)); samples.Add(a.config); } else { // Eğer sample boşlukta çıktıysa direk alınır. //samples.Add(getFreeConfiguration()); } } }