public Processor(RealMemory realMemory, ChannelTool channelTool, VirtualMemory virtualMemory = null, Pager pager = null) { RealMemory = realMemory; VirtualMemory = virtualMemory; ChannelTool = channelTool; Pager = pager; FileManager = new FileManager(RealMemory, this); CommandInterpretator = new CommandInterpretator(this, virtualMemory); Interruptor = new Interruptor(this, virtualMemory, FileManager, RealMemory); // STOPS PROGRAM AFTER MAX STEP COUNT UseMaxStep = true; // CURRENT STEP CurrentStep = 0; registers = new Dictionary <string, Register> { { "R1", new Register(value: 0) }, // Word length general register { "R2", new Register(value: 0) }, // Word length general register { "IC", new HexRegister(2) }, // Current command adress in memory register { "PTR", new HexRegister(4) }, // Page table adress register { "SF", new StatusFlagRegister() }, // Aritmetic operation logic values { "MODE", new ChoiceRegister('N', 'S') }, // Processor mode "N" - user, "S" - supervisor { "PI", new ChoiceRegister(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) }, // Program interuptor { "SI", new ChoiceRegister(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) }, // Supervisor interuptor { "TI", new HexRegister(Utility.TIMER_VALUE, 1) } // Timer interuptor }; }
public void SetVirtualMemory(VirtualMemory virtualMemory, Pager pager) { VirtualMemory = virtualMemory; Pager = pager; SetPTRRegisterValue(pager.GetPTR()); CommandInterpretator.SetVirtualMemory(virtualMemory); Interruptor.SetVirtualMemory(virtualMemory); }
public void Clear() { SearchKillers = new int[MaxDepth, 2]; SearchHistory = new int[13, 64]; FailHigh = 0; FailHighFirst = 0; NullMoveCutOffs = 0; NodesSearched = 0; Stopped = false; Interruptor.Start(); }
private bool Interrupt() { SetSupervisorMode(); if (Interruptor.Interrupt()) { SetUserMode(); return(true); } else { return(false); } }
public void onClick(Interruptor btn, int player, bool value) { if (player == 1) { dicBtnsP1[btn] = value; } else if (player == 2) { dicBtnsP2[btn] = value; } else { Debug.Log("Error"); } }
public void Explode() { Debug.Log("Booom"); // Show Effects //Instantiate(explosionEffect, transform.position, transform.rotation); GameObject EMPExplosion = Instantiate(explosionEffect, transform.position, transform.rotation); //Debug.Log(source + "AAAAAAAAAAAAAAAAAAAAA"); //Common.common.ChangePitchAndVolume(source); source.ChangePitchAndVolume(0.7f, 1, 0.95f, 1.05f); source.PlayOneShot(explosionClip); Destroy(EMPExplosion, 10); //Get Objects Collider[] colliders = Physics.OverlapSphere(transform.position, radius, layer); foreach (Collider nearbyObject in colliders) { if (nearbyObject.tag == "Enemy") { nearbyObject.transform.SendMessage("StunnedSet", empTime, SendMessageOptions.RequireReceiver); Debug.Log("Enemy"); } else if (nearbyObject.tag == "Interruptor") { Interruptor interruptor = nearbyObject.GetComponentInParent <Interruptor>(); if (interruptor != null) { interruptor.DoInteraction(); } } } //Damage enemies //Remove Granade coll.enabled = false; rb.detectCollisions = false; mesh.enabled = false; Destroy(gameObject, 5); }
void OnEnable() { _interruptor = target as Interruptor; BehaviourTree bt = _interruptor.Tree; var editorWindows = Resources.FindObjectsOfTypeAll <BonsaiWindow>(); // Find the the editor window with the tree associated with this behaviour. foreach (BonsaiWindow win in editorWindows) { // Found the tree, cache this window. if (win.tree == bt) { parentWindow = win; break; } } }
public OrdersElement(string type, Interruptor btn, int expectedValue) { this.type = type; this.btn = btn; this.exValue = expectedValue; }
public int Quiessence(int alpha, int beta, Board board, int currentDepth) { #if TEST Test.Assert(beta > alpha); board.CheckBoard(); #endif if ((NodesSearched & 2047) == 0) { if (Interruptor.IsInterrupted()) { Stopped = true; return(0); } } NodesSearched++; var isRepetition = IsRepetition(board); if (isRepetition) { return(0); } if (board.History.Length - board.LastTookPieceHistoryIndex >= 100) { return(0); } if (currentDepth >= MaxDepth) { return(EvaluationService.Evaluate(board)); } int score = EvaluationService.Evaluate(board); if (score >= beta) { return(beta); } if (score > alpha) { alpha = score; } var potentialMoves = PossibleMovesService.GetAllPotentialMoves(board).Where(x => x.TakesPiece > 0).ToList(); var oldAlpha = alpha; var validMoves = 0; Move?bestMove = null; var bestScore = -Inf; score = -Inf; for (var i = 0; i < potentialMoves.Count; i++) { SortNextMove(i, board, potentialMoves, currentDepth, null); var potentialMove = potentialMoves[i]; var bbAfter = PossibleMovesService.DoMoveIfKingSafe(board, potentialMove); if (bbAfter == null) { continue; } validMoves++; score = -Quiessence(-beta, -alpha, bbAfter, currentDepth + 1); if (Stopped) { return(0); } if (score > alpha) { if (score >= beta) { #if TEST if (validMoves == 1) { FailHighFirst++; } FailHigh++; #endif return(beta); } alpha = score; } } #if TEST Test.Assert(alpha >= oldAlpha); Test.Assert(alpha < Inf); Test.Assert(alpha > -Inf); #endif return(alpha); }
public int PrincipalVariationSearch(int alpha, int beta, Board board, int depth, int currentDepth, bool allowNullMoveSearch) { #if TEST Test.Assert(beta > alpha); Test.Assert(depth >= 0); board.CheckBoard(); #endif if ((NodesSearched & 2047) == 0) { if (Interruptor.IsInterrupted()) { Stopped = true; return(0); } } NodesSearched++; var isRepetition = IsRepetition(board); if (isRepetition && currentDepth > 0) { return(0); } if (board.History.Length - board.LastTookPieceHistoryIndex >= 100) { return(0); } if (currentDepth >= MaxDepth) { return(EvaluationService.Evaluate(board)); } if (depth <= 0) { // quiessence next return(Quiessence(alpha, beta, board, currentDepth)); } var enemyAttacks = PossibleMovesService.AttacksService.GetAllAttacked(board, !board.WhiteToMove); var myKing = board.WhiteToMove ? board.BitBoard[ChessPiece.WhiteKing] : board.BitBoard[ChessPiece.BlackKing]; var inCheck = (enemyAttacks & myKing) != 0; if (inCheck) { depth++; } int score = -Inf; Move?pvMove = null; SearchTTEntry foundEntry; var found = TTable.TryGet(board.Key, out foundEntry); if (found && foundEntry.Key == board.Key) { pvMove = foundEntry.Move; if (foundEntry.Depth >= depth) { switch (foundEntry.Flag) { case SearchTTFlags.Beta: return(beta); break; case SearchTTFlags.Exact: return(foundEntry.Score); break; case SearchTTFlags.Alpha: return(alpha); break; } } } const int nullMoveFactor = 2; if (allowNullMoveSearch && !inCheck && currentDepth > 0 && depth >= nullMoveFactor + 1) { var haveBigPiece = false; var pieceOffset = board.WhiteToMove ? 1 : 7; for (var i = 1; i < 5; i++) { if (board.PieceCounts[pieceOffset + i] > 0) { haveBigPiece = true; break; } } if (haveBigPiece) { var nullMove = new Move(0, 0, 0); var nullBoard = board.DoMove(nullMove); score = -PrincipalVariationSearch(-beta, -beta + 1, nullBoard, depth - nullMoveFactor - 1, currentDepth + 1, false); if (Stopped) { return(0); } if (score >= beta && score > -MateThereshold && score < MateThereshold) { NullMoveCutOffs++; return(beta); } } } var potentialMoves = PossibleMovesService.GetAllPotentialMoves(board); var oldAlpha = alpha; var validMoves = 0; Move?bestMove = null; var bestScore = -Inf; score = -Inf; var bbsAfter = new Board[potentialMoves.Count]; for (var i = 0; i < potentialMoves.Count; i++) { SortNextMove(i, board, potentialMoves, currentDepth, pvMove); var potentialMove = potentialMoves[i]; var bbAfter = PossibleMovesService.DoMoveIfKingSafe(board, potentialMove); if (bbAfter == null) { continue; } bbsAfter[i] = bbAfter; validMoves++; score = -PrincipalVariationSearch(-beta, -alpha, bbAfter, depth - 1, currentDepth + 1, true); if (Stopped) { return(0); } if (score > bestScore) { bestScore = score; bestMove = potentialMove; if (score > alpha) { if (score >= beta) { #if TEST if (validMoves == 1) { FailHighFirst++; } FailHigh++; #endif if (potentialMove.TakesPiece == 0) { SearchKillers[currentDepth, 1] = SearchKillers[currentDepth, 0]; SearchKillers[currentDepth, 0] = potentialMove.Key; } var entry = new SearchTTEntry(board.Key, bestMove.Value, beta, SearchTTFlags.Beta, depth); TTable.Add(board.Key, entry); return(beta); } alpha = score; if (potentialMove.TakesPiece == 0) { SearchHistory[potentialMove.Piece, potentialMove.To] += depth; } } } } if (validMoves == 0) { if (inCheck) { return(-MateScore + currentDepth); } else { return(0); } } #if TEST Test.Assert(alpha >= oldAlpha); #endif if (alpha != oldAlpha) { var entry = new SearchTTEntry(board.Key, bestMove.Value, bestScore, SearchTTFlags.Exact, depth); TTable.Add(board.Key, entry); //PVTable[currentDepth] = new PVSResult(alpha, bbsAfter[bestMove], potentialMoves[bestMove]); } else { var entry = new SearchTTEntry(board.Key, bestMove.Value, alpha, SearchTTFlags.Alpha, depth); TTable.Add(board.Key, entry); } return(alpha); }