public void BeginCheck(string descriptiveName, VCExpr vc, ProverInterface.ErrorHandler handler, int timeout, int rlimit, int?randomSeed) { Contract.Requires(descriptiveName != null); Contract.Requires(vc != null); Contract.Requires(handler != null); Contract.Requires(IsReady); status = CheckerStatus.Busy; hasOutput = false; outputExn = null; this.handler = handler; thmProver.Reset(gen); if (0 < rlimit) { timeout = 0; } SetTimeout(timeout); SetRlimit(rlimit); SetRandomSeed(randomSeed); proverStart = DateTime.UtcNow; thmProver.BeginCheck(descriptiveName, vc, handler); // gen.ClearSharedFormulas(); PR: don't know yet what to do with this guy ProverTask = Task.Factory.StartNew(() => { WaitForOutput(null); }, TaskCreationOptions.LongRunning); }
int MinValue(CheckerBoard currentBoard, int depth, int alpha, int beta, int currentPlayer) { if (_nodeGeneration % 10000 == 0 && _nodeGeneration != 0) { Console.WriteLine("Max Depth: {0}", _maxDepth); Console.WriteLine("# of Pruning in Max: {0}", _maxPruning); Console.WriteLine("# of Pruning in Min: {0}", _minPruning); Console.WriteLine("# of Node Generated: {0}", _nodeGeneration); Console.WriteLine("Time Elapsed: {0}", TimeElapsed); } CheckerStatus status = currentBoard.GetStatus(_currentTurn); if (status != CheckerStatus.Continue) { return((int)status); } _maxDepth = Math.Max(_maxDepth, depth); if (depth == Difficulty) { return(currentBoard.EvaluateBoard(_currentTurn)); } int v = 999; //For each movable piece for (var i = 0; i < currentBoard.MovablePieces[currentPlayer].Count(); i++) { //for each possible positions that the piece can go for (var j = 0; j < currentBoard.MoveDict[currentBoard.MovablePieces[currentPlayer][i]].Count(); j++) { _nodeGeneration++; //For each possible move make a new checkerboard and move it var newCheckerBoard = new CheckerBoard(currentBoard); var selectedPiece = newCheckerBoard.GetCheckerPiece(currentBoard.MovablePieces[currentPlayer][i].Row, currentBoard.MovablePieces[currentPlayer][i].Col); newCheckerBoard.SelectedPiece = selectedPiece; newCheckerBoard.HandleMove(currentBoard.MoveDict[currentBoard.MovablePieces[currentPlayer][i]][j]); newCheckerBoard.CheckAllAvailableMoves(); int nextTurn = newCheckerBoard.AINextTurn(currentPlayer); v = Math.Min(v, MaxValue(newCheckerBoard, depth + 1, alpha, beta, nextTurn)); //pruning if (v <= alpha) { _minPruning++; return(v); } if (v < beta) { beta = v; if (currentBoard == _checkerBoard) { _bestMoveSet = currentBoard.MoveDict[currentBoard.MovablePieces[currentPlayer][i]][j]; _bestPiece = currentBoard.MovablePieces[currentPlayer][i]; } } } } return(v); }
public void GoBackToIdle() { Contract.Requires(IsBusy); status = CheckerStatus.Idle; }
public void GetReady() { Contract.Requires(IsIdle); status = CheckerStatus.Ready; }
/// <summary> /// Clean-up. /// </summary> public void Close() { thmProver.Close(); status = CheckerStatus.Closed; }
public void BeginCheck(string descriptiveName, VCExpr vc, ProverInterface.ErrorHandler handler) { Contract.Requires(descriptiveName != null); Contract.Requires(vc != null); Contract.Requires(handler != null); Contract.Requires(IsReady); status = CheckerStatus.Busy; hasOutput = false; outputExn = null; this.handler = handler; thmProver.Reset(gen); SetTimeout(); proverStart = DateTime.UtcNow; thmProver.BeginCheck(descriptiveName, vc, handler); // gen.ClearSharedFormulas(); PR: don't know yet what to do with this guy ProverTask = Task.Factory.StartNew(() => { WaitForOutput(null); }, TaskCreationOptions.LongRunning); }
public CheckerOnDesk(ColorType color, CheckerStatus status, Point point) : base(color, status) { this.Point = point; }
//Gets the Max Value int MaxValue(CheckerBoard currentBoard, int depth, int alpha, int beta, int currentPlayer) { if (_nodeGeneration % 10000 == 0 && _nodeGeneration != 0) { Console.WriteLine("Max Depth: {0}", _maxDepth); Console.WriteLine("# of Pruning in Max: {0}", _maxPruning); Console.WriteLine("# of Pruning in Min: {0}", _minPruning); Console.WriteLine("# of Node Generated: {0}", _nodeGeneration); Console.WriteLine("Time Elapsed: {0}", TimeElapsed); } //Checks to see if it is a utility value CheckerStatus status = currentBoard.GetStatus(_currentTurn); //If it is return the value if (status != CheckerStatus.Continue) { return((int)status); } _maxDepth = Math.Max(_maxDepth, depth); //Depth Limiter if (depth == Difficulty) { return(currentBoard.EvaluateBoard(_currentTurn)); } var v = -999; //Iterate through every movable pieces for (var i = 0; i < currentBoard.MovablePieces[currentPlayer].Count(); i++) { //Iterate through every possible move for the selected piece for (var j = 0; j < currentBoard.MoveDict[currentBoard.MovablePieces[currentPlayer][i]].Count(); j++) { //Increment node counter _nodeGeneration++; //For each possible move make a new checkerboard and move it var newCheckerBoard = new CheckerBoard(currentBoard); //Select the piece that will be moved var selectedPiece = newCheckerBoard.GetCheckerPiece(currentBoard.MovablePieces[currentPlayer][i].Row, currentBoard.MovablePieces[currentPlayer][i].Col); newCheckerBoard.SelectedPiece = selectedPiece; //Move the piece to a piece location newCheckerBoard.HandleMove(currentBoard.MoveDict[currentBoard.MovablePieces[currentPlayer][i]][j]); newCheckerBoard.CheckAllAvailableMoves(); var nextTurn = newCheckerBoard.AINextTurn(currentPlayer); v = Math.Max(v, MinValue(newCheckerBoard, depth + 1, alpha, beta, nextTurn)); if (v >= beta) { _maxPruning++; return(v); } if (v > alpha) { alpha = v; if (currentBoard == _checkerBoard) { _bestMoveSet = currentBoard.MoveDict[currentBoard.MovablePieces[currentPlayer][i]][j]; _bestPiece = currentBoard.MovablePieces[currentPlayer][i]; } } } } return(v); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { var delta = (float)gameTime.ElapsedGameTime.TotalSeconds; TimeElapsed += delta; // Allows the game to exit if (IsActive) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed) { Exit(); } bolt.Update(gameTime); _screenManager.Update(gameTime); if (CurrentGameStatus == GameStatus.Setup) { if (_setupDialogOff) { _setupDialogOff = false; _setupForm.ShowDialog(); } /* * Renew(); * currentGameStatus = GameStatus.IN_PROGRESS; */ } else if (CurrentGameStatus == GameStatus.InProgress) { CheckerStatus status = _checkerBoard.GetStatus(_currentTurn); if (status != CheckerStatus.Continue) { CurrentGameStatus = GameStatus.GameOver; } if (status == CheckerStatus.Win) { _message = _color[_currentTurn] + " Wins!"; Console.WriteLine("{0} wins!", _color[_currentTurn]); } else if (status == CheckerStatus.Lose) { _message = String.Format("{0} wins!", _color[(_currentTurn + 1) % 2]); Console.WriteLine(_message); } else { if (CurrentVsType == VsType.CpuVsCpu) { if (_oThread == null) { _oThread = new Thread(Ai); _oThread.Start(); } } else if (CurrentVsType == VsType.PlayerVsCpu) { if (PlayerColor != _currentTurn) { if (_oThread == null) { _oThread = new Thread(Ai); _oThread.Start(); } } } } if (_oThread != null) { if (!_oThread.IsAlive) { _oThread.Join(); _oThread = null; //Move to the next turn _currentTurn = _checkerBoard.NextTurn(_currentTurn); } } foreach (var piece in _checkerBoard.AllPieces.Where(piece => piece.Status == CheckerPieceStatus.Dying)) { bolt.EndPoint = new Vector3(_checkerBoard.GetCenterOfTile(piece.Row, piece.Col), 0); break; } foreach (var piece in _checkerBoard.AllPieces.Where(piece => piece.Status == CheckerPieceStatus.Dead)) { _checkerBoard.AllPieces.Remove(piece); break; } if (_checkerBoard.AllPieces.Count(piece => piece.Status == CheckerPieceStatus.Dying) == 0) { bolt.EndPoint = _lightingBoltEnd; } _checkerBoard.Update(gameTime, _cam); } else if (CurrentGameStatus == GameStatus.GameOver) { _timer += delta; if (_particleManager.particleSystems.Count() < MaxFireworks) { if (_timer > .5) { _timer = 0f; _particleManager.Spawn(_particleManager.particleSystemInfoDict["firework"], new Vector2(Rand.Next((int)(GraphicsDevice.Viewport.Width * .1f), (int)(GraphicsDevice.Viewport.Width * .9f)), Rand.Next((int)(GraphicsDevice.Viewport.Height * .1f), (int)(GraphicsDevice.Viewport.Height * .90f))), 1f); } } } _particleManager.Update(gameTime); HandleInput(gameTime); } base.Update(gameTime); }
public static void Check() { _now = Time.time; if (!checkManually && (!needCheck || _now < _canCheckNext)) { return; } Debug.Log("<color=blue>PumkinsAvatarTools</color>: Checking for VRChat SDK in project..."); Type sdkType = GetType("VRCSDK2.VRC_AvatarDescriptor"); if (sdkType == null) { Debug.Log("<color=blue>PumkinsAvatarTools</color>: VRChat SDK not found. Please import the SDK to use these tools."); Status = CheckerStatus.NO_SDK; return; } else { Debug.Log("<color=blue>PumkinsAvatarTools</color>: Found VRChat SDK."); } Debug.Log("<color=blue>PumkinsAvatarTools</color>: Checking for DynamicBones in project..."); Type boneColliderType = GetType("DynamicBoneCollider"); Type boneColliderBaseType = GetType("DynamicBoneColliderBase"); //Type toolsType = GetType("Pumkin.AvatarTools.PumkinsAvatarTools"); var dynPaths = new List <string>(); dynPaths.AddRange(Directory.GetFiles(Application.dataPath, "DynamicBone.cs", SearchOption.AllDirectories)); dynPaths.AddRange(Directory.GetFiles(Application.dataPath, "DynamicBoneCollider.cs")); var toolScriptPath = Directory.GetFiles(Application.dataPath, "PumkinsAvatarTools.cs", SearchOption.AllDirectories); missingBoneFiles = dynPaths.Count == 0 ? true : false; if (toolScriptPath.Length > 0 && !string.IsNullOrEmpty(toolScriptPath[0])) { string toolsFile = File.ReadAllText(toolScriptPath[0]); string header = toolsFile.Substring(0, toolsFile.IndexOf("using")); toolsFile = toolsFile.Substring(toolsFile.IndexOf("using")); int hasBonesIndex = header.IndexOf(hasBonesString); int hasOldBonesIndex = header.IndexOf(hasOldBonesString); if (missingBoneFiles) //No bones in project { Status = CheckerStatus.NO_BONES; Debug.Log("<color=blue>PumkinsAvatarTools</color>: DynamicBones not found in project."); if (hasBonesIndex != -1 || hasOldBonesIndex != -1) //#define BONES present, remove { header = ""; needRewrite = true; } } else //DynamicBones Present { if (boneColliderType.IsSubclassOf(boneColliderBaseType)) { bonesAreOld = false; } else { bonesAreOld = true; } if (bonesAreOld) { Status = CheckerStatus.OK_OLDBONES; Debug.Log("<color=blue>PumkinsAvatarTools</color>: Found old version of DynamicBones in project!"); if (hasOldBonesIndex == -1) { header = hasOldBonesString; needRewrite = true; } } else { Status = CheckerStatus.OK; Debug.Log("<color=blue>PumkinsAvatarTools</color>: Found DynamicBones in project!"); if (hasBonesIndex == -1) { header = hasBonesString; needRewrite = true; } } } if (needRewrite) { File.WriteAllText(toolScriptPath[0], header + toolsFile); AssetDatabase.ImportAsset(RelativePath(toolScriptPath[0])); needRewrite = false; } } if (!checkManually) { _canCheckNext = _now + checkCooldown; } needCheck = false; }
public static void ForceCheck() { needCheck = true; Status = CheckerStatus.DEFAULT; Check(); }
public Checker(ColorType color, CheckerStatus status) { this.Color = color; this.Status = status; }
/// <summary> /// Start threads /// </summary> /// <param name="restart">Is this a restart?</param> public static void StartOrRestart() { bool restart = Core.loopThread != null; //Start checker thread Thread startThread = new Thread(() => { //If thread is not null, wait for it to stop if (restart) { threadStatus = CheckerStatus.Stopping; while (threadStatus == CheckerStatus.Stopping && Core.loopThread.ThreadState != ThreadState.Stopped) { Thread.Sleep(200); } } //Check for errors bool error = false; if (Core.conditions.Count == 0) { Core.UI.writeToConsole("No conditions, not running checks", Color.White); error = true; } if (Settings.acListUrl == "") { Core.UI.writeToConsole("ERROR: No AircraftList.json url specified, go to Options>Settings", Color.White); error = true; } if (Settings.radarUrl == "") { Core.UI.writeToConsole("ERROR: No radar url specified, go to Options>Settings", Color.White); error = true; } if (!Regex.IsMatch(Settings.acListUrl, @"(http|https):\/\/.+?\/VirtualRadar\/AircraftList\.json.*", RegexOptions.IgnoreCase)) { Core.UI.writeToConsole("ERROR: AircraftList.json url invalid. Example: http://127.0.0.1/VirtualRadar/AircraftList.json", Color.White); error = true; } if (error) { threadStatus = CheckerStatus.Stopped; Core.UI.statusLabel.Text = "Status: Idle"; return; } //Clear matches Core.activeMatches.Clear(); Core.waitingMatches.Clear(); //Start stats thread if stats thread is null if (Core.statsThread == null) { Core.statsThread = new Thread(Stats.updateStatsLoop); Core.statsThread.Name = "Stats Thread"; Core.statsThread.Start(); } //Start thread threadStatus = CheckerStatus.Running; Core.loopThread = new Thread(new ThreadStart(Checker.Start)); Core.loopThread.IsBackground = true; Core.loopThread.Name = "Checker Thread"; Core.loopThread.Start(); //If restart, log to UI if (restart) { Core.UI.writeToConsole("Checker Restarted", Color.White); Core.UI.reloadConditionsToolStripMenuItem.Enabled = true; } else { Core.UI.writeToConsole("Checker Started", Color.White); } }); startThread.Name = "Checker Starter Thread"; startThread.Start(); }