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); }
void TakeTurn() { // At the start of the turn, do a checkup on the fighters for (int i = 0; i < fighter.Length; i++) { fighter[i].stateData.Update(turn); fighter[i].CheckUp(map); } // We must reset the tile renderings map.ResetAllTiles(); // if (humansInvolved[turn]) { // check if the 3 variables have changed since the last frame if (p_D != dist || p_aX != angleX || p_aY != angleY) { // Get the movement data outp[turn] = Map.OutputLocation(map, fighter[turn].expression, fighter[turn == 0 ? 1 : 0].expression, dist, angleX, angleY, humanUsing: true); // if (dist >= .5f) { fighter[turn].RanAway(); } // if (outp[turn] != null) { p_D = dist; p_aX = angleX; p_aY = angleY; } } // Set camera to turnee map.SetCamTo(Map.camMode, turn); // if (fighter[turn].isStunned) { StartCoroutine(map.FIGHT(time, map, turn)); // incriment the turn _turn++; p_D = -1; p_aY = -1; p_aX = -1; } else { if (Input.GetKeyDown(KeyCode.Space)) { // start our Coroutine of moving our fighter StartCoroutine(map.MoveFighter(time, outp[turn].loc.Count > 0, map, turn, outp[turn].path)); // incriment the turn _turn++; p_D = -1; p_aY = -1; p_aX = -1; } else if (Input.GetKeyDown(KeyCode.Backspace)) { StartCoroutine(map.FIGHT(time, map, turn)); // incriment the turn _turn++; p_D = -1; p_aY = -1; p_aX = -1; } } } else { // OutputMakeMove s = OutputMakeMove.CalculateNormal(fighter[turn]); // Calculate if moving if (s.stay || fighter[turn].isStunned) { // calculate if AI even wants to battle OutputToBattle oB = OutputToBattle.CalculateOutput(fighter[turn]); // if the result of oB is to battle, if (oB.toBattle) { // start the coroutine to start the fight StartCoroutine(map.FIGHT(time, map, turn)); } else // otherwise we'll just entirely skip its turn { GM.turnSyncer++; } // incriment the turn _turn++; } else { // Calculate the move output OutputMove m = OutputMove.CalculateOutput(fighter[turn]); // if (m.distance >= .5f) { fighter[turn].RanAway(); } // Get the movement data outp[turn] = Map.OutputLocation(map, fighter[turn].expression, fighter[turn == 0 ? 1 : 0].expression, m.distance, m.angleX, m.angleY); // start our Coroutine of moving our fighter StartCoroutine(map.MoveFighter(time, outp[turn].loc.Count > 0, map, turn, outp[turn].path)); // incriment the turn _turn++; } } // turnTxt.text = $"{GM.timer}"; }