public AreaCheck(ActorFilterDelegate actorAreaFunc, ActorProcess actorProcess, List <PoolObjHandle <ActorRoot> > checkList) { this._actorAreaFunc = actorAreaFunc; this._actorProcess = actorProcess; this._waitCheckRef = checkList; this._aroundRecords = new DictionaryView <uint, AroundRecord>(); }
/// <summary> /// Handles a meow and signal it to other processes /// </summary> /// <param name="meowRequest"></param> /// <param name="sender"></param> private void HandleMeow(MeowRequest meowRequest, ActorProcess sender) { logger.LogMeow(sender.Rank, sender.Position); Broadcast(new MeowSignal { MeowLocation = sender.Position }); }
/// <summary> /// Handles a move request by a player and signal it to the other processes /// </summary> /// <param name="moveRequest"></param> /// <param name="sender"></param> private void HandleMovePlayer(MoveRequest moveRequest, ActorProcess sender) { // Pessimistically assume the move is going to be denied MoveSignal moveSignal = new MoveSignal { InitialTile = sender.Position, FinalTile = sender.Position }; // Try to move and update the final position MoveEffect effect = map.CheckForMoveEffects(sender.Position, moveRequest.DesiredTile); if (effect != MoveEffect.InvalidMove) { logger.LogMove(sender.Rank, true, sender.Position, moveRequest.DesiredTile); switch (effect) { case MoveEffect.RatCaptured: ActorProcess rat = GetActorProcessByCoordinates(moveRequest.DesiredTile); logger.LogCaptureRat(rat.Rank, sender.Rank); HandleRatRemoval(rat); break; case MoveEffect.RatEscaped: logger.LogExitRat(sender.Rank, moveRequest.DesiredTile); HandleRatRemoval(GetActorProcessByCoordinates(sender.Position)); break; case MoveEffect.CheeseEaten: logger.LogCheeseConsumption(sender.Rank, moveRequest.DesiredTile); break; } // Move is valid and the destination tile no longer has important information map.ApplyMove(sender.Position, moveRequest.DesiredTile); sender.Position = moveRequest.DesiredTile; moveSignal.FinalTile = moveRequest.DesiredTile; } else { logger.LogMove(sender.Rank, false, sender.Position, moveRequest.DesiredTile); } moveCount++; if (moveCount % MAP_LOG_INTERVAL == 0) { logger.LogMap(map.ToString()); } if (IsGameOver()) { EndGame(); } else { // Broadcast the result of the move Broadcast(moveSignal); } }
/// <summary> /// Handles a death /// </summary> /// <param name="deathConfirmation"></param> /// <param name="sender"></param> private void HandleDeath(DeathConfirmation deathConfirmation, ActorProcess sender) { GetActorProcessByRank(deathConfirmation.Rank).IsDeadProcess = true; if (AreAllActorsFinished()) { // Stop the MapManager reception of messages if all actor's processes are dead ContinueExecution = false; } }
/// <summary> /// Remove rat from playing actors and signal him that he died. /// </summary> /// <param name="rat"></param> private void HandleRatRemoval(ActorProcess rat) { // The cat cannot play anymore rat.Playing = false; lock (comm) { // Notify the rat that he should stop comm.Send(new KillSignal(), rat.Rank, 0); } }
/// <summary> /// Handle a request message /// </summary> /// <param name="request"></param> private void HandleRequest(Communication.Request request) { ActorProcess sender = GetActorProcessByRank(request.Rank); // Death confirmation DeathConfirmation deathConfirmation = request as DeathConfirmation; if (deathConfirmation != null) { HandleDeath(deathConfirmation, sender); return; } // Validate that the process is still in the game (playing). // This is meant to deny requests that were sent in between the moment the actor was removed from the game and the moment the actor learned about it. if (!sender.Playing) { return; // Ignore the request, the process is no longer playing } // Move request MoveRequest moveRequest = request as MoveRequest; if (moveRequest != null) { HandleMovePlayer(moveRequest, sender); return; } // Meow request MeowRequest meowRequest = request as MeowRequest; if (meowRequest != null) { HandleMeow(meowRequest, sender); return; } }