public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response) { if (!((CommandSender)sender).CheckPermission("fctrl.killzone")) { response = "Access denied."; return(false); } if (arguments.Count() < 1) { response = "Invalid format. Must be: \"killzone light/heavy/entrance/surface (eg. killzone light)"; return(false); } if (arguments.At(0).ToLower() != "light" && arguments.At(0).ToLower() != "heavy" && arguments.At(0).ToLower() != "entrance" && arguments.At(0).ToLower() != "surface") { response = "First argument must be light, heavy, entrance, or surface"; return(false); } ZoneType zone = (arguments.At(0).ToLower() == "light" ? ZoneType.LightContainment : (arguments.At(0).ToLower() == "heavy" ? ZoneType.HeavyContainment : (arguments.At(0).ToLower() == "entrance" ? ZoneType.Entrance : (arguments.At(0).ToLower() == "surface" ? ZoneType.Surface : ZoneType.Unspecified)))); int totalKilled = 0; foreach (Player Ply in Player.List) { if (Ply.CurrentRoom.Zone == zone && !Ply.IsGodModeEnabled) { Ply.Hurt(99999, DamageTypes.Wall, "ZONEKILL"); totalKilled++; } } response = $"Killed {totalKilled} players in {zone.ToString()}"; return(true); }
private void CreateMovePlyPool() { int totalSize = Constants.BoardSize * Constants.BoardSize; // the types of the constructor parameters, in order Type[] paramTypes = new Type[] { typeof(int), typeof(int), typeof(int), typeof(int) }; for (int from = 0; from < totalSize; from++) { movePlies[from] = new Ply[totalSize][]; for (int to = 0; to < totalSize; to++) { if (!IsValidMove(from, to)) { continue; } movePlies[from][to] = new Ply[Constants.WinnerHeight]; for (int count = 1; count < Constants.WinnerHeight; count++) { // the values of the constructor parameters, in order object[] paramValues = new object[] { from, to, count, poolSize++ }; movePlies[from][to][count] = Construct <MovePly>(paramTypes, paramValues); } } } }
void ResetBoardBackwards(Ply ply) { foreach (AffectedPiece p in ply.changes) { p.Undo(); } }
public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response) { if (!(sender as CommandSender).CheckPermission("ct.explode")) { response = "You do not have permission to run this command! Missing permission: \"ct.explode\""; return(false); } if (arguments.Count != 0) { response = "Usage: explode all / *"; return(false); } foreach (Exiled.API.Features.Player Ply in Exiled.API.Features.Player.List) { if (Ply.Role == RoleType.Spectator || Ply.Role == RoleType.None) { continue; } Ply.Kill(); CreativeToolboxEventHandler.SpawnGrenadeOnPlayer(Ply, false); } response = "Everyone exploded, Hubert cannot believe you have done this"; return(true); }
public async override void Enter() { Task <Ply> task = AIController.instance.CalculatePlays(); await task; Ply bestResult = task.Result; MakeBestPlay(bestResult); }
/// <summary> /// Awake is called when the script instance is being loaded. /// </summary> void Awake() { instance = this; maxPly = new Ply(); maxPly.score = 999999; minPly = new Ply(); minPly.score = -999999; squareTable.SetDictionaries(); }
void EvaluateBoard(Ply ply) { foreach (Piece piece in Board.instance.goldPieces) { EvaluatePiece(piece, ply, 1); } foreach (Piece piece in Board.instance.greenPieces) { EvaluatePiece(piece, ply, -1); } // Debug.Log("Board score: " + ply.score); }
AvailableMove GetMoveType(Ply ply) { List <AvailableMove> moves = Board.instance.selectedPiece.movement.GetValidMoves(); foreach (AvailableMove m in moves) { if (m.pos == ply.changes[0].to.pos) { return(m); } } return(new AvailableMove()); }
private static Ply AiStep(IList <Ply> history, ISolver <Ply> solver) { Ply result = solver.OptimizeNextMove(history); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("AI thinking..."); //Console.WriteLine(string.Format("Evaluation value: {0} ({1})", evaluationValue, ToString(evaluationValue))); Console.WriteLine(string.Format("Optimal next step: {0}", result)); //Console.WriteLine(string.Format("Forecast: {0}", string.Join(" ## ", forecast))); Console.ForegroundColor = ConsoleColor.White; return(result); }
protected override bool ExecuteParent(ArraySegment <string> arguments, ICommandSender sender, out string response) { EventHandlers.LogCommandUsed((CommandSender)sender, EventHandlers.FormatArguments(arguments, 0)); if (!((CommandSender)sender).CheckPermission("at.kill")) { response = "You do not have permission to use this command"; return(false); } if (arguments.Count != 1) { response = "Usage: kill ((player id / name) or (all / *))"; return(false); } switch (arguments.At(0)) { case "*": case "all": foreach (Player Ply in Player.List) { if (Ply.Role == RoleType.Spectator || Ply.Role == RoleType.None) { continue; } Ply.Kill(); } response = "Everyone has been game ended (killed) now"; return(true); default: Player Pl = Player.Get(arguments.At(0)); if (Pl == null) { response = $"Player not found: {arguments.At(0)}"; return(false); } else if (Pl.Role == RoleType.Spectator || Pl.Role == RoleType.None) { response = $"Player {Pl.Nickname} is not a valid class to kill"; return(false); } Pl.Kill(); response = $"Player {Pl.Nickname} has been game ended (killed) now"; return(true); } }
void GetLocalPlayer() { foreach (GameObject Ply in GameObject.FindGameObjectsWithTag("Player")) { if (Ply.GetComponent <NetworkIdentity>().isLocalPlayer) { PlayerGo = Ply; if (HUDActive) { ToggleHUD(); } return; } } }
void PrintBestPly(Ply finalPly) { Ply currentPly = finalPly; Debug.Log("Melhor Jogada:"); while (currentPly.originPly != null) { Debug.LogFormat("{0}-{1}->{2}", currentPly.changes[0].piece.transform.parent.name, currentPly.changes[0].piece.name, currentPly.changes[0].to.pos); currentPly = currentPly.originPly; } }
async void MakeBestPlay(Ply ply) { Ply currentPly = ply; for (int i = 1; i < AIController.instance.objectivePlyDepth; i++) { currentPly = currentPly.originPly; } Board.instance.selectedPiece = currentPly.changes[0].piece; Debug.Log(currentPly.changes[0].piece.name); Board.instance.selectedMove = GetMoveType(currentPly); Debug.Log(Board.instance.selectedMove); await Task.Delay(100); machine.ChangeTo <PieceMovementState>(); }
// Server Events public void OnRoundStarted() { foreach (KeyValuePair <string, List <Player> > data in FacilityControl.PlySets) { FacilityControl.PlySets[data.Key].Clear(); } // Credit for the original idea behind SCP lockdown goes to AlmightyLks's SCPLockdown plugin, found here: https://github.com/AlmightyLks/SCPLockdown foreach (KeyValuePair <RoleType, int> data in FacilityControl.Instance.Config.ScpLockdownPeriod) { if (data.Value == 0) { continue; } FacilityControl.ScpRoomLockdown[data.Key] = true; Timing.CallDelayed(data.Value, () => { FacilityControl.ScpRoomLockdown[data.Key] = false; List <Player> PlyList = Player.List.Where(P => P.Role == data.Key).ToList(); foreach (Player Ply in PlyList) { if (data.Key == RoleType.Scp079) { Ply.ReferenceHub.scp079PlayerScript.maxMana = 100; Ply.ReferenceHub.scp079PlayerScript.Mana = 100; } else if (data.Key == RoleType.Scp106) { Ply.Position = Map.GetRandomSpawnPoint(RoleType.Scp106); Timing.CallDelayed(0.3f, () => { Ply.ReferenceHub.scp106PlayerScript.DeletePortal(); }); } if (Ply != null && FacilityControl.Instance.Config.ScpLockdownOpenNotif == true) { Ply.ShowHint(FacilityControl.Instance.Config.ScpLockdownOpenMessage, 2); } } }); } }
protected override bool ExecuteParent(ArraySegment <string> arguments, ICommandSender sender, out string response) { EventHandlers.LogCommandUsed((CommandSender)sender, EventHandlers.FormatArguments(arguments, 0)); if (!CommandProcessor.CheckPermissions(((CommandSender)sender), "strip", PlayerPermissions.PlayersManagement, "AdminTools", false)) { response = "You do not have permission to use this command"; return(false); } if (arguments.Count != 1) { response = "Usage: strip ((player id / name) or (all / *))"; return(false); } switch (arguments.At(0)) { case "*": case "all": foreach (Player Ply in Player.List) { Ply.ClearInventory(); } response = "Everyone's inventories have been cleared now"; return(true); default: Player Pl = Player.Get(arguments.At(0)); if (Pl == null) { response = $"Player not found: {arguments.At(0)}"; return(false); } Pl.ClearInventory(); response = $"Player {Pl.Nickname}'s inventory have been cleared now"; return(true); } }
Ply IsBest(Ply ply, int minimaxDirection, Ply potentialBest, ref int alpha, ref int beta) { Ply best = ply; if (minimaxDirection == 1) { if (potentialBest.score > ply.score) { best = potentialBest; } alpha = Mathf.Max(alpha, best.score); } else { if (potentialBest.score < ply.score) { best = potentialBest; } beta = Mathf.Max(beta, best.score); } return(best); }
public async Task <Ply> CalculatePlays() { lastInterval = Time.realtimeSinceStartup; int minimaxDirection; if (StateMachineController.instance.currentlyPlaying == StateMachineController.instance.player1) { minimaxDirection = 1; } else { minimaxDirection = -1; } enPassantSaved = PieceMovementState.enPassantFlag; Ply currentPly = new Ply(); calculationCount = 0; currentPly.originPly = null; int currentPlyDepth = 0; currentPly.changes = new List <AffectedPiece>(); Debug.Log("Começo"); Task <Ply> calculation = CalculatePly(currentPly, -1000000, 1000000, currentPlyDepth, minimaxDirection); await calculation; currentPly.bestFuture = calculation.Result; Debug.Log("Calculations: " + calculationCount); Debug.Log("Time: " + (Time.realtimeSinceStartup - lastInterval)); PrintBestPly(currentPly.bestFuture); PieceMovementState.enPassantFlag = enPassantSaved; return(currentPly.bestFuture); }
private void EvaluatePiece(Piece eva, Ply ply, int scoreDirection) { int positionValue = eva.movement.positionValue[eva.tile.pos]; ply.score += (eva.movement.value + positionValue) * scoreDirection; }
public GameData Load() { if (File.Exists(dataPath)) { //파일존재하면데이터 불러오기 BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(dataPath, FileMode.Open); //데이터의 기록 gameData = (GameData)bf.Deserialize(file); file.Close(); for (int i = 0; i < MapObjS.Length; i++) { if (gameData.MapObj[i] != 0) { MapObjS[i].MapTrue(); } } for (int i = 0; i < SavePos.Length; i++) { if (gameData.AllSavePoint[i] != 0) { SavePos[i].NowState = gameData.AllSavePoint[i]; } //Debug.Log(i + " " + gameData.AllSavePoint[i]); } for (int i = StoryTr.childCount - 1; i >= 0; i--) { if (gameData.Story[i]) { Destroy(StoryTr.GetChild(i).gameObject); } } MonsterSSS(); //Ply.GetComponent<Player>().EndDie(); Vector3 GG = SavePos[gameData.SavePoint].transform.position; Sond(SavePos[gameData.SavePoint].BGSound); Ply.position = new Vector3(GG.x, GG.y, Ply.position.z); Ply.GetComponent <Player>().Hand.position = new Vector3(GG.x, GG.y, Ply.GetComponent <Player>().Hand.position.z); if (SavePos[gameData.SavePoint].MovePos == null) { SavePos[gameData.SavePoint].MovePos = SavePos[gameData.SavePoint].transform.parent.Find("MoveMap").GetChild(0); } GG = SavePos[gameData.SavePoint].MovePos.GetChild(1).position; Camera.main.transform.position = new Vector3(GG.x, GG.y, Camera.main.transform.position.z); Camera.main.GetComponent <CamMove>().XLock = SavePos[gameData.SavePoint].MovePos.parent.parent.GetComponent <MapManager>().XLock; Camera.main.GetComponent <CamMove>().YLock = SavePos[gameData.SavePoint].MovePos.parent.parent.GetComponent <MapManager>().YLock; return(gameData); } else { //파일이 없으면 새로생성 ResetMap(); return(gameData); } }//파일에서 데이터를 추출하는 함수
public int Quiescene(int alpha, int beta, BoardState bs, SearchInfo sInfo) { if (sInfo.IsTimeUp()) { sInfo.Stopped = true; } //sInfo.Nodes++; /*if (_helper.IsRepetition(bs) || bs.FiftyMoveRule >= 100) * { * //if (bs.BestPly != null) bs.BestPly.Score = 0; * return 0; * }*/ var score = _eval.EvalPosition(bs); if (score >= beta) { return(beta); } if (score > alpha) { alpha = score; } var mg = new MoveGenerator(bs); var capMoves = mg.AllCapMoves(); Ply bestMove = null; var nMoves = 0; if (capMoves != null) { nMoves = capMoves.Length; } var oldAlpha = alpha; var moveNum = 0; if (bs.BestPlyAtLowerDepth != null && !bs.HaveSearched) { mg.MakeMove(bs.BestPlyAtLowerDepth); bs.BestPlyAtLowerDepth.Score = -Quiescene(-beta, -alpha, bs, sInfo); mg.UndoMove(bs.BestPlyAtLowerDepth); bs.HaveSearched = true; bestMove = bs.BestPlyAtLowerDepth; alpha = bestMove.Score; //Console.WriteLine("This never happens."); } for (moveNum = 0; moveNum < nMoves; moveNum++) { mg.MakeMove(capMoves[moveNum]); capMoves[moveNum].Score = -Quiescene(-beta, -alpha, bs, sInfo); mg.UndoMove(capMoves[moveNum]); if (sInfo.Stopped) { return(Definitions.Stopped); } if (capMoves[moveNum].Score <= alpha) { continue; } if (capMoves[moveNum].Score >= beta) { if (nMoves == 1) { sInfo.Fhf++; } sInfo.Fh++; return(beta); // Fail hard beta-cutoff. } alpha = capMoves[moveNum].Score; // alpha acts like max in minimax. bestMove = capMoves[moveNum]; } if (alpha != oldAlpha) { //Console.WriteLine("New best ply!"); bs.BestPly = bestMove; } return(alpha); }
// Inspiration from VICE Chess Engine. public int AlphaBeta(int alpha, int beta, int depth, BoardState bs, SearchInfo sInfo) { if (depth == 0) { //return _eval.EvalPosition(bs); return(Quiescene(alpha, beta, bs, sInfo)); } // Check if time is up or interrupted by the GUI. if (sInfo.IsTimeUp()) { sInfo.Stopped = true; } sInfo.Nodes++; /*if (bs.BestPly != null) * { * if (bs.FiftyMoveRule >= 100 || _helper.IsRepetition(bs)) * { * return 0; * //Console.WriteLine("bestmove: {0}{1}, score {2}", Definitions.IndexToAlgebraic[bs.BestPly.GetFromToSquare()[0]], Definitions.IndexToAlgebraic[bs.BestPly.GetFromToSquare()[1]], bs.BestPly.Score); * } * }*/ var mg = new MoveGenerator(bs); var legalMoves = mg.AllLegalMoves(); Ply bestMove = null; var nMoves = legalMoves.Length; var oldAlpha = alpha; var moveNum = 0; if (bs.BestPlyAtLowerDepth != null && !bs.HaveSearched) { mg.MakeMove(bs.BestPlyAtLowerDepth); bs.BestPlyAtLowerDepth.Score = -AlphaBeta(-beta, -alpha, depth - 1, bs, sInfo); mg.UndoMove(bs.BestPlyAtLowerDepth); bs.HaveSearched = true; bestMove = bs.BestPlyAtLowerDepth; alpha = bestMove.Score; } for (moveNum = 0; moveNum < legalMoves.Length; moveNum++) { mg.MakeMove(legalMoves[moveNum]); legalMoves[moveNum].Score = -AlphaBeta(-beta, -alpha, depth - 1, bs, sInfo); mg.UndoMove(legalMoves[moveNum]); if (sInfo.Stopped) { return(Definitions.Stopped); } if (legalMoves[moveNum].Score >= beta) { if (nMoves == 1) { sInfo.Fhf++; } sInfo.Fh++; return(beta); // Fail hard beta-cutoff. } if (legalMoves[moveNum].Score > alpha) { alpha = legalMoves[moveNum].Score; // alpha acts like max in minimax. bestMove = legalMoves[moveNum]; } } if (nMoves == 0) { if (_helper.IsKingInCheck(bs.SideToMove, bs.BoardRepresentation, bs.KingSquares)) { return(-Definitions.MATE + bs.Ply); } // Stalemate. return(0); } if (alpha != oldAlpha) { bs.BestPly = bestMove; } return(alpha); }
// Queen Moves = Rook Moves + Bishop Moves #endregion #endregion public bool AreInverses(Ply one, Ply other) { return(one.From == other.To && one.To == other.From && one.Count == other.Count); }
async Task <Ply> CalculatePly(Ply parentPly, int alpha, int beta, int currentPlyDepth, int minimaxDirection) { currentPlyDepth++; if (currentPlyDepth > objectivePlyDepth) { EvaluateBoard(parentPly); // Task evaluationTask = Task.Run(()=> EvaluateBoard(parentPly)); // await evaluationTask; return(parentPly); } List <Piece> team; if (minimaxDirection == 1) { team = Board.instance.goldPieces; parentPly.bestFuture = minPly; } else { team = Board.instance.greenPieces; parentPly.bestFuture = maxPly; } Ply plyceHolder = new Ply(); plyceHolder.score = -9999999 * minimaxDirection; parentPly.bestFuture = plyceHolder; for (int i = 0; i < team.Count; i++) { Board.instance.selectedPiece = team[i]; foreach (AvailableMove move in team[i].movement.GetValidMoves()) { calculationCount++; Board.instance.selectedPiece = team[i]; Board.instance.selectedMove = move; TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>(); PieceMovementState.MovePiece(tcs, true, move.moveType); await tcs.Task; Ply newPly = new Ply(); newPly.changes = PieceMovementState.changes; newPly.enPassantFlag = PieceMovementState.enPassantFlag; Task <Ply> calculation = CalculatePly(newPly, alpha, beta, currentPlyDepth, minimaxDirection * -1); await calculation; parentPly.bestFuture = IsBest(parentPly.bestFuture, minimaxDirection, calculation.Result, ref alpha, ref beta); newPly.originPly = parentPly; PieceMovementState.enPassantFlag = parentPly.enPassantFlag; ResetBoardBackwards(newPly); if (beta <= alpha) { return(parentPly.bestFuture); } } } return(parentPly.bestFuture); }
protected override bool ExecuteParent(ArraySegment <string> arguments, ICommandSender sender, out string response) { EventHandlers.LogCommandUsed((CommandSender)sender, EventHandlers.FormatArguments(arguments, 0)); if (!((CommandSender)sender).CheckPermission("at.explode")) { response = "You do not have permission to use this command"; return(false); } if (arguments.Count != 1) { response = "Usage: expl ((player id / name) or (all / *))"; return(false); } switch (arguments.At(0)) { case "*": case "all": if (arguments.Count != 1) { response = "Usage: expl (all / *)"; return(false); } foreach (Player Ply in Player.List) { if (Ply.Role == RoleType.Spectator || Ply.Role == RoleType.None) { continue; } Ply.Kill(); EventHandlers.SpawnGrenadeOnPlayer(Ply, GrenadeType.Frag, 0.1f); } response = "Everyone exploded, Hubert cannot believe you have done this"; return(true); default: if (arguments.Count != 1) { response = "Usage: expl (player id / name)"; return(false); } Player Pl = Player.Get(arguments.At(0)); if (Pl == null) { response = $"Invalid target to explode: {arguments.At(0)}"; return(false); } if (Pl.Role == RoleType.Spectator || Pl.Role == RoleType.None) { response = $"Player \"{Pl.Nickname}\" is not a valid class to explode"; return(false); } Pl.Kill(); EventHandlers.SpawnGrenadeOnPlayer(Pl, GrenadeType.Frag, 0.1f); response = $"Player \"{Pl.Nickname}\" game ended (exploded)"; return(true); } }