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(); } }
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); }
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); }
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 }); }
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); }
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); }
public async Task <List <int> > GetAITurn(CancellationToken cancellationToken, AILevels aiLevel) { var myTask = Task.Run(() => gameManager.GetAITurn(cancellationToken, aiLevel)); var Move = await myTask; return(Move); }
public void CheckAITurn(AILevels aILevel, bool isTrue = false) { cancellationTokenSource = new CancellationTokenSource(); CheckAITurn(cancellationTokenSource.Token, isTrue, aILevel); }
public GameLogic(GameTypes type, AILevels Difficulty = AILevels.None) { // type 0 == AI, 1 == Local gameType = type; AILevel = Difficulty; }