public void GenerateMercenaryInCamp(MercenaryType mercenaryType, IBuildingInfo campInfo) { GameObject mercenary = this.GenerateMercenary(mercenaryType); ArmyAI ai = mercenary.GetComponent <ArmyAI>(); ai.GenerateArmyInCamp(campInfo); }
public void GenerateArmyInCamp(ArmyType armyType, int level, IBuildingInfo campInfo) { GameObject army = this.GenerateArmy(armyType, level); ArmyAI ai = army.GetComponent <ArmyAI>(); ai.GenerateArmyInCamp(campInfo); }
private void ChooseGeneralSafePoint() { ChessPiece general = ArmyAI.Find(piece => piece.type == "King"); int[] positionHolder = new int[] { general.CurrentX, general.CurrentY }; List <int[]> safeDestinations = new List <int[]>(); BoardManager.Instance.SelectPiece(general.CurrentX, general.CurrentY); chosenPiece = general; List <AIMove> moves = Utils.GetPieceDestinations(general); for (int i = 0; i < moves.Count; i++) { ChessPiece destinationPiece = TemporaryBoard[moves[i].AttackX, moves[i].AttackY]; Utils.UpdateSlot(general.CurrentX, general.CurrentY); Utils.RepositionPiece(general, new int[] { moves[i].AttackX, moves[i].AttackY }); if (Utils.CheckPointSafe(moves[i].AttackX, moves[i].AttackY)) { safeDestinations.Add(new int[] { moves[i].AttackX, moves[i].AttackY }); } general.SetPosition(positionHolder[0], positionHolder[1]); Utils.UpdateSlot(positionHolder[0], positionHolder[1], general); Utils.UpdateSlot(moves[i].AttackX, moves[i].AttackY, destinationPiece); RefreshBoardData(); } chosenDestination = safeDestinations.Count > 0 ? safeDestinations[Random.Range(0, safeDestinations.Count)] : null; }
private int[] RunForQueen() { movablePiecesAI = Utils.GetMovablePieces("Black"); List <ChessPiece> infantry = ArmyAI.FindAll(piece => piece.type == "Pawn"); if (infantry.Count == 0) { return(chosenDestination = null); } List <ChessPiece> movableInfantry = GetCandidatesForQueen(infantry); if (movableInfantry.Count == 0) { return(chosenDestination = null); } movableInfantry = movableInfantry.OrderBy(piece => piece.CurrentY).ToList(); // get frontmost movable pawn to promote to queen BoardManager.Instance.SelectPiece(movableInfantry[0].CurrentX, movableInfantry[0].CurrentY); List <AIMove> pieceMoves = Utils.GetPieceDestinations(movableInfantry[0]); if (pieceMoves.Count == 0) { return(chosenDestination = null); } chosenPiece = movableInfantry[0]; pieceMoves = pieceMoves.OrderBy(m => m.AttackY).ToList(); return(chosenDestination = new int[] { pieceMoves[0].AttackX, pieceMoves[0].AttackY }); }
public void SendMercenaryToCamp(MercenaryType mercenaryType, IBuildingInfo campInfo, IBuildingInfo factoryInfo) { GameObject mercenary = this.GenerateMercenary(mercenaryType); TilePosition initialPoint = BorderPointHelper.FindValidInflateOneBorderPoint(factoryInfo); mercenary.transform.position = PositionConvertor.GetWorldPositionFromActorTileIndex(initialPoint); ArmyAI ai = mercenary.GetComponent <ArmyAI>(); ai.SendArmyToCamp(campInfo); }
public void SendArmyToCamp(ArmyType armyType, int level, IBuildingInfo campInfo, IBuildingInfo factoryInfo) { GameObject army = this.GenerateArmy(armyType, level); TilePosition initialPoint = BorderPointHelper.FindValidInflateOneBorderPoint(factoryInfo); army.transform.position = PositionConvertor.GetWorldPositionFromActorTileIndex(initialPoint); ArmyAI ai = army.GetComponent <ArmyAI>(); ai.SendArmyToCamp(campInfo); }
private void HandleAIMove() { chosenPiece = GetPiece(); if (chosenPiece != null) { BoardManager.Instance.SelectPiece(chosenPiece.CurrentX, chosenPiece.CurrentY); } if (chosenMove != null && (chosenMove.Weight > 0 || initialSequenceCompleted)) { int destX = chosenMove.Defender != null ? chosenMove.Defender.CurrentX : chosenMove.AttackX; int destY = chosenMove.Defender != null ? chosenMove.Defender.CurrentY : chosenMove.AttackY; chosenDestination = new int[2] { destX, destY }; } else if (!initialSequenceCompleted) { chosenDestination = GetDestination(); } if (chosenDestination == null) { RunForQueen(); } if (chosenDestination == null || (chosenDestination != null && Utils.CheckGeneralThreatened(chosenPiece, chosenDestination[0], chosenDestination[1]))) { ChooseGeneralSafePoint(); } if (chosenDestination == null || (chosenDestination != null && Utils.CheckGeneralThreatened(chosenPiece, chosenDestination[0], chosenDestination[1]))) { ProtectGeneral(); } ChessPiece general = ArmyAI.Find(piece => piece.type == "King"); if (chosenDestination != null) { BoardManager.Instance.MovePiece(chosenDestination[0], chosenDestination[1]); } else { BoardManager.Instance.WhiteTurn(); initialSequenceCompleted = false; BoardManager.Instance.EndGame(); } }
private GameObject GenerateMercenary(MercenaryType mercenaryType) { string prefabPath = ActorPrefabConfig.Instance.GetMercenaryActorPrefab(mercenaryType); GameObject mercenaryPrefab = Resources.Load(prefabPath) as GameObject; GameObject mercenary = GameObject.Instantiate(mercenaryPrefab) as GameObject; if (!this.m_Mercenaries.ContainsKey(mercenaryType)) { this.m_Mercenaries.Add(mercenaryType, new List <GameObject>()); } this.m_Mercenaries[mercenaryType].Add(mercenary); ActorConfig config = ActorPrefabConfig.Instance.GetComponent <ActorConfig>(); ArmyAI armyAI = mercenary.GetComponent <ArmyAI>(); armyAI.WalkVelocity = config.MercenaryMoveVelocity[mercenaryType]; armyAI.MapData = this.m_MapData; return(mercenary); }
private GameObject GenerateArmy(ArmyType armyType, int level) { string prefabPath = ActorPrefabConfig.Instance.GetArmyActorPrefab(armyType, level); GameObject armyPrefab = Resources.Load(prefabPath) as GameObject; GameObject army = GameObject.Instantiate(armyPrefab) as GameObject; if (!this.m_Armies.ContainsKey(armyType)) { this.m_Armies.Add(armyType, new List <GameObject>()); } this.m_Armies[armyType].Add(army); ActorConfig config = ActorPrefabConfig.Instance.GetComponent <ActorConfig>(); ArmyAI armyAI = army.GetComponent <ArmyAI>(); armyAI.WalkVelocity = config.ArmyMoveVelocity[armyType]; armyAI.MapData = this.m_MapData; return(army); }