Exemple #1
0
    public static void UpdateAI(this IArtificialIntelligence ai)
    {
        if (ai.Server == null || !((Character)ai.GetSceneChar()).IsAlive)
        {
            return;
        }

        if (ai.Target == null)
        {
            ai.Target = ai.GetSceneChar().FindNearestEnemy(ai.Server.SceneCharacters.Values);
        }

        //Debug.Log( "AI Target is " + Target + " at " + Target.transform.position );

        // If there was no nearest enemy found, then don't do anything
        if (ai.Target == null)
        {
            return;
        }

        if (((Character)ai.Target).IsAlive)
        {
            ai.RunAtTarget();
            ai.AttackTarget();
        }
    }
Exemple #2
0
 public void setAI(IArtificialIntelligence ai)
 {
     if (ai == null)
         z_AI = null;
     else
         z_AI = ai.clone();
 }
Exemple #3
0
 public FormMain(IGameFactory gameFactory, IArtificialIntelligence artificialIntelligence, IMatchFactory matchFactory)
 {
     InitializeComponent();
     _gameFactory            = gameFactory;
     _artificialIntelligence = artificialIntelligence;
     _matchFactory           = matchFactory;
 }
        public void UpdatingAIEventArgsConstructorTest()
        {
            IArtificialIntelligence artificialIntelligence = null; // TODO: 初始化为适当的值
            WorldEntity             gameEntity             = null; // TODO: 初始化为适当的值
            UpdatingAIEventArgs     target = new UpdatingAIEventArgs(artificialIntelligence, gameEntity);

            Assert.Inconclusive("TODO: 实现用来验证目标的代码");
        }
Exemple #5
0
        public void Move(MoveUnitEvent moveUnitEvent, IArtificialIntelligence artificialIntelligence)
        {
            var unit = ComponentService.Get(moveUnitEvent.UnitId) as IUnit;
            if (unit == null)
                return;

            MoveUnitStore.Store(unit.Id,new MoveUnitProxy(unit,new Vector2(moveUnitEvent.X,moveUnitEvent.Y),moveUnitEvent.Id));
        }
        public void OnUpdatedAITest()
        {
            WorldEntityState        target = new WorldEntityState(); // TODO: 初始化为适当的值
            IArtificialIntelligence artificialIntelligence = null;   // TODO: 初始化为适当的值
            WorldEntity             gameEntity             = null;   // TODO: 初始化为适当的值

            target.OnUpdatedAI(artificialIntelligence, gameEntity);
            Assert.Inconclusive("无法验证不返回值的方法。");
        }
Exemple #7
0
 public Game(IArtificialIntelligence computerIntelligence)
 {
     //variables initializating
     AlreadyExitFromTimer = true;
     EnabledTips          = true;
     EnabledComputerMoves = false;
     CurrentMove          = 1;
     _timer = new Timer();
     _computerIntelligence = computerIntelligence;
 }
        public void NewAITest()
        {
            IArtificialIntelligence artificialIntelligence = null;                                        // TODO: 初始化为适当的值
            WorldEntity             gameEntity             = null;                                        // TODO: 初始化为适当的值
            UpdatingAIEventArgs     target = new UpdatingAIEventArgs(artificialIntelligence, gameEntity); // TODO: 初始化为适当的值
            IArtificialIntelligence actual;

            actual = target.NewAI;
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
        /// <summary>
        ///
        /// </summary>
        internal void OnUpdatedAI(IArtificialIntelligence artificialIntelligence, WorldEntity gameEntity)
        {
            EventHandler <UpdatedAIEventArgs> tempAfterEventArgs = m_EventUpdatedAI;

            if (tempAfterEventArgs != null)
            {
                UpdatedAIEventArgs eventArgs = new UpdatedAIEventArgs(artificialIntelligence, gameEntity);
                tempAfterEventArgs(this, eventArgs);
            }
        }
Exemple #10
0
 /// <summary>
 /// Unsubscribes a AI controler for it's lifespan updates.
 /// </summary>
 /// <param name="e"></param>
 public static void Unsubscribe(IArtificialIntelligence e)
 {
     if (e.Lifespan.IsRegistered)
     {
         NextThreadState = (e.Lifespan.LifespanThread - 1);
         LifespanThreads[(e.Lifespan.LifespanThread - 1)].Unregister(e);
         e.Lifespan.LifespanThread = 0;
         NumberSubscribedMobs--;
     }
 }
Exemple #11
0
        private void RunGameVsAI()
        {
            var    game   = _gameFactory.NewGame();
            Player player = default(Player);
            IArtificialIntelligence ai = null;

            switch (GetUserCommand(PlayerSelectMenu.Menu))
            {
            case PlayerSelectMenu.PlayAsX:
                player = Player.X;
                break;

            case PlayerSelectMenu.PlayAsO:
                player = Player.O;
                break;

            case UIMenu.Quit:
                return;
            }

            switch (GetUserCommand(AIMenu.Menu))
            {
            case AIMenu.BruteForce:
                ai = _gameFactory.NewArtificialIntelligence(ArtificialIntelligenceTypes.BruteForce);
                break;

            case AIMenu.OmniscientGod:
                //because some people were whining about it...
                if (_databaseBuilder.DatabaseIsEmpty())
                {
                    Populate();
                }

                ai = _gameFactory.NewArtificialIntelligence(ArtificialIntelligenceTypes.OmniscientGod);
                break;

            case UIMenu.Quit:
                return;
            }

            while (game.GameIsOver == false)
            {
                if (player == game.CurrentPlayer)
                {
                    MakeHumanMove(game);
                }
                else
                {
                    ai.MakeMove(game);
                }
            }

            RenderGameOver(game);
        }
Exemple #12
0
 //Constructor - this is private to force ppl to call the static function
 private EnemyBullet1(Texture2D loadedSprite, IArtificialIntelligence ai)
     : base(loadedSprite)
 {
     this.setIsKillerObject(true);
     this.setIsPickUp(false);
     if (ai != null)
     {
         setAI(ai);
         this.setPosition(this.getAI().getStartingPosition());
     }
 }
Exemple #13
0
        public void AITest()
        {
            WorldEntity             target   = CreateWorldEntity(); // TODO: 初始化为适当的值
            IArtificialIntelligence expected = null;                // TODO: 初始化为适当的值
            IArtificialIntelligence actual;

            target.AI = expected;
            actual    = target.AI;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
Exemple #14
0
        public MainForm()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;

            _computerIntelligence = new MinMaxAI();
            _music = new GameSounds();

            _game = new Game(_computerIntelligence);
            SubscribeEvents();
            _game.CreateNewGame();
        }
Exemple #15
0
 /// <summary>
 /// Subscribes a AI controler for it's lifespan updates.
 /// </summary>
 /// <remarks>
 /// The primairy target for this is to make them moveable.
 /// </remarks>
 /// <param name="e">Target who to subscribe</param>
 public static void Subscribe(IArtificialIntelligence e)
 {
     if (!e.Lifespan.IsRegistered)
     {
         int ThreadA = NextThreadState;
         int ThreadB = ThreadA + 1;
         LifespanThreads[ThreadA].Register(e);
         e.Lifespan.LifespanThread = ThreadB;
         NextThreadState = ++NextThreadState % LifespanThreads.Count;
         NumberSubscribedMobs++;
     }
 }
Exemple #16
0
 /// <summary>
 /// Subscribes a AI controler for it's lifespan updates.
 /// </summary>
 /// <remarks>
 /// The primairy target for this is to make them moveable.
 /// </remarks>
 /// <param name="e">Target who to subscribe</param>
 public static void Subscribe(IArtificialIntelligence e)
 {
     if (!e.Lifespan.IsRegistered)
     {
         int ThreadA = NextThreadState;
         int ThreadB = ThreadA + 1;
         LifespanThreads[ThreadA].Register(e);
         e.Lifespan.LifespanThread = ThreadB;
         NextThreadState = ++NextThreadState % LifespanThreads.Count;
         NumberSubscribedMobs++;
     }
 }
Exemple #17
0
 /// <summary>
 /// Unregisters a AI object
 /// </summary>
 /// <param name="c"></param>
 internal void Unregister(IArtificialIntelligence c)
 {
     try
     {
         IsWritting = true;
         c.Lifespan.lasttick = Environment.TickCount;
         ActivatedAI.Remove(c);
     }
     finally
     {
         IsWritting = false;
     }
 }
        public PlayerInputHandler(GameInfo info,
                                  BadgeSpawnPoint.Registry spawnRegistry,
                                  BadgeSpawner badgeSpawner,
                                  GameEvents gameEvents,
                                  IArtificialIntelligence ai)
        {
            Info          = info;
            SpawnRegistry = spawnRegistry;
            BadgeSpawner  = badgeSpawner;
            GameEvents    = gameEvents;
            Ai            = ai;

            Info.PropertyChanged    += OnGameInfoPropertyChanged;
            GameEvents.BadgeSpawned += OnBadgeSpawned;
        }
Exemple #19
0
 /// <summary>
 /// Registers a AI object
 /// </summary>
 /// <param name="c"></param>
 internal void Register(IArtificialIntelligence c)
 {
     try
     {
         IsWritting = true;
         //Add a random delay to make mobs appear they move pure random
         int rand = Saga.Managers.WorldTasks._random.Next(0, 1000);
         c.Lifespan.lasttick = Environment.TickCount + rand;
         ActivatedAI.Add(c);
     }
     finally
     {
         IsWritting = false;
     }
 }
 public void StartLocalGame(IArtificialIntelligence aiPlayer, int aiDelayMs = 250)
 {
     IsInSinglePlayerMode = true;
     if (_localGame == null)
     {
         _localGame = new LocalGame {
             AiCommandDelay = aiDelayMs
         };
         // TODO: WeakEventManager
         _localGame.SyncRequired +=
             (sender, args) => { Application.Current.Dispatcher.Invoke(() => SyncLocalGame()); };
     }
     _localGame.SetAi(aiPlayer);
     _localGame.InitGame();
     SyncLocalGame();
 }
Exemple #21
0
        /// <summary>
        ///
        /// </summary>
        public virtual void OnProcessSlice(DateTime updateDelta)
        {
            IArtificialIntelligence tempAI = m_ArtificialIntelligence;

            if (tempAI != null)
            {
                tempAI.SliceAI();
            }

            EventHandler <ProcessSliceEventArgs> tempEventArgs = m_EventSlice;

            if (tempEventArgs != null)
            {
                ProcessSliceEventArgs eventArgs = new ProcessSliceEventArgs(updateDelta, this);
                tempEventArgs(this, eventArgs);
            }
        }
Exemple #22
0
        public MainForm()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;

            _computerIntelligence = new MinMaxAI();
            _music = new GameSounds();

            _game = new Game(_computerIntelligence);
            _game.InitDrawHandler      += InitializeDraw;
            _game.UpdateScoreHandler   += UpdateScoreAndPlayerMove;
            _game.ShomMessageHandler   += ShowMessage;
            _game.PlayGoodSoundHandler += _music.PlayGoodSound;
            _game.PlayBadSoundHandler  += _music.PlayBadSound;

            _game.CreateNewGame();
        }
Exemple #23
0
 //Constructor - this is private to force ppl to call the static function
 private Enemy1(Texture2D loadedSprite, IArtificialIntelligence ai)
     : base(loadedSprite)
 {
     this.IsKillerObject = true;
     this.IsPickUp = false;
     this.fireTime = 0;
     this.fireCoolOff = MathHelper.Lerp(1000, 5000, (float)RandomGen.NextDouble());
     this.PointValue = 100;
     this.Health = 100;
     this.Damage = 100000; // ensure that this will kill the player despite shields, etc
     this.CanTakeDamage = true;
     DrawRotation = -MathHelper.PiOver2;
     DrawDepth = .4f;
     if (ai != null)
     {
         AI = ai;
         this.Position = this.AI.getStartingPosition();
     }
 }
Exemple #24
0
    /// <summary>
    /// Instantiates an AI to attack players
    /// </summary>
    private void InstantiateAI()
    {
        Debug.Log("instantiating AI");
        Debug.Log("spawn point is " + SceneInformation.AiSpawn);

        var aiInstantiation = (GameObject)GameObject.Instantiate(
            AIPrefab,
            SceneInformation.AiSpawn.position,
            SceneInformation.AiSpawn.rotation);

        Debug.Log("AI Instantiation: " + aiInstantiation);

        IArtificialIntelligence aiSceneCharacter = null;

        aiSceneCharacter = aiInstantiation.GetComponent <AI3D>();


        if (aiSceneCharacter == null)
        {
            throw new InvalidOperationException("AI prefab needs an AI component that matches the 3D/2D aspect of the game");
        }

        ////Debug.Log ("AI scene char: " + aiSceneCharacter);

        int charId = AI_ID_INDEX + AICount;

        AICount++;

        aiSceneCharacter.Server = this;
        ((Character)aiSceneCharacter.GetSceneChar()).Team = "AI";
        ((Character)aiSceneCharacter.GetSceneChar()).Id   = charId;

        Debug.Log("Adding AI character " + aiSceneCharacter.BaseCharacter.CharName + " with ID " + charId);

        SceneCharacters.Add(charId, aiSceneCharacter.GetSceneChar());
        foreach (var charId2 in SceneCharacters.Keys)
        {
            Debug.Log("Scene characters contains key: " + charId2);
        }

        GetComponent <NetworkView>().RPC("InitNewSceneCharacter", RPCMode.Others, aiSceneCharacter.BaseCharacter.Serialize());
    }
        static void Main(string[] args)
        {
            ShowMenu();

            _computerIntelligence = new MinMaxAI();
            _music = new GameSounds();
            _game  = new Game(_computerIntelligence);

            Subscribe();
            CreateGame(true);

            string key;
            char   option;
            bool   gameProcess = true;
            int    x = 0, y = 0;

            do
            {
                key = Console.ReadLine();
                if (key.Length < 2)
                {
                    if (char.TryParse(key.ToUpper(), out option))
                    {
                        MenuProcess(option, ref gameProcess);
                    }
                }
                else
                {
                    if (int.TryParse(key[0].ToString(), out x) && int.TryParse(key[1].ToString(), out y))
                    {
                        x--;
                        y--;
                    }
                    else
                    {
                        continue;
                    }
                    _game.MoveTo(x, y);
                }
            }while (gameProcess);
            Console.ReadLine();
        }
Exemple #26
0
        // Retrieves a bullet from the pool. If the pool is empty, it creates one from scratch.
        public static EnemyBullet1 getNewBullet(IArtificialIntelligence ai)
        {
            EnemyBullet1 bullet;
            // This must be called with an AI for the bullet
            if (ai == null)
                return null;
            // if there are any bullets in the pool, use one of them
            if (zs_pool.Count > 0)
            {
                bullet = zs_pool[zs_pool.Count - 1];
                bullet.setAI(ai);
                zs_pool.RemoveAt(zs_pool.Count - 1);
            }
            else
                bullet = new EnemyBullet1(zs_image, ai); // pool was empty, so create a new enemy

            // reset the enemy before use
            bullet.setIsAlive(true);
            return bullet;
        }
Exemple #27
0
        // Retrieves a new enemy from the pool. If the pool is empty, it creates one from scratch.
        public static Enemy1 getNewEnemy(IArtificialIntelligence ai)
        {
            Enemy1 enemy;
            // This must be called with an AI for the critter
            if (ai == null)
                return null;
            // if there are any enemies in the pool, use one of them
            if (zs_pool.Count > 0)
            {
                enemy = zs_pool[zs_pool.Count - 1];
                enemy.setAI(ai);
                zs_pool.RemoveAt(zs_pool.Count - 1);
            }
            else
                enemy = new Enemy1(zs_image, ai); // pool was empty, so create a new enemy

            // reset the enemy before use
            enemy.setIsAlive(true);
            return enemy;
        }
Exemple #28
0
        private static Controller CreateGame(int numberOfPlayers, Random rnd, StreamReader reader, StreamWriter writer)
        {
            Controller controller = new Controller(numberOfPlayers, rnd);
            Game       game       = controller.game;

            // Create players:
            for (int i = 0; i < numberOfPlayers; i++)
            {
                IArtificialIntelligence AI = null;
                if (i == 0)
                {
                    AI = new AIWeighedMovesV2(game, reader, writer);
                }
                else
                {
                    AI = new AIWeighedMoves(game);
                }
                AI.Initialize();
                controller.CreatePlayer(false, AI, Player.Colors[i]);
            }
            return(controller);
        }
Exemple #29
0
        public MediumAI(Board userBoard)
        {
            _userBoard = userBoard;

            _easyAI = new EasyAI(userBoard);
            _hardAI = new HardAI(userBoard);

            _fieldList = new List <Field>();
            for (int y = 0; y < _userBoard.Height; y++)
            {
                for (int x = 0; x < _userBoard.Width; x++)
                {
                    Coordinate coordinate = new Coordinate(x, y);
                    _fieldList.Add(_userBoard.GetField(coordinate));
                }
            }

            _difficltyToUse = new List <Difficulty>();
            _difficltyToUse.Add(Difficulty.Hard);
            _difficltyToUse.Add(Difficulty.Hard);
            _difficltyToUse.Add(Difficulty.Hard);
            _difficltyToUse.Add(Difficulty.Hard);
            _difficltyToUse.Add(Difficulty.Easy);
        }
        public void StartGame(Nou p1, IArtificialIntelligence p2)
        {
            P1 = p1;
            P2 = p2;
            if (Game != null)
            {
                Game.PropertyChanged -= Game_PropertyChanged;
                Game.SyncRequired    -= Game_SyncRequired;
            }
            Round = 0;
            Game  = new LocalGame();
            Game.SetAi(p1, 1);
            Game.SetAi(p2, 2);
            Game.InitGame();

            Game.AiCommandDelay = AiDelay;

            Game.PropertyChanged += Game_PropertyChanged;
            Game.SyncRequired    += Game_SyncRequired;

            NeedsUiUpdate?.Invoke(this, EventArgs.Empty);
            ++Round;
            Task.Run(async() => await Game.AiPlayer1Move());
        }
 public void SetInfo(IHumanPlayer player,
                     IArtificialIntelligence ai,
                     IList <IMonsterCard> playerMonsters,
                     IList <IManaCostable> playerEffects,
                     IList <IMonsterCard> aiMonsters,
                     IList <IManaCostable> aiEffects,
                     int playerRemaining,
                     int aiRemaining,
                     Phases phase,
                     bool playersTurn,
                     bool playerIsTarget)
 {
     this.Player               = player;
     this.AI                   = ai;
     this.PlayerMonsters       = playerMonsters;
     this.PlayerEffects        = playerEffects;
     this.AIMonsters           = aiMonsters;
     this.AIEffects            = aiEffects;
     this.PlayerCardsRemaining = playerRemaining;
     this.AICardsRemainig      = aiRemaining;
     this.Phase                = phase;
     this.PlayersTurn          = playersTurn;
     this.PlayerIsTarget       = playerIsTarget;
 }
Exemple #32
0
 /// <summary>
 /// Registers a AI object
 /// </summary>
 /// <param name="c"></param>
 internal void Register(IArtificialIntelligence c)
 {
     try
     {
         IsWritting = true;
         //Add a random delay to make mobs appear they move pure random
         int rand = Saga.Managers.WorldTasks._random.Next(0, 1000);
         c.Lifespan.lasttick = Environment.TickCount + rand;
         ActivatedAI.Add(c);
     }
     finally
     {
         IsWritting = false;
     }
 }
Exemple #33
0
 /// <summary>
 /// Unregisters a AI object
 /// </summary>
 /// <param name="c"></param>
 internal void Unregister(IArtificialIntelligence c)
 {
     try
     {
         IsWritting = true;
         c.Lifespan.lasttick = Environment.TickCount;
         ActivatedAI.Remove(c);
     }
     finally
     {
         IsWritting = false;
     }
 }
Exemple #34
0
 /// <summary>
 /// Checks if the AI controler is subscribed.
 /// </summary>
 /// <param name="e">AI controler to check</param>
 /// <returns>True if the controller is subscribed</returns>
 public static bool IsSubscribed(IArtificialIntelligence e)
 {
     return e.Lifespan.IsRegistered;
 }
Exemple #35
0
 /// <summary>
 /// Unsubscribes a AI controler for it's lifespan updates.
 /// </summary>
 /// <param name="e"></param>
 public static void Unsubscribe(IArtificialIntelligence e)
 {
     if (e.Lifespan.IsRegistered)
     {
         NextThreadState = (e.Lifespan.LifespanThread - 1);
         LifespanThreads[(e.Lifespan.LifespanThread - 1)].Unregister(e);
         e.Lifespan.LifespanThread = 0;
         NumberSubscribedMobs--;
     }
 }
 public void Initialize(Player currentPlayer)
 {
     CurrentPlayer = currentPlayer;
     CurrentAI     = currentPlayer.AI;
     FightPhase    = FightPhase.PLACEMENT;
 }
 /// <summary>
 /// 
 /// </summary>
 internal void OnUpdatedAI( IArtificialIntelligence artificialIntelligence, WorldEntity gameEntity )
 {
     EventHandler<UpdatedAIEventArgs> tempAfterEventArgs = m_EventUpdatedAI;
     if ( tempAfterEventArgs != null )
     {
         UpdatedAIEventArgs eventArgs = new UpdatedAIEventArgs( artificialIntelligence, gameEntity );
         tempAfterEventArgs( this, eventArgs );
     }
 }
 /// <summary>
 /// 初始化构造
 /// </summary>
 /// <param name="baseCreature"></param>
 public UpdatedAIEventArgs( IArtificialIntelligence artificialIntelligence, WorldEntity gameEntity ) :
     base( gameEntity )
 {
     m_OldArtificialIntelligence = artificialIntelligence;
 }
Exemple #39
0
 /// <summary>
 /// Ubsubscribes the Lifespan Object
 /// </summary>
 public void Unsubscribe(IArtificialIntelligence ai)
 {
     LifespanAI.Unsubscribe(ai);
 }
Exemple #40
0
 /// <summary>
 /// Ubsubscribes the Lifespan Object
 /// </summary>
 public void Unsubscribe(IArtificialIntelligence ai)
 {
     LifespanAI.Unsubscribe(ai);
 }
Exemple #41
0
 public ProductionHandler(IArtificialIntelligence ai, IEventAgent eventAgent, PositionHandler positionHandler)
 {
     _ai = ai;
     _eventAgent = eventAgent;
     _positionHandler = positionHandler;
 }
Exemple #42
0
 public void transferAI(IArtificialIntelligence ai)
 {
     z_AI = ai;
 }
Exemple #43
0
 public BasicGameEngine()
 {
     PlayerBids             = new PlayerBids();
     ArtificialIntelligence = new ArtificialIntelligence();
 }
Exemple #44
0
 /// <summary>
 /// Checks if the AI controler is subscribed.
 /// </summary>
 /// <param name="e">AI controler to check</param>
 /// <returns>True if the controller is subscribed</returns>
 public static bool IsSubscribed(IArtificialIntelligence e)
 {
     return e.Lifespan.IsRegistered;
 }
Exemple #45
0
 public virtual void OnParentChanged(ParentChangedEngineEventArgs args, IArtificialIntelligence ai, IArtificialIntelligenceState currentState)
 {
 }
 public Player(int teamId)
 {
     this.teamId = teamId;
     //this.ai = new AI.Rush();
     this.ai = new AI.Basic();
 }