コード例 #1
0
ファイル: ZombieShow.cs プロジェクト: ybbbby/Client_IDG_YISHI
    // protected GunBase gun;

    //public AiEngine ai;
    public override void Start()
    {
        base.Start();
        maxHealth = 300.ToFixed();
        _m_Hp     = 300.ToFixed();
        this.tag  = "Zombie";
        if (ai != null)
        {
        }
        else
        {
            //  UnityEngine.Debug.LogError("ai is Null");
            ai        = new AiEngine();
            ai.aiName = "AI_test";
            ai        = AddCommponent <AiEngine>(ai);
        }
        team       = 2;
        move_speed = 0.7f.ToFixed();
        weaponSystem.AddWeapon(WeaponId.丧尸);

        // gun = new GunBase();
        // rigibody.useCheck=true;
        // var ai=new AiEngine();
        // ai.aiName="AI_test";
        // ai.aiActionFunc=AiAction;
        // ai=AddCommponent<AiEngine>(ai);



        // gun.Init(2, this);
    }
コード例 #2
0
 private void SetupParameters()
 {
     gamemode   = ((string)GamemodeButton.Content) == "Player vs Ai" ? Gamemode.PlayerVsAi : Gamemode.AiVsAi;
     methodType = ((string)MethodButton.Content) == MethodType.AlphaBeta.ToString() ? MethodType.AlphaBeta : MethodType.MinMax;
     depth      = (int)DifficultySlider.Value;
     aiEngine   = new AiEngine(depth);
     if (AiStartDockPanel.Visibility == Visibility.Visible)
     {
         aiStartPos = (int)AiStartSlider.Value;
     }
 }
コード例 #3
0
        public void GetBestMoveTest(string input, Color color1, Color color2, int expeceted)
        {
            var matrix    = input.StringToByteMatrix(10);
            var weights   = new TsitsiklisWeights(1, 3);
            var algorithm = new Tsitsiklis(weights);
            var manager   = new BoardManager(matrix);

            manager.SpawnPill(color1, color2);
            var engine   = new AiEngine(algorithm);
            var bestMove = engine.GetNextMove(manager);

            Assert.AreEqual(expeceted, bestMove.Fitness);
        }
コード例 #4
0
 public MainWindow()
 {
     InitializeComponent();
     worker = new BackgroundWorker();
     worker.WorkerSupportsCancellation = true;
     aiEngine = new AiEngine(depth);
     program  = new Program();
     InitPanels();
     GamemodeButton.Content      = gamemode == Gamemode.PlayerVsAi ? "Player vs Ai" : "Ai vs Ai";
     MethodButton.Content        = methodType == MethodType.MinMax ? MethodType.MinMax.ToString() : MethodType.AlphaBeta.ToString();
     AiStartDockPanel.Visibility = gamemode == Gamemode.PlayerVsAi ? Visibility.Hidden : Visibility.Visible;
     AiStart.Visibility          = gamemode == Gamemode.PlayerVsAi ? Visibility.Hidden : Visibility.Visible;
 }
コード例 #5
0
 public override void Start()
 {
     base.Start();
     maxHealth = 300.ToFixed();
     _m_Hp     = 300.ToFixed();
     this.tag  = "Zombie";
     if (ai != null)
     {
     }
     else
     {
         ai        = new AiEngine();
         ai.aiName = "AI_test";
         ai        = AddCommponent <AiEngine>(ai);
     }
     team       = 2;
     move_speed = 0.7f.ToFixed();
     weaponSystem.AddWeapon(WeaponId.丧尸);
 }
コード例 #6
0
        public void MovesAreCorrect(string input, Move[] expeceted)
        {
            var matrix  = input.StringToByteMatrix(8);
            var weights = new AiWeights()
            {
                PillsCleared  = -100,
                WellSums      = 1,
                NumberOfHoles = 10,
            };
            var algorithm = new FeatureAi(weights);
            var manager   = new BoardManager(matrix);

            manager.SpawnPill(Color.Red, Color.Blue);
            var engine = new AiEngine(algorithm);

            var bestMove = engine.GetNextMove(manager);
            var moves    = bestMove.Moves;

            Assert.IsTrue(bestMove.IsValid);

            Console.WriteLine(JsonConvert.SerializeObject(bestMove));
            foreach (var move in moves)
            {
                manager.Move(move);
                Console.WriteLine(manager.GameBoard.MatrixToString(manager.ActivePill));
            }
            while (manager.ActivePill != null)
            {
                manager.Move(Move.Down);
                Console.WriteLine(manager.GameBoard.MatrixToString(manager.ActivePill));
            }

            Assert.AreEqual(expeceted.Where(x => x == Move.Right).Count(), moves.Where(x => x == Move.Right).Count());
            Assert.AreEqual(expeceted.Where(x => x == Move.Left).Count(), moves.Where(x => x == Move.Left).Count());
            Assert.AreEqual(expeceted.Where(x => x == Move.RotateLeft).Count(),
                            moves.Where(x => x == Move.RotateLeft).Count());
            Assert.AreEqual(expeceted.Where(x => x == Move.RotateRight).Count(),
                            moves.Where(x => x == Move.RotateRight).Count());
            Assert.That(bestMove.Fitness, Is.AtMost(1), "Fitness");
        }
コード例 #7
0
 public Move MakeMove(Grid grid)
 {
     return(makeMove(grid, AiEngine.GenerateMove(grid, Team).Position));
 }
コード例 #8
0
ファイル: Program.cs プロジェクト: cbpetersen/dr-mario-engine
        static void Main(string[] args)
        {
            var uiEnabled = false;
            var gameCount = 0;

            Engine.Random.Instance().SetNewSeed(123);
            _colorMap = MapColors();
            var httpclient        = new ApiClient.ApiClient(new Uri("http://localhost:3000"));
            var algorithmSettings = new AlgorithmSetting <AiWeights>();
            var moves             = new Stack <Move>();

            while (true)
            {
                try
                {
                    algorithmSettings = httpclient.GetAlgorithmSettings <FeatureAi, AiWeights>(
                        new AlgorithmSetting <AiWeights> {
                        Name = "Dr Mario - Engine"
                    });
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    Console.WriteLine($"Error: retrying in a sec");
                    Thread.Sleep(1000);
                    continue;
                }

                var gameManager = new GameManager(20, 10);
                gameManager.AddBacterias(15, 3);
                var         ai           = new AiEngine(new FeatureAi(algorithmSettings.Weights));
                IEnumerator moveIterator = null;
                AI.Move     aiMove       = null;
                var         blockNumber  = -1;
                while (!gameManager.GameState.IsGameOver())
                {
                    if (uiEnabled)
                    {
                        PrintState(gameManager, moves, aiMove);
                    }

                    Thread.Sleep(2);

                    gameManager.OnGameLoopStep();

                    if (moveIterator != null && moveIterator.MoveNext())
                    {
                        gameManager.MoveBlock((Move)moveIterator.Current);
                        moves.Push((Move)moveIterator.Current);
                        continue;
                    }

                    // Make sure we only calculate best move once per spawned block.
                    if (blockNumber != gameManager.GameStats.PillsSpawned)
                    {
                        aiMove       = ai.GetNextMove(gameManager.BoardManager);
                        moveIterator = aiMove.Moves.GetEnumerator();
                        blockNumber  = gameManager.GameStats.PillsSpawned;
                    }

                    if (gameManager.Bacterias.Count < BacteriaCount)
                    {
                        var color = gameManager.Bacterias.GroupBy(x => x.Color).OrderByDescending(o => o.Count()).First().Key;
                        gameManager.AddBacteria(color);
                    }
                }

                if (uiEnabled)
                {
                    Console.Clear();
                    Console.Write("Game Over {0}", gameManager.GameStats.Fitness);
                    Console.WriteLine();
                    Console.WriteLine();
                }
                else
                {
                    Console.Write("{0}, ", gameManager.GameStats.Fitness);
                }

                try
                {
                    httpclient.PostStats(new GameResult <AiWeights>(algorithmSettings)
                    {
                        PillsSpawned = gameManager.GameStats.PillsSpawned,
                        Bacterias    = gameManager.GameStats.TotalBacteriaClearings,
                        Pills        = gameManager.GameStats.TotalPillClearings,
                        Fitness      = gameManager.GameStats.Fitness
                    });
                    gameCount++;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    Thread.Sleep(1000);
                }

                Thread.Sleep(50);
                if (uiEnabled)
                {
                    Thread.Sleep(5000);
                }
            }
        }