// Use this for initialization void Start() { if ((FSM = this.GetComponent (typeof(AICore)) as AICore) == null) { Debug.Log ("Failed to get AICore script"); } _isDead = false; }
void Update() { // if we have proximity targets, modify the flicker rate to a max, // based on distance between the two if (proximityFlicker == true) { float currentDistance = Vector3.Distance(DataCore.player.transform.position, proximityToTarget.transform.position); flickerRate = AICore._IsItMin(currentDistance, 0.0f, proximity); } // flicker the color renderer.material.color = Color.Lerp(c[0], c[1], t); if (!change) { t += flickerRate * Time.deltaTime; } else { t -= flickerRate * Time.deltaTime; } if (t >= 1) { change = true; } if (t <= 0) { change = false; } }
private void Init() { Bitmap bmp = new Bitmap(this.mapName); grid = new Grid(bmp, this.gridPanel); Logger.AddInfo("Map loaded: " + bmp.Width.ToString() + "; " + bmp.Height.ToString()); ai = new AICore(grid); string[] npcList = File.ReadAllLines(Directory.GetCurrentDirectory() + "\\Settings\\level1npc.ini"); characters = new WiccanRede.AI.CharacterNPC[npcList.Length]; Entity[] entities = new Entity[npcList.Length]; for (int i = 0; i < npcList.Length; i++) { try { characters[i] = new WiccanRede.AI.CharacterNPC("Settings\\" + npcList[i] + ".xml"); //ai.AddPlayer(characters[i], new Microsoft.DirectX.Vector3(i, i, i), new Entity(), "BasicFSM"); entities[i] = new Entity(characters[i], ai, "BasicFSM"); } catch (Exception ex) { Logging.Logger.AddWarning("Chyba pri nacitani NPC: " + npcList[i] + " - " + ex.ToString()); } } }
private void Awake() { pathfinder = GameObject.FindObjectOfType <PathfinderAStar>(); pathRequester = GameObject.FindObjectOfType <PathRequester>(); navAgent = GetComponent <NavAgent>(); parentAICore = GetComponent <AICore>(); }
void Start() { game = new FourInRowGame(7, 6, 2, 4, this); aICore = new AICore(game, 1000); firstImg.sprite = GameManager.firstPlayerSkin.roundSprite; secondImg.sprite = GameManager.secondPlayerSkin.roundSprite; PrepareScoreSize(firstImg); PrepareScoreSize(secondImg); scoreText.text = game.GetScore(); InitiatePools(); pauseSlider.gameObject.SetActive(!(GameManager.CurrentPlayMode == PlayMode.TwoPlayers)); switch (GameManager.CurrentPlayMode) { case PlayMode.Multiplayer: break; case PlayMode.TwoAI: playTask = BothAIPlayTask; break; case PlayMode.TwoPlayers: playTask = TwoPlayersTask; break; case PlayMode.WithAI: playTask = PlayWithAITask; break; } }
void SpawnEnemies(int count) { for (int i = 0; i < count; i++) { GameObject go = Instantiate(ZombiePrefab, AICore.GetRandomMapPosition(), Quaternion.identity, GameObject.FindGameObjectWithTag("ENEMY_CONTAINER").transform); } }
/// <summary> /// Initializes a new instance of the <see cref="AIvsAIMode"/> class. /// </summary> /// <param name="consoleManager">The console manager.</param> /// <param name="commandsManager">The commands manager.</param> public AIvsAIMode(ConsoleManager consoleManager, CommandsManager commandsManager) : base(consoleManager, commandsManager) { _whiteAI = new AICore(); _blackAI = new AICore(); _currentColor = Color.White; CalculateBitboard(new DefaultFriendlyBoard(), false); SetCommandHandlers(); }
public void aiAct() { Debug.Log("A enemy does their turn!"); int i = 0; while (actionsLeft > 0 && i < 99) { AIAction a = AICore.decide(AICore.oneDeep(this)); attemptToUseCard(a.card, a.target); i++; } Handler.h.nextTurn(); }
/// <summary> /// WiccanRede.AI controlled npc with script /// </summary> /// <param name="character">his character</param> /// <param name="logic"> GameLogic object - used for interaction, respawn, etc, contains AICore object</param> /// <param name="position">absolute position on map</param> /// <param name="scriptPath">path to the script file</param> public GameNPC(CharacterNPC character, Game.GameLogic logic, string scriptPath, Vector3 position) { this.ai = logic.Ai; this.logic = logic; this.character = character; this.position = position; this.scriptPath = scriptPath; this.actionDefinition = ""; this.direction = new Vector3(1, 0, 0); JoinToGraphic(character); logic.Ai.AddPlayer(character, position, this, scriptPath); }
//IWalkable terrain; //static List<GameNPC> players = new List<GameNPC>(); /// <summary> /// WiccanRede.AI controlled npc /// </summary> /// <param name="character">his character</param> /// <param name="logic">GameLogic object - used for interaction, respawn, etc, contains AICore object</param> /// <param name="position">absolute position on map</param> /// <param name="fsmName">name of FSM plug-in which will be loaded for this NPC</param> /// <param name="actionDefinition">name of config xml file with definitions of actions</param> public GameNPC(CharacterNPC character, Game.GameLogic logic, string fsmName, Vector3 position, string actionDefinition) { this.ai = logic.Ai; this.logic = logic; this.character = character; this.position = position; this.fsmName = fsmName; this.actionDefinition = actionDefinition; this.direction = new Vector3(1, 0, 0); JoinToGraphic(character); logic.Ai.AddPlayer(character, position, this, fsmName, actionDefinition); }
/// <summary> /// Checks if king with the specified color is in stalemate. /// </summary> /// <param name="color">The king color.</param> /// <returns>True if king with specified color is in stalemate, otherwise false.</returns> public bool IsStalemate(Color color) { if (!_calculated) { throw new BitboardNotCalculatedException(); } var bitboardWithoutEnPassant = new Bitboard(this); bitboardWithoutEnPassant.EnPassant[(int)color] = 0; var ai = new AICore(); var aiResult = ai.Calculate(color, bitboardWithoutEnPassant, 0, 0); return(!IsCheck(color) && Math.Abs(aiResult.Score) == AIConstants.MateValue); }
/// <summary> /// Initializes a new instance of the <see cref="PlayervsAIMode"/> class. /// </summary> /// <param name="consoleManager">The console manager.</param> /// <param name="commandsManager">The commands manager.</param> public PlayervsAIMode(ConsoleManager consoleManager, CommandsManager commandsManager) : base(consoleManager, commandsManager) { _ai = new AICore(); _history = new List <Move>(); _openingBook = new OpeningBookProvider(); _currentColor = Color.White; _done = false; CalculateBitboard(new DefaultFriendlyBoard(), false); VisualBoard.OnFieldSelection += Board_OnFieldSelection; VisualBoard.OnPieceMove += Board_OnPieceMove; PromotionWindow.OnPromotionSelection += PromotionWindow_OnPromotionSelection; SetCommandHandlers(); }
/// <summary> /// Runs AI calculating. /// </summary> /// <param name="command">The AI command</param> private void CalculateBestMove(Command command) { var colorArgument = command.GetArgument <string>(0); var preferredTimeArgument = command.GetArgument <float>(1); var helperTasksCount = command.GetArgument <int>(2); var colorParseResult = Enum.TryParse(colorArgument, true, out Color color); if (!colorParseResult) { ConsoleManager.WriteLine($"$rInvalid color type ($R{color}$r)"); return; } var ai = new AICore(); var aiResult = ai.Calculate(color, Bitboard, preferredTimeArgument, helperTasksCount); ConsoleManager.WriteLine(); if (aiResult.PVNodes.Count == 0) { ConsoleManager.WriteLine("$gMate"); } else { ConsoleManager.WriteLine($"$wDepth: $g{aiResult.Depth}"); ConsoleManager.WriteLine($"$wTotal nodes: $g{aiResult.Stats.TotalNodes} N"); ConsoleManager.WriteLine($"$wEnd nodes: $g{aiResult.Stats.EndNodes} N"); ConsoleManager.WriteLine($"$wα-β cutoffs: $y{aiResult.Stats.AlphaBetaCutoffs} N"); ConsoleManager.WriteLine($"$wTT hits: $y{aiResult.Stats.TranspositionTableHits} N"); ConsoleManager.WriteLine($"$wBranching factor: $y{aiResult.Stats.BranchingFactor}"); ConsoleManager.WriteLine($"$wNodes per second: $c{aiResult.NodesPerSecond / 1000} kN"); ConsoleManager.WriteLine($"$wTime per node: $c{aiResult.TimePerNode} ns"); ConsoleManager.WriteLine($"$wTime: $m{aiResult.Time} s"); ConsoleManager.WriteLine(); ConsoleManager.WriteLine($"$wQ Total nodes: $g{aiResult.Stats.QuiescenceTotalNodes} N"); ConsoleManager.WriteLine($"$wQ End nodes: $g{aiResult.Stats.QuiescenceEndNodes} N"); ConsoleManager.WriteLine(); ConsoleManager.WriteLine($"$wBest move: $g{aiResult.PVNodes}"); ConsoleManager.WriteLine($"$wScore: $m{aiResult.Score}"); } ConsoleManager.WriteLine(); }
public void CreateAI(BoardWar myBoard, BoardWar theirBoard, int type, int difficulty = 0) { switch (type) { case (int)PersistData.GT.Training: AI = new TrainingAI(myBoard, theirBoard, this); break; case (int)PersistData.GT.Challenge: AI = new TrainingAI(myBoard, theirBoard, this); break; default: AI = new AIversion2(myBoard, theirBoard, this, difficulty); break; } if (type == (int)PersistData.GT.Training && difficulty == 2) { AI.forceState(3); } if (PD.GetSaveData().savedOptions["easymode"] == 1) { AI.EasyModo(); AI.boostDifficulty(difficulty); } }
/// <summary> /// Initializes a new instance of the <see cref="GameSession"/> class. /// </summary> /// <param name="helperThreadsCount">The helper threads count.</param> public GameSession(int helperThreadsCount) { _helperThreadsCount = helperThreadsCount; _aiCore = new AICore(); _aiCore.OnThinkingOutput += AICore_OnThinkingOutput; Bitboard = new Bitboard(new DefaultFriendlyBoard()); _preferredTimeCalculator = new PreferredTimeCalculator(50); _remainingTime = new[] { 999999999, 999999999 }; _history = new List <Move>(); _openingBook = new OpeningBookProvider(); }
// Use this for initialization void Awake() { FSM = GetComponentInParent(typeof(AICore)) as AICore; }
// _SeekTarget : Seeks out the indicated target and returns true when reached static public bool _SeekTarget(Component bot, Vector3 target, float fMaxVelocity) { float fTargetDistance; float zIsTargetBehindMe, zIsTargetInFrontOfMe, zIsTargetToMyLeft, zIsTargetToMyRight; AICore._GetSpatialAwareness2D(bot, target, out fTargetDistance, out zIsTargetBehindMe, out zIsTargetInFrontOfMe, out zIsTargetToMyLeft, out zIsTargetToMyRight); // Detect whether TARGET is sufficiently in front if (zIsTargetInFrontOfMe > 0.99) { // Satisfactally facing target // No need to turn } else { // Should we turn right or left? if (zIsTargetToMyRight > zIsTargetToMyLeft) { // Turn right float fTurnRate; if (zIsTargetBehindMe > zIsTargetToMyRight) { fTurnRate = AICore._Defuzzify(zIsTargetBehindMe, 0.0f, 6.0f); } else { fTurnRate = AICore._Defuzzify(zIsTargetToMyRight, 0.0f, 6.0f); } RULECORE._RotateYaw(bot, fTurnRate); } else { // Turn left float fTurnRate; if (zIsTargetBehindMe > zIsTargetToMyLeft) { fTurnRate = AICore._Defuzzify(zIsTargetBehindMe, 0.0f, 6.0f); } else { fTurnRate = AICore._Defuzzify(zIsTargetToMyLeft, 0.0f, 6.0f); } RULECORE._RotateYaw(bot, -fTurnRate); } } if (fMaxVelocity > 0.0f) { // Only drive forward when facing nearly toward target if (zIsTargetInFrontOfMe > 0.7) { // Only drive forward if we're far enough from target if (fTargetDistance >= 3.00f) { float fVelocity = AICore._Defuzzify(zIsTargetInFrontOfMe, 0.0f, fMaxVelocity); RULECORE._MoveForward(bot, fVelocity); } } // Return whether target is reached return(fTargetDistance < 4.00f); } else { // Return whether we're facing the target // Also include whether target is reached because when // we're very close to the target we get weird look at information return(zIsTargetInFrontOfMe > 0.9f || fTargetDistance < 5.00f); } }
private void Awake() { m_pawn = GetComponent <Pawn>(); m_brain = new AICore(m_pawn); }
/// <summary> /// Runs AI game. /// </summary> /// <param name="command">The AI command.</param> private void RunAIGame(Command command) { var preferredTime = command.GetArgument <float>(0); var helperTasksCount = command.GetArgument <int>(1); var whiteAI = new AICore(); var blackAI = new AICore(); var currentColor = Color.White; var history = new List <Move>(); var openingBook = new OpeningBookProvider(); CalculateBitboard(new DefaultFriendlyBoard(), false); Task.Run(() => { while (true) { var currentAI = currentColor == Color.White ? whiteAI : blackAI; var enemyColor = ColorOperations.Invert(currentColor); Move moveToApply; var openingBookMove = openingBook.GetMoveFromBook(history); if (openingBookMove != null) { moveToApply = Bitboard.Moves.First(p => p.From == openingBookMove.From && p.To == openingBookMove.To); } else { var aiResult = currentAI.Calculate(currentColor, Bitboard, preferredTime, helperTasksCount); moveToApply = aiResult.PVNodes[0]; ConsoleManager.WriteLine(); ConsoleManager.WriteLine($"$w{currentColor}:"); ConsoleManager.WriteLine($"$wBest move: $g{aiResult.PVNodes} $w(Score: $m{aiResult.Score}$w)"); ConsoleManager.WriteLine($"$wTotal nodes: $g{aiResult.Stats.TotalNodes} N $w(Depth: $m{aiResult.Depth}$w)"); ConsoleManager.WriteLine($"$wTime: $m{aiResult.Time} s"); ConsoleManager.WriteLine(); } CalculateBitboard(moveToApply, false); if (Bitboard.IsStalemate(enemyColor)) { ConsoleManager.WriteLine("$gStalemate, wins!"); break; } if (Bitboard.IsThreefoldRepetition()) { ConsoleManager.WriteLine("$gThreefold repetition!"); break; } if (Bitboard.IsMate(enemyColor)) { ConsoleManager.WriteLine($"$gMate, {currentColor} wins!"); break; } currentColor = enemyColor; history.Add(moveToApply); } }); }