예제 #1
0
        public async void CheckAITurn(CancellationToken cancellationToken,
                                      bool find, AILevels aiLevel)
        {
            if (gameManager.IsPlayerOnTurnAI || find)
            {
                IsEngineThinking = true;
                EngineThinkingChanged(true);
                gameManager.Move = await GetAITurn(cancellationToken, aiLevel);

                if (cancellationToken.IsCancellationRequested)
                {
                    IsEngineThinking = false;
                    EngineThinkingChanged(false);
                    gameManager.IsGameEndTriggered(gameManager.GameBoard.GameArray);
                    PrintBoard(gameManager.GameBoard.GameArray);

                    cancellationTokenSource = new CancellationTokenSource();
                    return;
                }

                if (find)
                {
                    RecommendedMove = new List <int>(gameManager.Move);
                    OutputMessage(SendBestMoveToOutput(RecommendedMove));
                    IsEngineThinking = false;
                    EngineThinkingChanged(false);
                    RecommendedMove.Clear();
                    gameManager.Move.Clear();
                    gameManager.IsGameEndTriggered(gameManager.GameBoard.GameArray);
                    return;
                }

                GameTurn();
            }
        }
예제 #2
0
 public List <int> GetAITurn(CancellationToken cancellationToken, AILevels aiLevel)
 {
     ArtificialIntelligence.MoveList = new List <List <int> >(MoveList);
     int[,] testArray = CloneArray(GameBoard.GameArray);
     Move             = ArtificialIntelligence.FindBestMove(cancellationToken, aiLevel, testArray, IsPlayerWTurn);
     return(Move);
 }
예제 #3
0
        public int CreateNpc(Ship ship, AILevels ai, Npc motherShip)
        {
            var id = GetNextAvailableId();

            ship.AI = (int)ai;
            var position = motherShip.Position;

            CreateNpc(new Npc(id, ship.Name,
                              new Hangar(0, ship, new Dictionary <int, Drone>(), position, this, ship.Health, ship.Nanohull),
                              0, position, this, ship.Health, 0, ship.Shield,
                              ship.Shield, ship.Health, ship.Damage, ship.Reward, 0, false, motherShip));
            return(id);
        }
예제 #4
0
        public void CreateNpc(Ship ship, AILevels ai, bool respawning, int respawnTime, Vector pos = null, int vwId = 0)
        {
            var id = GetNextAvailableId();

            ship.AI = (int)ai;
            if (pos == null)
            {
                pos = Vector.Random(this, 1000, 20000, 1000, 12000);
            }
            else
            {
                pos = Vector.GetPosOnCircle(pos, 100);
            }
            CreateNpc(new Npc(id, ship.Name,
                              new Hangar(ship, new List <Drone>(), pos, this, ship.Health, ship.Nanohull,
                                         new Dictionary <string, Item>()),
                              0, pos, this, ship.Health, ship.Nanohull, ship.Reward, ship.Shield,
                              ship.Damage, respawnTime, respawning)
            {
                VirtualWorldId = vwId
            });
        }
예제 #5
0
        public Npc CreateNpc(Ship ship, AILevels ai, bool respawning, int respawnTime, Vector pos = null, int vwId = 0, string namePrefix = "", Reward reward = null)
        {
            var id = GetNextAvailableId();

            ship.AI = (int)ai;
            if (pos == null)
            {
                pos = Vector.Random(this, new Vector(1000, 1000), new Vector(20000, 12000));
            }
            else
            {
                pos = Vector.GetPosOnCircle(pos, 100);
            }

            var name = ship.Name;

            if (namePrefix != "")
            {
                name += " " + namePrefix;
            }

            if (reward == null)
            {
                reward = ship.Reward;
            }

            var npc = new Npc(id, name,
                              new Hangar(0, ship, new Dictionary <int, Drone>(), pos, this, ship.Health, ship.Nanohull),
                              0, pos, this, ship.Health, 0, ship.Shield,
                              ship.Shield, ship.Health, ship.Damage, reward, respawnTime, respawning)
            {
                VirtualWorldId = vwId
            };

            CreateNpc(npc);
            return(npc);
        }
예제 #6
0
        public static List <int> FindBestMove(CancellationToken cancellationToken, AILevels aILevel, int[,] gameArray, bool isPlayerWTurn)
        {
            if (aILevel == 0)
            {
                return(MoveList[AppConstants.Rnd.Next(MoveList.Count)]);
            }

            AppConstants.Depth = (int)aILevel;

            OutputRating = -AppConstants.Max;
            OutputMove?.Clear();
            IsPlayerWTurn = isPlayerWTurn;

            CountedGameScore     = CountGameScore(gameArray);
            CountedKingsDistance = CountKingsDistance(gameArray);
            CountedPawnsDistance = CountPawnsDistance(gameArray);

            MoveList.Shuffle();
            foreach (var move in MoveList.ToList())
            {
                DoTempMove(move, gameArray);
                int rating = -AlphaBeta(gameArray, AppConstants.Depth, false, -AppConstants.Max, Dal(AppConstants.Max), cancellationToken);
                UndoTempMove(move, gameArray);
                //Increases the value for frozing moves
                rating += (Hunting((move[5]), (move[6])) * (AppConstants.Depth + 1));

                //Console.WriteLine($"Final output move {string.Join("",move)} rating {rating}");
                if (rating > OutputRating)
                {
                    OutputRating = rating;
                    OutputMove   = move;
                }
            }
            //Console.WriteLine(Count);
            return(OutputMove);
        }
예제 #7
0
        public async Task <List <int> > GetAITurn(CancellationToken cancellationToken, AILevels aiLevel)
        {
            var myTask = Task.Run(() => gameManager.GetAITurn(cancellationToken, aiLevel));
            var Move   = await myTask;

            return(Move);
        }
예제 #8
0
 public void CheckAITurn(AILevels aILevel, bool isTrue = false)
 {
     cancellationTokenSource = new CancellationTokenSource();
     CheckAITurn(cancellationTokenSource.Token, isTrue, aILevel);
 }
예제 #9
0
 public GameLogic(GameTypes type, AILevels Difficulty = AILevels.None)
 {
     // type 0 == AI, 1 == Local
     gameType = type;
     AILevel  = Difficulty;
 }