/// <summary> /// Creates a new Living Entity /// </summary> /// <param name="rect">The rectangle that represents the location and width and height of the entity</param> /// <param name="fileName">the location of the sprite for this entity</param> public LivingEntity(FloatRectangle rect, Sprite sprite, int health, AI.AI ai = null, int cash = 0) : base(rect, sprite) { inventory = new Inventory(); time = new GameTime(); lastShot = 60000D; interactRange = 32; // the below depend on texture, this should not be needed ever but because of the player texture it is... //this.interactBoundsOffsetY = interactBoundsOffsetY; //this.interactBoundsOffsetX = interactBoundsOffsetX; this.cash = cash; this.health = health; this.ai = ai; maxHealth = health; color = Color.Red; healthBar = new ProgressBar(new Vector2(60, 20)); healthBar.MaxValue = maxHealth; healthBar.CurrentValue = health; healthBar.IncludeText = Name; healthBar.LoadVisuals(Game1.Instance.Content, Game1.Instance.GraphicsDevice); controls.Add(healthBar); }
public override void UpdateItem() { ResetCooldown(); //TODO: Remove this once Shadow Demons are added to the room count. AI.AI[] ShadowDemons = GameObject.FindObjectsOfType <AI.ShadowDemonAI>(); for (int i = 0; i < ShadowDemons.Length; i++) { AI.AI enemy = ShadowDemons[i]; int damage = Mathf.RoundToInt(1); Status[] statuses = { Status.Burn }; enemy.TakeDamage(m_Player.PlayerNumber, damage, statuses, 1); } //Do damage to every enemy in the room by their max HP and apply burn for (int i = 0; i < m_Player.MyIslandRoom.EnemiesInRoomCount; i++) { AI.AI enemy = m_Player.MyIslandRoom.EnemiesInRoom[i]; int damage = Mathf.RoundToInt(enemy.Health.MaxHp / 2); if (m_Player.MyIslandRoom.TypeOfRoom == RoomType.Boss) { damage = 30; } Status[] statuses = { Status.Burn }; enemy.TakeDamage(m_Player.PlayerNumber, damage, statuses, 1); } }
private static void PlayIAMain(params AIRule[] ias) { Game2048 game = new Game2048(); AI.AI ia = new AI.AI(ias); ShowGrid(game); var result = ia.PlayGame(game, () => { ShowGrid(game); System.Threading.Thread.Sleep(75); }).Item1; if (result == GameResult.Loss) { ShowGrid(game); Console.WriteLine(); Console.WriteLine("You loose you dumb !"); Console.WriteLine(); Console.ReadKey(); } else if (result == GameResult.Win) { ShowGrid(game); Console.WriteLine(); Console.WriteLine("Congratulations, you won .... A COCONUT !"); Console.WriteLine(); } Console.WriteLine("Press any key to leave !"); }
private static void PlayIAStatsMain(params AIRule[] rules) { string text = string.Format("Running 1000 tests with selected AI : {0}", rules.Aggregate("", (x, y) => x + y.GetType().Name + " (" + y.Coefficient + "),")); Console.WriteLine(text); List <GameResult> results = new List <GameResult>(); List <int> scores = new List <int>(); List <int> bests = new List <int>(); AI.AI ai = new AI.AI(rules); Parallel.For(0, 1000, (i) => { Game2048 game = new Game2048(); var res = ai.PlayGame(game, () => { }); results.Add(res.Item1); scores.Add(game.Score); bests.Add(game.ShowBoard.Max(Game2048.SIZE)); }); Console.WriteLine("Results : "); var wins = results.Count(x => x == GameResult.Win); Console.WriteLine(" - {0} win and {1} losses.", wins, 1000 - wins); Console.WriteLine(" - {0} average score, {1} best, {2} worst.", scores.Average(), scores.Max(), scores.Min()); Console.WriteLine(" - {0} average best tile, {1} best, {2} worst.", bests.Average(), bests.Max(), bests.Min()); Console.WriteLine(); Console.WriteLine(); }
public Diablo3Api() { Log.OnLogMessage += LogMessageCallback; d3 = new BlackMagic(); d3.SetDebugPrivileges = false; memReader = new MemoryReader(d3); ai = new AI.AI(this); }
private void ShockNearbyEnemies(Collider[] CollidersInRange) { //Loop though all the colliders and find all the AI in Range foreach (Collider collider in CollidersInRange) { //If the collider has an AI attached to it Apply damage to the AI AI.AI colliderAI = collider.GetComponent <AI.AI>(); if (collider != null) { colliderAI.TakeDamage(DamageCountManager.instance.PlayerWhoLastDealtDamage, ShockDamage, null, 1); } } }
private async Task RunAiAsync(int segmentId, int userId, decimal addThr, decimal rmvThr, double exp, double rmv, double brk) { var aiInstance = new AI.AI(_segmentRepository, segmentId); AiInstances.Add(userId, aiInstance); var ai = Task.Run(() => aiInstance.Run(exp, rmv, addThr, rmvThr, brk)); var msg = await ReplyAsync("hang on...").ConfigureAwait(false); while (!ai.IsCompleted) { await UpdateMsgAsync(msg, segmentId, aiInstance.Status).ConfigureAwait(false); await Task.Delay(2000).ConfigureAwait(false); } await UpdateMsgAsync(msg, segmentId, aiInstance.Status).ConfigureAwait(false); }
/// <summary> /// Will create a new instance of this enemy character with the given /// texture, at the given position, with the given walking, running /// and jumping speeds. /// REQUIRE: given.texture != null /// given.position != nil && given.position.X,Y > 0 /// given.walking, running, jumping speed != null && > 0 /// ENSURE: this.currentSpeed() == given.walking_speed /// this.boundingBox().X,Y == given.position.X,Y /// </summary> public Enemy(Texture2D texture, Vector2 position, float walk_speed, float run_speed, float jump_speed, float jump_height, float sight_range, AI.AI personality) { this.personality = personality; //register this enemy to the personality this.personality.register(this); this.texture = texture; this.position = position; this.sight_range = sight_range; this.walk_velocity = walk_speed; this.run_velocity = run_speed; this.jump_velocity = jump_speed; this.fall_velocity = jump_speed; this.max_jump_height = jump_height; this.is_jumping_left = false; this.is_jumping_right = false; this.current_velocity = new Vector2(0, 0); //start the enemy off as alive this.is_alive = true; }
public override void GetVariablesFrom(GameObject recordable) { AI.AI ai = recordable.GetComponent <AI.AI>(); VisibleEnemies = ai.VisibleEnemies; Side = ai.Side; }
//for detecting enemies public Character(Sprite sprite, Body body, World world, CharacterDef charDef) : base(sprite, body, world) { _width = charDef.Width; _height = charDef.Height; _moveSpeed = charDef.MoveSpeed; //create surface sensor float xtmp = _width*CHAR_SENSOR_WIDTH_FACTOR*0.5f; float x1 = World.B2Value(-xtmp); float x2 = World.B2Value(xtmp); float ytmp = -_height*0.5f - 2.0f; float y1 = World.B2Value(ytmp - 1.0f); float y2 = World.B2Value(ytmp); var vertices = new Vector2[4]; vertices[0].X = x2; vertices[0].Y = y2; vertices[1].X = x1; vertices[1].Y = y2; vertices[2].X = x1; vertices[2].Y = y1; vertices[3].X = x2; vertices[3].Y = y1; _surfaceSense = AttachPolygonSensor(vertices); _surfaceSense.SensorName = Constants.SURFACE_SENSOR; //create visual sensor _visualSense = AttachCircleSensor(Vector2.Zero, _width*VISUAL_RANGE); _visualSense.SensorName = Constants.VISUAL_SENSOR; HP = charDef.HP; MaxHP = charDef.MaxHP; //Load animation if (charDef.FrameDefs != null) { for (int i = 0; i < charDef.FrameDefs.Length; i++) { FrameDef frameDef = charDef.FrameDefs[i]; var frame = new Frame(frameDef); frame.Target = sprite; _animations.Add(frame.Name, frame); } } //Load actions if (charDef.Actions != null) { for (int i = 0; i < charDef.Actions.Length; i++) { AttachAction(Activator.CreateInstance(Type.GetType(charDef.Actions[i])) as IAction); } } //Load sound effects if (charDef.SoundEffects != null) { foreach (var i in charDef.SoundEffects) { _soundEffects.Add(i.Key, AuditionManager.Instance.SoundEffects[i.Value]); } } //Load AI if (!string.IsNullOrEmpty(charDef.AI)) { _ai = new AI.AI(charDef.AI, this); } }
void LevelSelectionButtonClick(object sender, EventArgs e) { BG = Content.Load<Texture2D>(String.Format("Backgrounds\\bg{0}", rnd.Next(1, 7))); Manager.State.Planets.Clear(); Manager.State.Fleets.Clear(); Selected.Clear(); Manager.State.AIPlanets.Clear(); Manager.State.NeutralPlanets.Clear(); Manager.State.PlayerPlanets.Clear(); Button b = sender as Button; if(b.Tag!=21) Manager.State.Planets.AddRange(LoadMap(String.Format("Maps\\map{0}.xml", b.Tag))); else { if(rnd.NextDouble()<0.1) Manager.State.Planets.AddRange(LoadMap(String.Format("Maps\\map{0}.xml", 22))); else Manager.State.Planets.AddRange(LoadMap(String.Format("Maps\\map{0}.xml", b.Tag))); } CurrentPlanet = b.Tag; GameState = GameState.Game; if (CurrentPlanet <= 7) { Manager.AIAttackBias = 0.5f; Manager.PlayerAttackBias = 1.5f; Ai = new EasyAI(); } else if (CurrentPlanet > 7 && CurrentPlanet <= 14) { Manager.AIAttackBias = 0.75f; Manager.PlayerAttackBias = 1.25f; Ai = new MediumAI(); } else if (CurrentPlanet > 14 && CurrentPlanet <= 20) { Manager.AIAttackBias = 1f; Manager.PlayerAttackBias = 1; Ai = new HardAI(); } else { Manager.AIAttackBias = 1.25f; Manager.PlayerAttackBias = 1f; Ai = new InsaneAI(); } if (CurrentPlanet == 1) GameState = GameState.Tutorial; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here Manager = new GameManger(); Menu = new MenuManager(); PauseMenu = new MenuManager(); SelectionState = SelectionState.Selection; GameState = GameState.MainMenu; Ai = new EasyAI(); SoundTracksEnabled = MediaPlayer.GameHasControl; base.Initialize(); }