// Use this for initialization void Start() { LookForFirst(); ai = GetComponent<Ai>(); waypoint = GameObject.Find("Waypoint 2"); }
public void Setup() { _game = new FiveByFiveGame(); _player = new Player {IsHumanPlayer = false, Strikes = 0}; _game.AddPlayer(_player); _ai = new EasyAi(); }
public void GetAiChoiceReturnsSomethingOtherThanUndetermined() { //initialize Ai target = new Ai(); RpsEnum unexpected = RpsEnum.Undetermined; RpsEnum actual; //setup actual = target.GetAiChoice(null); //assert Assert.AreNotEqual(unexpected, actual); }
public void fire() { update = true; clicksExist = wb.existingClicks; GameObject aiPrefab = (GameObject)Resources.Load("Prefabs/AiManagement"); goSpecial = Instantiate(aiPrefab); Vector2 newPosition; try{ newPosition = new Vector2( gameObject.transform.parent.GetComponentInChildren<Player>().posX + 1, gameObject.transform.parent.GetComponentInChildren<Player>().posY); } catch (Exception e) { newPosition = new Vector2( gameObject.transform.parent.GetComponentInChildren<Ai>().posX + 1, gameObject.transform.parent.GetComponentInChildren<Ai>().posY); } goSpecial.transform.position = newPosition; goSpecial.name = "Tesla CLONE [" + playerBase.playerNumber + "]"; special = goSpecial.transform.GetChild(0).GetComponent<Ai>(); special.isClone = true; PlayerInfo specialInfo = new PlayerInfo(); specialInfo.playerNumber = playerBase.playInfo.playerNumber; specialInfo.charEnum = playerBase.playInfo.charEnum; specialInfo.playerColor = playerBase.playInfo.playerColor; specialInfo.lifes = playerBase.playInfo.lifes; special.SetUpPlayer(specialInfo); special.hitPoints = 70; //special.weaponHandling.inventory.Remove(special.weaponHandling.weapons[WeaponEnum.specialTesla]); //suposing pistol is on position 0 in inventory special.weaponHandling.RemoveFromInventoryAllBut(WeaponEnum.pistol); special.weaponHandling.activeWeapon = special.weaponHandling.inventory[0]; /* for (int i = special.weaponHandling.inventory.Count-1; i > 0;i--) { special.weaponHandling.inventory.RemoveAt(i); }*/ }
public void ChangeTask(Ai.Task t) { Time = 0; CurrentTask = t; Cheetah.Console.WriteLine("bot task: " + t.GetType().Name); }
public GameForm() { InitializeComponent(); board = new Board(); ai = new Ai(); }
public void LoadPlayersTypes() { prefab = (GameObject)Resources.Load("Prefabs/PlayerManagment"); aiPrefab = (GameObject)Resources.Load("Prefabs/AiManagement"); switch (gameInfo.player1type) { case PlayerTypeEnum.Player: player1 = Instantiate(prefab); player1Comp = player1.transform.GetChild(0).GetComponent<Player>(); player1.SetActive(false); break; case PlayerTypeEnum.AI: player1 = Instantiate(aiPrefab); ai1Comp = player1.transform.GetChild(0).GetComponent<Ai>(); player1.SetActive(false); break; } switch (gameInfo.player2type) { case PlayerTypeEnum.Player: player2 = Instantiate(prefab); player2Comp = player2.transform.GetChild(0).GetComponent<Player>(); player2.SetActive(false); break; case PlayerTypeEnum.AI: player2 = Instantiate(aiPrefab); ai2Comp = player2.transform.GetChild(0).GetComponent<Ai>(); player2.SetActive(false); break; } switch (gameInfo.player3type) { case PlayerTypeEnum.Player: player3 = Instantiate(prefab); player3Comp = player3.transform.GetChild(0).GetComponent<Player>(); player3.SetActive(false); break; case PlayerTypeEnum.AI: player3 = Instantiate(aiPrefab); ai3Comp = player3.transform.GetChild(0).GetComponent<Ai>(); player3.SetActive(false); break; } switch (gameInfo.player4type) { case PlayerTypeEnum.Player: player4 = Instantiate(prefab); player4Comp = player4.transform.GetChild(0).GetComponent<Player>(); player4.SetActive(false); break; case PlayerTypeEnum.AI: player4 = Instantiate(aiPrefab); ai4Comp = player4.transform.GetChild(0).GetComponent<Ai>(); player4.SetActive(false); break; } }
public X8Timer ShootTimer = new X8Timer(.5f); //this will time how longer the player faces the recticle void Start() { innerShield = gameObject.GetComponentInChildren <RaydraShield>(); //!search for the sheild in the children of the parent object _myCamera = this.GetComponentInChildren <Camera>(); //get the camera that is connected to this game object bool ScoreMode = false; //initally we are not in score mode //!the player info that unity will keep tract of p_fCameraAngleTheta = 43f; //!initialize the angle that player if facing p_fCameraAnglePhi = 45f; //!The camera is initially yyyyin this state p_fPlayerToFocusAngleTheta = 43f; //!initialize the angle that player if facing p_fPlayerToFocusAnglePhi = 45f; //!//!initialize the angle that player if facing in the upward direction p_fJumpVelocity = .40f; //!initialize the upward jump force ForceOfGravity = 1f / 60f; //!this will have a unit per second force of gravity, in the downward direction p_fOrientationAngle = 90f; //!Angle that the player is facing in degrees p_v3OrientationVect = new Vector3(0, 0, 1f); //!Direction player is facing represented as an angle p_v3PlayerToFocusVect = new Vector3(0, 0, 0); //!The vector the represents the direction the camera if facing p_v3PlayerToCameraVect = new Vector3(0, 0, 0); //!The Vector Data the represent the player to camera direction PlayerMovementState = MovingState.IsStandingStill; //!Intially the player is not moving PlayerJumpState = JumpingState.NotJumping; //!initlialize the the player is not jumping PlayerTackleHitState = TackeHitState.NoContact; //!Initial the tackle state of the player PlayerTackleState = TackleState.IsNotTackling; //!Initial the tackle state of the player PlayerAttackState = AttackMode.NotFiringAbility; //!Initial the shoot state of the player PlayerRaydraState = RaydraState.NotInRaydraMode; //!initailly the player is not in Raydra Mode PlayerCameraState = CameraPerspective.Normal; //!initially the camera to do nothing PlayerPhaseState = PhaseState.IsNotPhasing; PlayerBallThrowState = BallThrowingState.NotBeingThrown; //!Initial the vertical state of the player PlayerBallPossessionState = BallPossessionState.HasBall; //!Initial the Possession State of the player // PlayerMotionVector = new Vector3 (this.transform.position.x,.transform.position.y,playerData.transform.position.z); p_v3PlayerVectorDirection = Vector3.zero; //! This is direction that te player is headed as a vector _armWeapon = this.GetComponentInChildren <RaydraWeapon>(); //!reference to the arm weapon on the player which is null to begin with p_bFacePlayer = false; //! variable that determines weather or not to face the player, this variable determine weather or not this medthod is recursive p_fMass = 0f; //!initialize the mass of the player p_StateTime = 0f; // Time elasped in current state p_Collider = null; //initialize the first collider connect to this body pRidgidBody = null; Controls = GetComponent <RaydraControls>(); if (CameraFocusOverHead != null) { p_v3PlayerToCameraVect = CameraFocusOverHead.transform.position - _myCamera.transform.position; } p_fCameraAnglePhi = Vector3.Angle(new Vector3(0, 1, 0), p_v3PlayerToCameraVect); p_fCameraAngleTheta = Vector3.Angle(new Vector3(1, 0, 0), p_v3PlayerToCameraVect); p_fPlayerToFocusAnglePhi = Vector3.Angle(new Vector3(0, 1, 0), p_v3PlayerToFocusVect); p_fPlayerToFocusAngleTheta = Vector3.Angle(new Vector3(1, 0, 0), p_v3PlayerToFocusVect); X8Animator = GetComponent <Animator>(); isGrounded = false; if (p_v3PlayerToFocusVect.z < 0) { p_fPlayerToFocusAngleTheta = 360 - p_fPlayerToFocusAngleTheta; //make sure that the angle is at the correct corridinate } if (p_v3PlayerToCameraVect.z < 0) { p_fCameraAngleTheta = 360 - p_fCameraAngleTheta; //make sure that the angle is at the correct corridinate } TheBall = FindObjectOfType <RaydraCellz>(); X8Animator = GetComponent <Animator>(); //get the reference to the animator PlayerMovementState = MovingState.IsStandingStill; EnemyAI = GetComponent <Ai>(); //get the ai script attached to the player (if there is one) if (EnemyAI != null) { Debug.Log("enemy AI" + EnemyAI.ToString()); } }
public void MovePlayer(Ai by) { }
internal void Init() { using (MyCube.Pin()) { if (!MyCube.MarkedForClose && Entity != null) { Entity.NeedsUpdate = ~MyEntityUpdateEnum.EACH_10TH_FRAME; Ai.FirstRun = true; StorageSetup(); InventoryInit(); PowerInit(); Ai.CompChange(true, this); RegisterEvents(); if (Platform.State == MyWeaponPlatform.PlatformState.Inited) { Platform.ResetParts(this); } Entity.NeedsWorldMatrix = true; for (int i = 0; i < Platform.Weapons.Length; i++) { var weapon = Platform.Weapons[i]; weapon.UpdatePivotPos(); if (Session.IsClient) { var target = WeaponValues.Targets[weapon.WeaponId]; if (target.State != TransferTarget.TargetInfo.Expired) { target.SyncTarget(weapon.Target, false); } if (!weapon.Target.IsProjectile && !weapon.Target.IsFakeTarget && weapon.Target.Entity == null) { weapon.Target.StateChange(true, Target.States.Invalid); weapon.Target.TargetChanged = false; } else if (weapon.Target.IsProjectile) { TargetType targetType; AcquireProjectile(weapon, out targetType); if (targetType == TargetType.None) { if (weapon.NewTarget.CurrentState != Target.States.NoTargetsSeen) { weapon.NewTarget.Reset(weapon.Comp.Session.Tick, Target.States.NoTargetsSeen); } if (weapon.Target.CurrentState != Target.States.NoTargetsSeen) { weapon.Target.Reset(weapon.Comp.Session.Tick, Target.States.NoTargetsSeen, !weapon.Comp.TrackReticle); } } } } } if (!Ai.GridInit) { Session.CompReAdds.Add(new CompReAdd { Ai = Ai, Comp = this }); } else { OnAddedToSceneTasks(); } Platform.State = MyWeaponPlatform.PlatformState.Ready; } else { Log.Line($"Comp Init() failed"); } } }
public AiSetupDecision Setup(State state, IServices services) { return(Ai.Setup(state, services)); }
/// <summary> /// one of the main functions, get the wanted territory from countryHnadler(the player) and play the game /// </summary> /// <param name="input">index of the country</param> public void getInput(int input) { //dont get input before the user declare the players if (this.forcesPanel != null) { if (this.forcesPanel.activeSelf == false) { bool flag_next_player = false; //the player lost already if (players[this.currentPlayer] == false) { //move to next player nextPlayer(); } else { if (this.counter == 0) { this.inputInexOfCou = input; //in the choose teritories stage if (this.currentStage == 3) { bool flag_to_attack = false; flag_next_player = chooseTer(this.inputInexOfCou); //still need to be deployed if (this.st.num_of_players > 0) { //the player picked good if (flag_next_player == true) { nextPlayer(); //already moved so no need to move it flag_next_player = false; //while the player is bot while (this.st.num_of_players > 0 && this.playerAi[this.currentPlayer] == true) { //make a move as ai this.bot = new Ai(this.currentPlayer); this.bot.makeMoveInStart(this.st); //all the soldiers werent deployed if (this.st.num_of_players > 0) { nextPlayer(); } else { flag_to_attack = true; } } } } //all the soldiers of all players were deployed else { flag_to_attack = true; } if (flag_to_attack == true) { //hide the startPanel if (this.startPanel != null) { this.startPanel.SetActive(false); } this.currentStage = 1; //move to next player nextPlayer(); flag_next_player = false; this.at = new Attack(this.currentPlayer, Global.map); if (this.AttackPanel != null) { this.AttackPanel.SetActive(true); } } } //in the choose reinfoesment stage else if (this.currentStage == 0) { //check if all the soldiers were deployed if (this.rei.getNumberOfForces() <= 0) { //hide the reinforsment Panel if (this.ReiPanel != null) { this.ReiPanel.SetActive(false); } //next stage this.currentStage = 1; this.at = new Attack(this.currentPlayer, Global.map); //show the attackPanel if (this.AttackPanel != null) { this.AttackPanel.SetActive(true); } } else { //allow to reinforse if (this.ReiPanel.transform.Find("conf") != null) { this.ReiPanel.transform.Find("conf").gameObject.SetActive(true); } if (this.ReiPanel.transform.Find("SliderText") != null) { this.ReiPanel.transform.Find("SliderText").gameObject.SetActive(true); } if (this.ReiPanel.transform.Find("Slider") != null) { this.ReiPanel.transform.Find("Slider").gameObject.SetActive(true); } this.ReiPanel.transform.Find("Slider").GetComponent <Slider>().maxValue = this.rei.getNumberOfForces(); this.ReiPanel.transform.Find("Slider").GetComponent <Slider>().minValue = 1; } } //on the attack stage else if (this.currentStage == 1) { //create the list of possible location at.possible_sources(); //can attack if (at.possibleToAttack() == true) { //a possible location was selcted if (at.in_possible_sources(this.inputInexOfCou)) { //show text if (this.AttackPanel.transform.Find("ataText") != null) { this.AttackPanel.transform.Find("ataText").gameObject.SetActive(true); } this.counter++; } } else { //next stage //hide the attackPanel if (this.AttackPanel != null) { this.AttackPanel.SetActive(false); } this.currentStage = 2; this.mo = new moving(this.currentPlayer, Global.map); //show the movekPanel if (this.MovePanel != null) { this.MovePanel.SetActive(true); } } } // on the move forces else { //create all the possble source this.mo.possible_source(); //can move if (this.mo.canMove() == true) { if (this.mo.canChooseSou(this.inputInexOfCou)) { this.mo.possible_des(this.inputInexOfCou); this.mo.removeSelf(this.inputInexOfCou); //show text if (this.MovePanel.transform.Find("first") != null) { this.MovePanel.transform.Find("first").gameObject.SetActive(true); } this.counter++; } } else { moveNextStage(); } } //reinforsment //attack //check win //move } //one teritory was already chosen else if (this.counter == 1) { this.inputInexOfCou2 = input; //on the attack stage if (this.currentStage == 1) { //the selcted des can be attacked if (at.destention_is_possible(this.inputInexOfCou2, this.inputInexOfCou)) { //show text if (this.AttackPanel.transform.Find("defText") != null) { this.AttackPanel.transform.Find("defText").gameObject.SetActive(true); } //show buttons if (this.AttackPanel.transform.Find("withdraw") != null) { this.AttackPanel.transform.Find("withdraw").gameObject.SetActive(true); } if (this.AttackPanel.transform.Find("cont") != null) { this.AttackPanel.transform.Find("cont").gameObject.SetActive(true); } this.counter++; } } //the sourse location was chosen in the moving stage else if (this.currentStage == 2) { if (this.mo.canChooseDes(this.inputInexOfCou2)) { //show text if (this.MovePanel.transform.Find("SliderText") != null) { this.MovePanel.transform.Find("SliderText").gameObject.SetActive(true); } //show slider if (this.MovePanel.transform.Find("Slider") != null) { this.MovePanel.transform.Find("Slider").gameObject.SetActive(true); } //show button if (this.MovePanel.transform.Find("Button") != null) { this.MovePanel.transform.Find("Button").gameObject.SetActive(true); } this.counter++; this.MovePanel.transform.Find("Slider").GetComponent <Slider>().maxValue = Global.map.map[this.inputInexOfCou].Info.Num_of_forces - 1; this.MovePanel.transform.Find("Slider").GetComponent <Slider>().minValue = 1; } } } if (flag_next_player == true) { //move to next player nextPlayer(); } } } } }
internal void OnAddedToSceneTasks() { try { if (Ai.MarkedForClose) { Log.Line($"OnAddedToSceneTasks and AI MarkedForClose - Subtype:{MyCube.BlockDefinition.Id.SubtypeName} - grid:{MyCube.CubeGrid.DebugName} - CubeMarked:{MyCube.MarkedForClose} - GridMarked:{MyCube.CubeGrid.MarkedForClose} - GridMatch:{MyCube.CubeGrid == Ai.MyGrid} - AiContainsMe:{Ai.WeaponBase.ContainsKey(MyCube)} - MyGridInAi:{Ai.Session.GridToMasterAi.ContainsKey(MyCube.CubeGrid)}[{Ai.Session.GridTargetingAIs.ContainsKey(MyCube.CubeGrid)}]"); } Ai.UpdatePowerSources = true; RegisterEvents(); if (!Ai.GridInit) { Ai.GridInit = true; var fatList = Session.GridToInfoMap[MyCube.CubeGrid].MyCubeBocks; for (int i = 0; i < fatList.Count; i++) { var cubeBlock = fatList[i]; if (cubeBlock is MyBatteryBlock || cubeBlock.HasInventory) { Ai.FatBlockAdded(cubeBlock); } } SubGridInit(); } var maxTrajectory = 0d; for (int i = 0; i < Platform.Weapons.Length; i++) { var weapon = Platform.Weapons[i]; weapon.InitTracking(); double weaponMaxRange; DpsAndHeatInit(weapon, out weaponMaxRange); if (maxTrajectory < weaponMaxRange) { maxTrajectory = weaponMaxRange; } if (weapon.Ammo.CurrentAmmo > weapon.ActiveAmmoDef.ConsumableDef.Const.MagazineSize) { weapon.Ammo.CurrentAmmo = weapon.ActiveAmmoDef.ConsumableDef.Const.MagazineSize; } if (Session.IsServer && weapon.TrackTarget) { Session.AcqManager.Monitor(weapon.Acquire); } } if (maxTrajectory + Ai.MyGrid.PositionComp.LocalVolume.Radius > Ai.MaxTargetingRange) { Ai.MaxTargetingRange = maxTrajectory + Ai.MyGrid.PositionComp.LocalVolume.Radius; Ai.MaxTargetingRangeSqr = Ai.MaxTargetingRange * Ai.MaxTargetingRange; } Ai.OptimalDps += PeakDps; Ai.EffectiveDps += EffectiveDps; if (!Ai.WeaponBase.TryAdd(MyCube, this)) { Log.Line($"failed to add cube to gridAi"); } Ai.CompChange(true, this); Ai.IsStatic = Ai.MyGrid.Physics?.IsStatic ?? false; Ai.Construct.Refresh(Ai, Constructs.RefreshCaller.Init); if (!FunctionalBlock.Enabled) { for (int i = 0; i < Platform.Weapons.Length; i++) { Session.FutureEvents.Schedule(Platform.Weapons[i].DelayedStart, null, 1); } } TurretBase?.SetTarget(Vector3D.MaxValue); Status = !IsWorking ? Start.Starting : Start.ReInit; } catch (Exception ex) { Log.Line($"Exception in OnAddedToSceneTasks: {ex} AiNull:{Ai == null} - SessionNull:{Session == null} EntNull{Entity == null} MyCubeNull:{MyCube?.CubeGrid == null}"); } }
public static string GetAiName(byte[] aiAddressPointer) { Ai matchedAi = Ai.GetAiByPointerValue(aiAddressPointer); return(matchedAi == null ? "???" : matchedAi.Name); }
/// <summary> /// 1) Ищет совпадения в начале и в конце последовательностей. /// Если ничего не совпало выходим /// 2) Удаляем последовательность которая короче. Если Aj короче swap = true /// 3) Берем подпоследовательности Cp,Dq /// 4) Мастрячим замену - если D нету, квантификатор, иначе альтернативу /// </summary> /// <param name="Ai">B1,...,Bn,[D1,...,Dq],E1,...,Ek</param> /// <param name="Aj">B1,...,Bn, C1,...,Cp, E1,...,Ek</param> /// <param name="swap">true если удаляем Aj, а не Ai</param> /// <returns>B1,...,Bn, (C1,...,Cn)?, D1,...,Dn</returns> private Seqence FindNonMandatryInclusion(Seqence Ai, Seqence Aj, out bool swap) { // 1) Ищет совпадения в начале и в конце последовательностей. int start_len = 0; //FindEqualSeq(A1, A2, 1); int Ci = Ai.Phrases.Count - 1; int Cj = Aj.Phrases.Count - 1; while (start_len <= Ci && start_len <= Cj && Ai.Phrases[start_len] is NonTerminal && Aj.Phrases[start_len] is NonTerminal && Ai.Phrases[start_len].ToString() == Aj.Phrases[start_len].ToString() ) { start_len++; } int end_len = 0; //FindEqualSeq(A1, A2, -1); while (Ci >= start_len && Cj >= start_len && Ai.Phrases[Ci] is NonTerminal && Aj.Phrases[Cj] is NonTerminal && Ai.Phrases[Ci].ToString() == Aj.Phrases[Cj].ToString() ) { Ci--; Cj--; end_len++; } //Теперь у нас //start_len=n end_len=k // B1,...,Bn, D1,...,Dq, E1,...,Ek // B1,...,Bn, C1,...,Cp, E1,...,Ek // 2) Анализируем варианты swap = (Aj.Phrases.Count < Ai.Phrases.Count); //true Aj короче - ее и удалим if (start_len > 0 || end_len > 0) { if (swap) { Seqence At = Ai; Ai = Aj; Aj = At; } int sub_d_len = Ai.Phrases.Count - start_len - end_len; int sub_c_len = Aj.Phrases.Count - start_len - end_len; //Выделим D1,...,Dq из Ai Seqence sub_d = Ai.SubSequence(start_len, sub_d_len); //Выделим C1,...,Cp Seqence sub_c = Aj.SubSequence(start_len, sub_c_len); if (sub_c != null) { IPhrase replacement; if (sub_d != null) { // Альтернатива (D|C) if (sub_c.Count == 1 && sub_c.Phrases[0] is AlternativeSet) { (sub_c.Phrases[0] as AlternativeSet).Add(sub_d); return(Aj); } else if (sub_d.Count == 1 && sub_d.Phrases[0] is AlternativeSet) { (sub_d.Phrases[0] as AlternativeSet).Add(sub_c); swap = true; return(Ai); } else { replacement = new AlternativeSet(mGrammar, sub_d); (replacement as AlternativeSet).Phrases.Add(sub_c); } } else { // Необязательная C? replacement = new QuantifiedPhrase(mGrammar, sub_c, 0, 1); } return(ReplaceSubSequence(Aj, start_len, sub_c_len, replacement)); } else { throw new Exception( "FindNonMandatryInclusion. Подпоследовательность С нулевая. Такое может быть только если среди альтернатив две одинаковые последовательности, например S = A,B | A,B "); } } //иначе вообще нет совпадений return(null); }
protected override IAction OnGetAction() { return(Ai.DecideNextAction()); }
private static void Main(string[] args) { string[] inputs; var projectCount = int.Parse(Console.ReadLine()); for (var i = 0; i < projectCount; i++) { inputs = Console.ReadLine().Split(' '); var a = int.Parse(inputs[0]); var b = int.Parse(inputs[1]); var c = int.Parse(inputs[2]); var d = int.Parse(inputs[3]); var e = int.Parse(inputs[4]); } var player = new Robot("START_POS", 0, 0, new[] { 0, 0, 0, 0, 0 }); var ai = new Ai(player); // game loop while (true) { for (var i = 0; i < 2; i++) { inputs = Console.ReadLine().Split(' '); var target = inputs[0]; var eta = int.Parse(inputs[1]); var score = int.Parse(inputs[2]); var storageA = int.Parse(inputs[3]); var storageB = int.Parse(inputs[4]); var storageC = int.Parse(inputs[5]); var storageD = int.Parse(inputs[6]); var storageE = int.Parse(inputs[7]); var expertiseA = int.Parse(inputs[8]); var expertiseB = int.Parse(inputs[9]); var expertiseC = int.Parse(inputs[10]); var expertiseD = int.Parse(inputs[11]); var expertiseE = int.Parse(inputs[12]); var storageNumbers = new int[5] { storageA, storageB, storageC, storageD, storageE }; if (i == 0) { player.Eta = eta; player.Score = score; player.SetTarget(target); player.Storage.UpdateMoleculeValues(storageNumbers); } } inputs = Console.ReadLine().Split(' '); var availableA = int.Parse(inputs[0]); var availableB = int.Parse(inputs[1]); var availableC = int.Parse(inputs[2]); var availableD = int.Parse(inputs[3]); var availableE = int.Parse(inputs[4]); var sampleCount = int.Parse(Console.ReadLine()); for (var i = 0; i < sampleCount; i++) { inputs = Console.ReadLine().Split(' '); var sampleId = int.Parse(inputs[0]); var carriedBy = int.Parse(inputs[1]); var rank = int.Parse(inputs[2]); var expertiseGain = inputs[3]; var health = int.Parse(inputs[4]); var costA = int.Parse(inputs[5]); var costB = int.Parse(inputs[6]); var costC = int.Parse(inputs[7]); var costD = int.Parse(inputs[8]); var costE = int.Parse(inputs[9]); var costNumbers = new int[5] { costA, costB, costC, costD, costE }; if (ai.Samples.DoesThisExistInBag(sampleId)) { var sample = ai.Samples.SingleSampleById(sampleId); sample.UpdateSampleOwner((Carried)carriedBy); } else { var sample = new Sample(sampleId, carriedBy, health, costNumbers); ai.Samples.AddSample(sample); } } ai.Run(); // Write an action using Console.WriteLine() // To debug: Console.Error.WriteLine("Debug messages..."); } }
public void SetupAi() { var robot = new Robot("START_POS", 0, 0, new[] { 0, 0, 0, 0, 0 }); this._ai = new Ai(robot); }
public void OnMessage(object sender, CQEventEventArgs e) { CQCode atCode = null; Match m; string msg; if (e.GetType() == typeof(CQGroupMessageEventArgs)) { atCode = ((CQGroupMessageEventArgs)e).FromQQ.CQCode_At(); msg = ((CQGroupMessageEventArgs)e).Message.Text; } else { msg = ((CQPrivateMessageEventArgs)e).Message.Text; } if ((m = Commands[0].Match(msg.Trim(' '))).Success) { Ai.Reply(e, $" 想让爱梅斯帮你搜什么呀?请用 点歌+歌名 或者 点歌+歌名+By:+作者 呼叫我哦~"); } else if ((m = Commands[1].Match(msg.ToLower())).Success) { if (m.Groups[1].Value.Trim(' ').Length == 0) { Ai.Reply(e, atCode == null ? "" : atCode.ToSendString(), " 没告诉我歌名我怎么搜索呀"); } else { Music music = FindBetter(Client, m.Groups[1].Value.Trim(' ').Replace('\n', ' ').Replace('&', ' '), m.Groups[2].Value.Trim(' ').Replace('\n', ' ').Replace('&', ' ')); ClientType client = music.Client; if (music.Stat == Music.Status.E404A) { if (music.StatText != null) { Ai.Reply(e, atCode == null ? "" : atCode.ToSendString(), $" 找不到这个名字的歌曲,你是不是想搜索{ m.Groups[2].Value.Trim(' ') }呢?"); } else { Ai.Reply(e, atCode == null ? "" : atCode.ToSendString(), " 搜索不到哦..."); }; } else if (music.Stat == Music.Status.E404B) { Ai.Reply(e, atCode == null ? "" : atCode.ToSendString(), $" 爱梅斯没有找到由这个作者演唱的歌曲哦"); } else { Ai.Reply(e, $" [CQ:music,type={(client == ClientType.Netease ? "163" : "qq")},id={music.Id}]"); if (IsWithLink && client == ClientType.Netease) { Ai.Reply(e, atCode == null ? "" : atCode.ToSendString(), $" https://music.163.com/#/song?id={music.Id}"); } else if (IsWithLink && client == ClientType.QQ) { Ai.Reply(e, atCode == null ? "" : atCode.ToSendString(), $" https://y.qq.com/n/yqq/song/{music.Id}_num.html"); } } } } else if ((m = Commands[2].Match(msg)).Success) { if (m.Groups[1].Value.Trim(' ').Length == 0) { Ai.Reply(e, atCode == null ? "" : atCode.ToSendString(), " 没告诉我歌名我怎么搜索呀"); } else { Music music = FindBetter(Client, m.Groups[1].Value.Trim(' ').Replace('\n', ' ').Replace('&', ' ')); ClientType client = music.Client; if (music.Stat == Music.Status.E404A) { if (m.Groups[2].Value.Trim(' ').Length > 0) { Ai.Reply(e, atCode == null ? "" : atCode.ToSendString(), $" 找不到这个名字的歌曲,你是不是想搜索{ m.Groups[2].Value.Trim(' ') }呢?"); } else { Ai.Reply(e, atCode == null ? "" : atCode.ToSendString(), " 搜索不到哦..."); } } else if (music.Stat == Music.Status.E404B) { Ai.Reply(e, atCode == null ? "" : atCode.ToSendString(), $" 爱梅斯找不到符合要求的歌曲呢..."); } else { Ai.Reply(e, $" [CQ:music,type={(client == ClientType.Netease ? "163" : "qq")},id={music.Id}]"); if (IsWithLink && client == ClientType.Netease) { Ai.Reply(e, atCode == null ? "" : atCode.ToSendString(), $" https://music.163.com/#/song?id={music.Id}"); } else if (IsWithLink && client == ClientType.QQ) { Ai.Reply(e, atCode == null ? "" : atCode.ToSendString(), $" https://y.qq.com/n/yqq/song/{music.Id}_num.html"); } } } } }
public void ChooseLine_ShouldChooseRandom() { var lineList = new List <LineStructure> { new LineStructure() { X1 = 0, Y1 = 0, X2 = 10, Y2 = 0, StrokeColor = red }, new LineStructure() { X1 = 10, Y1 = 0, X2 = 20, Y2 = 0, StrokeColor = blue }, new LineStructure() { X1 = 0, Y1 = 20, X2 = 10, Y2 = 20, StrokeColor = red }, new LineStructure() { X1 = 0, Y1 = 0, X2 = 0, Y2 = 10, StrokeColor = blue }, new LineStructure() { X1 = 20, Y1 = 0, X2 = 20, Y2 = 10, StrokeColor = red }, new LineStructure() { X1 = 0, Y1 = 10, X2 = 0, Y2 = 20, StrokeColor = red } }; var expected1 = new LineStructure() { X1 = 0, Y1 = 10, X2 = 10, Y2 = 10, StrokeColor = white }; var expected2 = new LineStructure() { X1 = 10, Y1 = 10, X2 = 20, Y2 = 10, StrokeColor = white }; var expected3 = new LineStructure() { X1 = 10, Y1 = 0, X2 = 10, Y2 = 10, StrokeColor = white }; var expected4 = new LineStructure() { X1 = 10, Y1 = 10, X2 = 10, Y2 = 20, StrokeColor = white }; lineList.Add(expected1); lineList.Add(expected2); lineList.Add(expected3); lineList.Add(expected4); var ai = new Ai(10, 10) { LineList = lineList }; ai.ChooseLine(); var actual = ai.ChosenLine; Assert.IsTrue(expected1.Equals(actual) || expected2.Equals(actual) || expected3.Equals(actual) || expected4.Equals(actual), "The chosen line is not a white line."); }
public void GetMove_ImpossibleAiValidMove_Success() { // Arrange const int aiDifficulty = (int)Ai.AiDifficulty.Impossible; // Players mark is X string[,] boardPlayerStartsFirstOne = GetBoardPlayerStartsFirstOne(); string[,] boardPlayerStartsFirstTwo = GetBoardPlayerStartsFirstTwo(); string[,] boardPlayerStartsFirstThree = GetBoardPlayerStartsFirstThree(); string[][,] boardsPlayerStartsFirst = { boardPlayerStartsFirstOne, boardPlayerStartsFirstTwo, boardPlayerStartsFirstThree }; var expectedMovePlayerStartsFirstOne = new Ai.Move() { X = 2, Y = 1 }; var expectedMovePlayerStartsFirstTwo = new Ai.Move() { X = 1, Y = 2 }; var expectedMovePlayerStartsFirstThree = new Ai.Move() { X = 2, Y = 2 }; List <Ai.Move> expectedPlayerStartsFirstMoves = new List <Ai.Move> { expectedMovePlayerStartsFirstOne, expectedMovePlayerStartsFirstTwo, expectedMovePlayerStartsFirstThree }; // Players mark is O string[,] boardAiStartsFirstOne = GetBoardAiStartsFirstOne(); string[,] boardAiStartsFirstTwo = GetBoardAiStartsFirstTwo(); string[,] boardAiStartsFirstThree = GetBoardAiStartsFirstThree(); string[][,] boardsAiStartsFirst = { boardAiStartsFirstOne, boardAiStartsFirstTwo, boardAiStartsFirstThree }; var expectedMoveAiStartsFirstOne = new Ai.Move() { X = 1, Y = 2 }; var expectedMoveAiStartsFirstTwo = new Ai.Move() { X = 1, Y = 2 }; var expectedMoveAiStartsFirstThree = new Ai.Move() { X = 1, Y = 2 }; List <Ai.Move> expectedAiStartsFirstMoves = new List <Ai.Move> { expectedMoveAiStartsFirstOne, expectedMoveAiStartsFirstTwo, expectedMoveAiStartsFirstThree }; List <Ai.Move> performedPlayerStartsFirstMoves = new List <Ai.Move>(); List <Ai.Move> performedAiStartsFirstMoves = new List <Ai.Move>(); // Act for (int i = 0; i < 3; i++) { var computerPlayerOMarkAi = new Ai(boardsPlayerStartsFirst[i], GetRandom()); var playerStartsFirstMove = computerPlayerOMarkAi.GetMove(Resources.BoardCircleMark, aiDifficulty); performedPlayerStartsFirstMoves.Add(playerStartsFirstMove); var computerPlayerXMarkAi = new Ai(boardsAiStartsFirst[i], GetRandom()); var aiStartsFirstMove = computerPlayerXMarkAi.GetMove(Resources.BoardCrossMark, aiDifficulty); performedAiStartsFirstMoves.Add(aiStartsFirstMove); } // Assert for (int i = 0; i < 3; i++) { Assert.AreEqual(expectedPlayerStartsFirstMoves[i].X, performedPlayerStartsFirstMoves[i].X); Assert.AreEqual(expectedPlayerStartsFirstMoves[i].Y, performedPlayerStartsFirstMoves[i].Y); Assert.AreEqual(expectedAiStartsFirstMoves[i].X, performedAiStartsFirstMoves[i].X); Assert.AreEqual(expectedAiStartsFirstMoves[i].Y, performedAiStartsFirstMoves[i].Y); } }
public AiMoveDecision GetNextMove(State state, IServices services) { return(Ai.GetNextMove(state, services)); }
internal void OnAddedToSceneTasks() { try { Ai.UpdatePowerSources = true; if (!Ai.GridInit) { Ai.GridInit = true; Ai.InitFakeShipController(this); Ai.ScanBlockGroups = true; var fatList = Session.GridToFatMap[MyCube.CubeGrid].MyCubeBocks; for (int i = 0; i < fatList.Count; i++) { var cubeBlock = fatList[i]; if (cubeBlock is MyBatteryBlock || cubeBlock is IMyCargoContainer || cubeBlock is IMyAssembler || cubeBlock is IMyShipConnector) { Ai.FatBlockAdded(cubeBlock); } } } var maxTrajectory = 0d; var ob = MyCube.BlockDefinition as MyLargeTurretBaseDefinition; for (int i = 0; i < Platform.Weapons.Length; i++) { var weapon = Platform.Weapons[i]; weapon.InitTracking(); double weaponMaxRange; DpsAndHeatInit(weapon, ob, out weaponMaxRange); if (maxTrajectory < weaponMaxRange) { maxTrajectory = weaponMaxRange; } } if (maxTrajectory + Ai.MyGrid.PositionComp.LocalVolume.Radius > Ai.MaxTargetingRange) { Ai.MaxTargetingRange = maxTrajectory + Ai.MyGrid.PositionComp.LocalVolume.Radius; Ai.MaxTargetingRangeSqr = Ai.MaxTargetingRange * Ai.MaxTargetingRange; } Ai.OptimalDps += PeakDps; Ai.EffectiveDps += EffectiveDps; Ai.Construct.Update(Ai); if (!FunctionalBlock.Enabled) { Session.FutureEvents.Schedule(o => { for (int i = 0; i < Platform.Weapons.Length; i++) { Platform.Weapons[i].EventTriggerStateChanged(EventTriggers.TurnOff, true); } }, null, 1); } Status = !IsWorking ? Start.Starting : Start.ReInit; } catch (Exception ex) { Log.Line($"Exception in OnAddedToSceneTasks: {ex} AiNull:{Ai == null} - SessionNull:{Session == null} EntNull{Entity == null} MyCubeNull:{MyCube?.CubeGrid == null}"); } }
private bool check_pong_kong(Brand brand) { // 測試是否被 槓 碰 for (int i = 0; i < 3; i++) { all.next(); CheckBrands c = new CheckBrands(brand, NowPlayer_removeTeam); CheckBrands w = new CheckBrands(brand, all.NowPlayer); Ai.setPlayer(brand, all.NowPlayer); // 如果是玩家 if (NowPlayer_is_Real_Player) { if (c.Pong() || c.Kong()) { CheckUser check = new Control.CheckUser((c.Chow() && i == 0), c.Pong(), c.Kong(), false, w.Win(), true, brand); toUser(check); if (Player_Pass_Brand) { Player_Pass_Brand = false; } else { return(true); } } } else { // 槓 if (c.Kong() && Ai.Kong) { setInforamtion(); if (PlayerSound) { soundplayer.Stream = Resources.kong; soundplayer.Play(); } if (showMessageBox) { ShowMessage(Mahjong.Properties.Settings.Default.Kong); } all.kong(brand, c.SuccessPlayer); Chow_Pong_Brand = false; updatePlayer_Table(); return(true); } // 碰 else if (c.Pong() && Ai.Pong) { setInforamtion(); if (PlayerSound) { soundplayer.Stream = Resources.pon; soundplayer.Play(); } if (showMessageBox) { ShowMessage(Mahjong.Properties.Settings.Default.Pong); } all.chow_pong(brand, c.SuccessPlayer); updatePlayer_Table(); Chow_Pong_Brand = true; return(true); } } } all.next(); return(false); }
internal void Init() { using (MyCube.Pin()) { if (!MyCube.MarkedForClose && Entity != null) { Entity.NeedsUpdate = ~MyEntityUpdateEnum.EACH_10TH_FRAME; Ai.FirstRun = true; StorageSetup(); InventoryInit(); PowerInit(); Ai.CompChange(true, this); RegisterEvents(); if (Platform.State == MyWeaponPlatform.PlatformState.Inited) { Platform.ResetParts(this); } Entity.NeedsWorldMatrix = true; if (!Ai.GridInit) { Session.CompReAdds.Add(new CompReAdd { Ai = Ai, Comp = this }); } else { OnAddedToSceneTasks(); } Platform.State = MyWeaponPlatform.PlatformState.Ready; for (int i = 0; i < Platform.Weapons.Length; i++) { var weapon = Platform.Weapons[i]; weapon.UpdatePivotPos(); if (Session.IsClient) { var target = WeaponValues.Targets[weapon.WeaponId]; if (target.State != TransferTarget.TargetInfo.Expired) { target.SyncTarget(weapon.Target, false); } if (!weapon.Target.IsProjectile && !weapon.Target.IsFakeTarget && weapon.Target.Entity == null) { weapon.Target.StateChange(true, Target.States.Invalid); weapon.Target.TargetChanged = false; } else if (weapon.Target.IsProjectile) { TargetType targetType; AcquireProjectile(weapon, out targetType); if (targetType == TargetType.None) { if (weapon.NewTarget.CurrentState != Target.States.NoTargetsSeen) { weapon.NewTarget.Reset(weapon.Comp.Session.Tick, Target.States.NoTargetsSeen); } if (weapon.Target.CurrentState != Target.States.NoTargetsSeen) { weapon.Target.Reset(weapon.Comp.Session.Tick, Target.States.NoTargetsSeen, !weapon.Comp.TrackReticle); } } } } if (weapon.State.Sync.CurrentAmmo == 0 && !weapon.State.Sync.Reloading) { weapon.EventTriggerStateChanged(EventTriggers.EmptyOnGameLoad, true); } if (weapon.AnimationsSet.ContainsKey(EventTriggers.TurnOn)) { //Log.Line($"On exists"); for (int j = 0; j < weapon.AnimationsSet[EventTriggers.TurnOn].Length; j++) { var animation = weapon.AnimationsSet[EventTriggers.TurnOn][j]; MyAPIGateway.Utilities.InvokeOnGameThread(() => weapon.PlayEmissives(animation, weapon.System)); } } } } else { Log.Line($"Comp Init() failed"); } } }
/// <summary> /// in the end of turn move the the next player. /// if the next player is bot play the moves of the bots /// </summary> private void moveNextStage() { //hide text //hide text if (this.MovePanel.transform.Find("first") != null) { this.MovePanel.transform.Find("first").gameObject.SetActive(false); } if (this.MovePanel.transform.Find("SliderText") != null) { this.MovePanel.transform.Find("SliderText").gameObject.SetActive(false); } //hide slider if (this.MovePanel.transform.Find("Slider") != null) { this.MovePanel.transform.Find("Slider").gameObject.SetActive(false); } //hide button if (this.MovePanel.transform.Find("Button") != null) { this.MovePanel.transform.Find("Button").gameObject.SetActive(false); } //hide the move Panel if (this.MovePanel != null) { this.MovePanel.SetActive(false); } nextPlayer(); bool flag_find_player = false; while (flag_find_player == false) { //player is not alive if (players[this.currentPlayer] == false) { //if its after the beggining if (this.counterStart > 0) { this.counterStart--; } nextPlayer(); } else { //player was elimnated if (lostCheck() == true) { nextPlayer(); } else { //the player is bot if (this.playerAi[this.currentPlayer] == true) { int won = 0; //if its after the beggining and you should go straight to attack if (this.counterStart > 0) { this.bot = new Ai(this.currentPlayer); won = this.bot.playATurn(true, this); //bot from attack this.counterStart--; } else { this.bot = new Ai(this.currentPlayer); won = this.bot.playATurn(false, this); //bot from rein } //bot won if (won == 1) { //show winner if (this.WPanel != null) { this.WPanel.SetActive(true); } this.WPanel.transform.Find("winner").GetComponent <Text>().text = "the winner is " + whichPlayer(); flag_find_player = true; } else { nextPlayer(); } } //regular player else { //if its after the beggining and you should go straight to attack if (this.counterStart > 0) { //next stage this.currentStage = 1; this.at = new Attack(this.currentPlayer, Global.map); //show the attackPanel if (this.AttackPanel != null) { this.AttackPanel.SetActive(true); } this.counterStart--; } else { //next stage this.currentStage = 0; this.counter = 0; this.rei = new reinforcement(this.currentPlayer, Global.map); //show the reinforcement Panel if (this.ReiPanel != null) { this.ReiPanel.SetActive(true); } } //player founded play it flag_find_player = true; } } } } }
public void InitAi() { //if (!MyAPIGateway.Multiplayer.IsServer) return; if (!Constants.IsServer) { return; } if (Constants.DisableAi) { IsOperable = true; _inited = true; DebugWrite("GridComponent.InitAI", "Type:None, shutting down."); Shutdown(notify: false); return; } //SetupRecompileTimer(); try { if (Grid.Physics == null || ((MyEntity)Grid).IsPreview) { return; } } catch (Exception scrap) { LogError("InitAI[grid check]", scrap); } try { if (string.IsNullOrWhiteSpace(Rc.CustomData) || !Rc.CustomData.Contains("[EEM_AI]")) { Shutdown(notify: false); return; } if (!Rc.IsOwnedByNpc()) { DebugWrite("GridComponent.InitAI", "RC is not owned by NPC!"); Shutdown(notify: false); return; } if (Rc.CustomData.Contains("Faction:")) { try { TryAssignToFaction(); } catch (Exception scrap) { LogError("TryAssignToFaction", scrap); } } if (Rc.CustomData.Contains("Type:None")) { IsOperable = true; _inited = true; DebugWrite("GridComponent.InitAI", "Type:None, shutting down."); Shutdown(notify: false); return; } //BotTypeBase botType = BotBase.ReadBotType(Rc); //switch (botType) //{ // case BotTypeBase.None: // DebugWrite("GridComponent.InitAI", "Skipping grid — no setup found"); // break; // case BotTypeBase.Invalid: // LogError("GridComponent.InitAI", new Exception("Bot type is not valid!", new Exception())); // break; // case BotTypeBase.Station: // break; // case BotTypeBase.Fighter: // break; // case BotTypeBase.Freighter: // break; // case BotTypeBase.Carrier: // break; //} //DebugWrite("GridComponent.InitAI", $"Bot found. Bot type: {BotType.ToString()}"); } catch (Exception scrap) { LogError("GridComponent.InitAI", scrap); return; } try { Ai = BotFabric.FabricateBot(Grid, Rc); if (Ai == null) { DebugWrite("GridComponent.InitAI", "Bot Fabricator yielded null"); Shutdown(); return; } bool init = Ai.Init(Rc); if (init) { //DebugWrite("GridComponent.InitAI", "AI.Init() successfully initialized AI component"); } else { DebugWrite("GridComponent.InitAI", "AI.Init() returned false — bot initialization failed somewhy"); Shutdown(); return; } if (Ai.Update != default(MyEntityUpdateEnum)) { NeedsUpdate |= Ai.Update; } Rc.OnMarkForClose += (trash) => { Shutdown(); }; IsOperable = true; _inited = true; } catch (Exception scrap) { LogError("GridComponent.InitAI", scrap); Shutdown(); } }
internal void RemoveComp() { try { if (Registered) { RegisterEvents(false); } if (Ai != null) { Ai.OptimalDps -= PeakDps; Ai.EffectiveDps -= EffectiveDps; WeaponCount wCount; if (Ai.WeaponCounter.TryGetValue(MyCube.BlockDefinition.Id.SubtypeId, out wCount)) { wCount.Current--; Constructs.UpdateWeaponCounters(Ai); if (wCount.Current == 0) { Ai.WeaponCounter.Remove(MyCube.BlockDefinition.Id.SubtypeId); Session.WeaponCountPool.Return(wCount); } } else if (Session.LocalVersion) { Log.Line($"didnt find counter for: {MyCube.BlockDefinition.Id.SubtypeId} - MarkedForClose:{Ai.MarkedForClose} - AiAge:{Ai.Session.Tick - Ai.AiSpawnTick} - CubeMarked:{MyCube.MarkedForClose} - GridMarked:{MyCube.CubeGrid.MarkedForClose}"); } if (Ai.Data.Repo.ActiveTerminal == MyCube.EntityId) { Ai.Data.Repo.ActiveTerminal = 0; } GridAi testAi; WeaponComponent comp; if (Ai.WeaponBase.TryRemove(MyCube, out comp)) { if (Platform.State == MyWeaponPlatform.PlatformState.Ready) { for (int i = 0; i < comp.Platform.Weapons.Length; i++) { var w = comp.Platform.Weapons[i]; w.StopShooting(); w.WeaponCache.HitEntity.Clean(); if (!Session.IsClient) { w.Target.Reset(Session.Tick, Target.States.AiLost); } if (w.DrawingPower) { w.StopPowerDraw(); } } } Ai.CompChange(false, this); } else { Log.Line($"RemoveComp Weaponbase didn't have my comp: {Ai.Session.CompsDelayed.Contains(this)} - FoundAi:{Ai.Session.GridTargetingAIs.TryGetValue(MyCube.CubeGrid, out testAi)} - sameAi:{testAi == Ai}"); } if (Ai.WeaponBase.Count == 0) { GridAi gridAi; Session.GridTargetingAIs.TryRemove(Ai.MyGrid, out gridAi); } Ai = null; } else if (Platform.State != MyWeaponPlatform.PlatformState.Delay) { Log.Line($"CompRemove: Ai already null - State:{Platform.State} - Status:{Status}"); } } catch (Exception ex) { Log.Line($"Exception in RemoveComp: {ex} - AiNull:{Ai == null} - SessionNull:{Session == null}"); } }
public IActionResult Details(int id) { Ai feed = _repo.Ais.GetById(id); return(View(feed)); }
internal void ReInit() { using (MyCube.Pin()) { if (!MyCube.MarkedForClose && Entity != null) { GridAi ai; if (!Session.GridTargetingAIs.TryGetValue(MyCube.CubeGrid, out ai)) { var newAi = Session.GridAiPool.Get(); newAi.Init(MyCube.CubeGrid, Session); Session.GridTargetingAIs.TryAdd(MyCube.CubeGrid, newAi); Ai = newAi; } else { Ai = ai; } if (Ai != null && Ai.WeaponBase.TryAdd(MyCube, this)) { Ai.FirstRun = true; var blockDef = MyCube.BlockDefinition.Id.SubtypeId; if (!Ai.WeaponCounter.ContainsKey(blockDef)) { Ai.WeaponCounter.TryAdd(blockDef, Session.WeaponCountPool.Get()); } Ai.WeaponCounter[blockDef].Current++; Ai.CompChange(true, this); RegisterEvents(); if (Platform.State == MyWeaponPlatform.PlatformState.Inited) { Platform.ResetParts(this); } Entity.NeedsWorldMatrix = true; if (!Ai.GridInit || !Ai.Session.GridToFatMap.ContainsKey(Ai.MyGrid)) { Session.CompReAdds.Add(new CompReAdd { Ai = Ai, Comp = this }); } else { OnAddedToSceneTasks(); } } else { Log.Line($"Comp ReInit() failed stage2!"); } } else { Log.Line($"Comp ReInit() failed stage1! - marked:{MyCube.MarkedForClose} - Entity:{Entity != null} - hasAi:{Session.GridTargetingAIs.ContainsKey(MyCube.CubeGrid)}"); } } }
public AiController(Ai ai) { m_ai = ai ?? throw new ArgumentNullException(nameof(m_ai)); }
protected override void ExecuteQuery() { Ai.SetBestResult(this); }
public AiController(Entity owner, AiController original) : base(owner, original.Id) { m_ai = original.m_ai.Copy(owner); }
public void LoadPlayersTypes() { prefab = (GameObject)Resources.Load("Prefabs/PlayerManagment"); aiPrefab = (GameObject)Resources.Load("Prefabs/AiManagement"); switch (gameInfo.player1type) { case PlayerTypeEnum.Player: player1 = Instantiate(prefab); player1Comp = player1.transform.GetChild(0).GetComponent <Player>(); player1.SetActive(false); break; case PlayerTypeEnum.AI: player1 = Instantiate(aiPrefab); ai1Comp = player1.transform.GetChild(0).GetComponent <Ai>(); player1.SetActive(false); break; } switch (gameInfo.player2type) { case PlayerTypeEnum.Player: player2 = Instantiate(prefab); player2Comp = player2.transform.GetChild(0).GetComponent <Player>(); player2.SetActive(false); break; case PlayerTypeEnum.AI: player2 = Instantiate(aiPrefab); ai2Comp = player2.transform.GetChild(0).GetComponent <Ai>(); player2.SetActive(false); break; } switch (gameInfo.player3type) { case PlayerTypeEnum.Player: player3 = Instantiate(prefab); player3Comp = player3.transform.GetChild(0).GetComponent <Player>(); player3.SetActive(false); break; case PlayerTypeEnum.AI: player3 = Instantiate(aiPrefab); ai3Comp = player3.transform.GetChild(0).GetComponent <Ai>(); player3.SetActive(false); break; } switch (gameInfo.player4type) { case PlayerTypeEnum.Player: player4 = Instantiate(prefab); player4Comp = player4.transform.GetChild(0).GetComponent <Player>(); player4.SetActive(false); break; case PlayerTypeEnum.AI: player4 = Instantiate(aiPrefab); ai4Comp = player4.transform.GetChild(0).GetComponent <Ai>(); player4.SetActive(false); break; } }
//Ai(); //~Ai(); public void AddWorker(ref Ai aiValue) { workers.Add(new AiWorker(ref aiValue)); }
private void Start() { ai = GetComponentInParent <Ai>(); }
public void Load(string path) { if (!File.Exists(path)) { Debug.WriteLine($"Spielstand \" {path}\" konnte nicht geladen werden. Bitte überprüfen.\n"); } string c = ""; try { ObjectManager.Instance.UnloadAll(); var doc = new XmlDocument(); doc.Load(path); Debug.WriteLine("-----------------------------------------------"); if (doc.DocumentElement != null) { foreach (XmlNode node in doc.DocumentElement.ChildNodes) { c = node.Name; if (node.Attributes == null) { continue; } if (node.Name == "Farmer") { var x = float.Parse(node.Attributes.Item(0).Value, System.Globalization.CultureInfo.InvariantCulture); var y = float.Parse(node.Attributes.Item(1).Value, System.Globalization.CultureInfo.InvariantCulture); var health = float.Parse(node.Attributes.Item(2).Value, System.Globalization.CultureInfo.InvariantCulture); var money = float.Parse(node.Attributes.Item(3).Value, System.Globalization.CultureInfo.InvariantCulture); var seed1 = int.Parse(node.Attributes.Item(4).Value, System.Globalization.CultureInfo.InvariantCulture); var seed2 = int.Parse(node.Attributes.Item(5).Value, System.Globalization.CultureInfo.InvariantCulture); var seed3 = int.Parse(node.Attributes.Item(6).Value, System.Globalization.CultureInfo.InvariantCulture); var points = int.Parse(node.Attributes.Item(7).Value, System.Globalization.CultureInfo.InvariantCulture); var time = float.Parse(node.Attributes.Item(8).Value, System.Globalization.CultureInfo.InvariantCulture); ObjectManager.Instance.Add(new Farmer(x, y)); ObjectManager.Instance.GetFarmer().Health = (int)health; EconomyManager.Instance.GoldAmount = (int)money; EconomyManager.Instance.SeedAmount1 = seed1; EconomyManager.Instance.SeedAmount2 = seed2; EconomyManager.Instance.SeedAmount3 = seed3; Game1.sStatistics.Points = points; Game1.mTime = time; Debug.WriteLine("Farmer Loaded" + points); } else if (node.Name == "Fence") { var x = float.Parse(node.Attributes.Item(0).Value, System.Globalization.CultureInfo.InvariantCulture); var y = float.Parse(node.Attributes.Item(1).Value, System.Globalization.CultureInfo.InvariantCulture); var health = float.Parse(node.Attributes.Item(2).Value.PadLeft(2), System.Globalization.CultureInfo.InvariantCulture); var level = int.Parse(node.Attributes.Item(3).Value, System.Globalization.CultureInfo.InvariantCulture); ObjectManager.Instance.Add(new Fence((int)x, (int)y, level: level, loadhealth: (int)health)); Debug.WriteLine("Fence Loaded"); } else if (node.Name == "FogOfWar") { Game1.sFog.Reset(); for (var i = 0; i < node.Attributes.Count; i++) { var visiblePoint = node.Attributes.Item(i).Value.Split(','); var end = visiblePoint[1].Length - 1; var x = int.Parse(visiblePoint[0].Remove(0, 1)); var y = int.Parse(visiblePoint[1].Remove(end)); Game1.sFog.SetField(x, y); } } else if (node.Name == "Tower") { var x = float.Parse(node.Attributes.Item(0).Value, System.Globalization.CultureInfo.InvariantCulture); var y = float.Parse(node.Attributes.Item(1).Value, System.Globalization.CultureInfo.InvariantCulture); var health = float.Parse(node.Attributes.Item(2).Value, System.Globalization.CultureInfo.InvariantCulture); var level = int.Parse(node.Attributes.Item(3).Value, System.Globalization.CultureInfo.InvariantCulture); ObjectManager.Instance.Add(new Tower((int)x, (int)y, loadhealth: (int)health, level: level)); Debug.WriteLine("Tower Loaded"); } else if (node.Name == "Chicken") { var x = float.Parse(node.Attributes.Item(0).Value, System.Globalization.CultureInfo.InvariantCulture); var y = float.Parse(node.Attributes.Item(1).Value, System.Globalization.CultureInfo.InvariantCulture); var health = float.Parse(node.Attributes.Item(2).Value, System.Globalization.CultureInfo.InvariantCulture); var level = int.Parse(node.Attributes.Item(3).Value, System.Globalization.CultureInfo.InvariantCulture); ObjectManager.Instance.Add(new Chicken((int)x, (int)y, loadhealth: (int)health, level: level)); Debug.WriteLine("Chicken Loaded"); } else if (node.Name == "Cow") { var x = float.Parse(node.Attributes.Item(0).Value, System.Globalization.CultureInfo.InvariantCulture); var y = float.Parse(node.Attributes.Item(1).Value, System.Globalization.CultureInfo.InvariantCulture); var health = float.Parse(node.Attributes.Item(2).Value, System.Globalization.CultureInfo.InvariantCulture); var level = int.Parse(node.Attributes.Item(3).Value, System.Globalization.CultureInfo.InvariantCulture); ObjectManager.Instance.Add(new Cow((int)x, (int)y, loadhealth: (int)health, level: level)); Debug.WriteLine("Cow Loaded"); } else if (node.Name == "AttackCow") { var x = float.Parse(node.Attributes.Item(0).Value, System.Globalization.CultureInfo.InvariantCulture); var y = float.Parse(node.Attributes.Item(1).Value, System.Globalization.CultureInfo.InvariantCulture); var health = float.Parse(node.Attributes.Item(2).Value, System.Globalization.CultureInfo.InvariantCulture); ObjectManager.Instance.Add(new AttackCow((int)x, (int)y, loadhealth: (int)health)); Debug.WriteLine("Attackcow Loaded"); } else if (node.Name == "AttackChicken") { var x = float.Parse(node.Attributes.Item(0).Value, System.Globalization.CultureInfo.InvariantCulture); var y = float.Parse(node.Attributes.Item(1).Value, System.Globalization.CultureInfo.InvariantCulture); var health = float.Parse(node.Attributes.Item(2).Value, System.Globalization.CultureInfo.InvariantCulture); ObjectManager.Instance.Add(new AttackChicken((int)x, (int)y, loadhealth: (int)health)); Debug.WriteLine("Attackchicken Loaded"); } else if (node.Name == "AttackPig") { var x = float.Parse(node.Attributes.Item(0).Value, System.Globalization.CultureInfo.InvariantCulture); var y = float.Parse(node.Attributes.Item(1).Value, System.Globalization.CultureInfo.InvariantCulture); var health = float.Parse(node.Attributes.Item(2).Value, System.Globalization.CultureInfo.InvariantCulture); ObjectManager.Instance.Add(new AttackPig((int)x, (int)y, loadhealth: (int)health)); Debug.WriteLine("Attackpig Loaded"); } else if (node.Name == "Trap") { var x = float.Parse(node.Attributes.Item(0).Value, System.Globalization.CultureInfo.InvariantCulture); var y = float.Parse(node.Attributes.Item(1).Value, System.Globalization.CultureInfo.InvariantCulture); ObjectManager.Instance.Add(new Trap((int)x, (int)y)); Debug.WriteLine("Trap Loaded"); } else if (node.Name == "FarmerHouse") { var x = float.Parse(node.Attributes.Item(0).Value, System.Globalization.CultureInfo.InvariantCulture); var y = float.Parse(node.Attributes.Item(1).Value, System.Globalization.CultureInfo.InvariantCulture); var health = float.Parse(node.Attributes.Item(2).Value, System.Globalization.CultureInfo.InvariantCulture); ObjectManager.Instance.Add(new Farmhouse((int)x, (int)y, loadhealth: (int)health)); } else if (node.Name == "Necromancer") { var x = float.Parse(node.Attributes.Item(0).Value, System.Globalization.CultureInfo.InvariantCulture); var y = float.Parse(node.Attributes.Item(1).Value, System.Globalization.CultureInfo.InvariantCulture); var health = float.Parse(node.Attributes.Item(2).Value, System.Globalization.CultureInfo.InvariantCulture); ObjectManager.Instance.Add(new Necromancer((int)x, (int)y, loadhealth: (int)health)); } else if (node.Name == "Pig") { var x = float.Parse(node.Attributes.Item(0).Value, System.Globalization.CultureInfo.InvariantCulture); var y = float.Parse(node.Attributes.Item(1).Value, System.Globalization.CultureInfo.InvariantCulture); var health = float.Parse(node.Attributes.Item(2).Value, System.Globalization.CultureInfo.InvariantCulture); var level = int.Parse(node.Attributes.Item(3).Value, System.Globalization.CultureInfo.InvariantCulture); ObjectManager.Instance.Add(new Pig((int)x, (int)y, loadhealth: (int)health, level)); Debug.WriteLine("pig Loaded"); } else if (node.Name == "Tree") { var x = float.Parse(node.Attributes.Item(0).Value, System.Globalization.CultureInfo.InvariantCulture); var y = float.Parse(node.Attributes.Item(1).Value, System.Globalization.CultureInfo.InvariantCulture); var health = float.Parse(node.Attributes.Item(2).Value, System.Globalization.CultureInfo.InvariantCulture); ObjectManager.Instance.Add(new Tree((int)x, (int)y, loadhealh: (int)health)); Debug.WriteLine("Tree Loaded"); } else if (node.Name == "Boulder") { var x = float.Parse(node.Attributes.Item(0).Value, System.Globalization.CultureInfo.InvariantCulture); var y = float.Parse(node.Attributes.Item(1).Value, System.Globalization.CultureInfo.InvariantCulture); ObjectManager.Instance.Add(new Boulder((int)x, (int)y)); Debug.WriteLine("Boulder Loaded"); } else if (node.Name == "Zombie") { var x = float.Parse(node.Attributes.Item(0).Value, System.Globalization.CultureInfo.InvariantCulture); var y = float.Parse(node.Attributes.Item(1).Value, System.Globalization.CultureInfo.InvariantCulture); var health = float.Parse(node.Attributes.Item(2).Value, System.Globalization.CultureInfo.InvariantCulture); if (health > 0) { ObjectManager.Instance.Add(new Zombie((int)x, (int)y, loadhealth: (int)health)); Debug.WriteLine("Zombie Loaded"); } } else if (node.Name == "Graveyard") { var x = float.Parse(node.Attributes.Item(0).Value, System.Globalization.CultureInfo.InvariantCulture); var y = float.Parse(node.Attributes.Item(1).Value, System.Globalization.CultureInfo.InvariantCulture); var health = float.Parse(node.Attributes.Item(2).Value, System.Globalization.CultureInfo.InvariantCulture); ObjectManager.Instance.Add(new Graveyard((int)x, (int)y, (int)health)); Debug.WriteLine("graveyard Loaded"); } else if (node.Name == "Wheat") { var x = int.Parse(node.Attributes.Item(0).Value, System.Globalization.CultureInfo.InvariantCulture); var y = int.Parse(node.Attributes.Item(1).Value, System.Globalization.CultureInfo.InvariantCulture); var type = node.Attributes.Item(2).Value; Wheat.WheatType tmp; if (type == "Corn") { tmp = Wheat.WheatType.Corn; } else if (type == "Wheat1") { tmp = Wheat.WheatType.Wheat1; } else { tmp = Wheat.WheatType.Wheat2; } var stage = int.Parse(node.Attributes.Item(3).Value, System.Globalization.CultureInfo.InvariantCulture); var time = float.Parse(node.Attributes.Item(4).Value, System.Globalization.CultureInfo.InvariantCulture); var health = float.Parse(node.Attributes.Item(5).Value, System.Globalization.CultureInfo.InvariantCulture); Game1.sTileMap.mPlowedTiles.Remove(new Vector2(x, y)); ObjectManager.Instance.Add(new Wheat(x, y, tmp, stage: stage, loadinghealth: (int)health, time: time)); Game1.sTileMap.SetTile(x, y, Tile.Dirt); Debug.WriteLine("wheat Loaded"); } else if (node.Name == "Map") { // first planting grass everywhere for (var i = 0; i < Game1.MapWidth; i++) { for (var j = 0; j < Game1.MapHeight; j++) { Game1.sTileMap.PlantGrass(i, j, true); } } // then loading all fields which are not grass for (var i = 0; i < node.Attributes.Count; i++) { var visiblePoint = node.Attributes.Item(i).Value.Split(','); var x = int.Parse(visiblePoint[0]); var y = int.Parse(visiblePoint[1]); if (int.Parse(node.Attributes.Item(i).Name.Split('X')[1]) == 1) { Game1.sTileMap.PlowTile(x, y); } if (int.Parse(node.Attributes.Item(i).Name.Split('X')[1]) == 2) { Game1.sTileMap.PlantWater(x, y); } if (int.Parse(node.Attributes.Item(i).Name.Split('X')[1]) == 3) { Game1.sTileMap.PlantWasteland(x, y); } } } } } Ai.AddWave(ObjectManager.Instance.GetZombies().ToList()); } catch (Exception e) { Console.WriteLine(e); if (c != null) { Debug.WriteLine(c + "error"); } throw; } }