/// <summary> /// Create update proxy node if it hasn't already been created. /// </summary> private void CreateUpdaterNode() { if (updateProxyNode == null) { updateProxyNode = UpdateProxy.CreateUpdateWrapper(); } }
/// <summary> /// Create an update proxy with /// </summary> /// <returns>GameObject wrapper for the update proxy.</returns> public static GameObject CreateUpdateWrapper() { GameObject go = new GameObject("WorldLockingUpdater"); UpdateProxy updater = go.AddComponent <UpdateProxy>(); GameObject.DontDestroyOnLoad(go); return(go); }
public Dictionary <string, object> DoAction(Action <ProxyData> act) { ProxyData a = new ProxyData(); ProxyData b = UpdateProxy <ProxyData> .Create(); act(a); act(b); return(((IUpdateChange <ProxyData>)b).__GetChanges__(a)); }
//////////Methods////////// /// <summary> /// Create a new API's game, using the IPirateGame given /// </summary> public Game(IPirateGame game) { this.nativeObject = game; // each command "takes" at least one pirate this.MaxCommandsPerTurn = game.AllMyPirates().Count; this.currentTurn = new Turn(game); this.map = new Map(game); this.logger = new Logger(game); // creates the predictions this.attackPrediction = new AttackPredictionManager(this); this.movementPrediction = new MovementPredictionManager(this); // adds the appropriate objects to the update proxys this.updateProxy = new UpdateProxy <IPirateGame>(); this.updateProxy.Add(this.currentTurn); this.updateProxy.Add(this.map); this.updateProxy.Add(this.logger); this.myUpdateProxy = new UpdateProxy <Game>(); this.myUpdateProxy.Add(this.attackPrediction); this.myUpdateProxy.Add(this.movementPrediction); // initiates this game's constants this.MaxPoints = game.GetMaxPoints(); this.TurnsUntilSpawn = game.GetSpawnTurns(); this.TurnsUntilSober = game.GetSoberTurns(); this.TurnsUntilAttackReload = game.GetReloadTurns(); this.TurnsUntilDefenseReload = game.GetDefenseReloadTurns(); this.DefenseDuration = game.GetDefenseExpirationTurns(); this.ActionsPerTurn = game.GetActionsPerTurn(); this.MaxTurns = game.GetMaxTurns(); this.OpponentName = game.GetOpponentName(); }
public void UpdateProxyTest_Save_RabbitMqSource_Expectexception() { //------------Setup for test-------------------------- var comms = new Mock <ICommunicationControllerFactory>(); var env = new Mock <IEnvironmentConnection>(); env.Setup(a => a.WorkspaceID).Returns(Guid.NewGuid); var updateProxyTest = new UpdateProxy(comms.Object, env.Object); var controller = new Mock <ICommunicationController>(); comms.Setup(a => a.CreateController("SaveRabbitMQServiceSource")).Returns(controller.Object); controller.Setup(a => a.ExecuteCommand <IExecuteMessage>(env.Object, It.IsAny <Guid>())).Returns(new ExecuteMessage() { HasError = true, Message = new StringBuilder("bob") }); //------------Execute Test--------------------------- updateProxyTest.SaveRabbitMQServiceSource(new Mock <IRabbitMQServiceSourceDefinition>().Object, Guid.NewGuid()); //------------Assert Results------------------------- controller.Verify(a => a.ExecuteCommand <IExecuteMessage>(env.Object, It.IsAny <Guid>())); }
//////////Methods////////// /// <summary> /// Creates a new Pirate Manager, to manage the pirates of "owner" /// </summary> public PirateManager(IPirateGame game, Owner owner) { allPiratesProxy = new UpdateProxy <IPirateGame>(); // choose the list of all pirates to use List <Pirates.Pirate> allPirates; if (owner == Owner.Me) { allPirates = game.AllMyPirates(); } else { allPirates = game.AllEnemyPirates(); } // initialize the lists containing the pirates by states this.piratesByStates = new List <Pirate> [(int)PirateState.COUNT]; for (int i = 0; i < this.piratesByStates.Length; i++) { this.piratesByStates[i] = new List <Pirate>(); } // initialize the allPirates array this.allPirates = new Pirate[allPirates.Count]; // initialize all the pirates in the allPirates array, and add them to allPiratesProxy and freePirates foreach (Pirates.Pirate p in allPirates) { Pirate newPirate = new Pirate(p, game.GetActionsPerTurn()); this.allPirates[p.Id] = newPirate; this.piratesByStates[(int)PirateState.Free].Add(newPirate); this.allPiratesProxy.Add(newPirate); } this.Armada = this.GetAllPiratesCount() > 6; }
public SingleUpdateByProxy() { UpdateProxy = new UpdateProxy <TModel>(); }
//////////Methods////////// /// <summary> /// Creates a new map of the game /// </summary> public Map(IPirateGame game) { // updates map constants this.Rows = game.GetRows(); this.Collumns = game.GetCols(); this.AttackRadius = Utils.Sqrt(game.GetAttackRadius()); // set the computing limits this.IsBig = this.Rows > 40 || this.Collumns > 40; // create the pirate managers this.MyPirateManager = new PirateManager(game, Owner.Me); this.MyAttackMap = new AttackMap(this, this.MyPirateManager.GetAllPirates()); this.EnemyPirateManager = new PirateManager(game, Owner.Enemy); this.EnemyAttackMap = new AttackMap(this, this.EnemyPirateManager.GetAllPirates()); // create the sail manager this.SailManager = new SailManager(game, this); // create the update proxy this.updateProxy = new UpdateProxy <IPirateGame>(); this.updateProxy.Add(this.MyPirateManager); this.updateProxy.Add(this.EnemyPirateManager); this.updateProxy.Add(this.SailManager); // initialize the neighbors matrix this.neighbors = new List <Location> [this.Rows, this.Collumns, (2 * game.GetActionsPerTurn()) + 1]; // calculate the neighbors for each location in map for (int row = 0; row < this.Rows; row++) { for (int collumn = 0; collumn < this.Collumns; collumn++) { // assign neighbors of distance 0 ;) this.neighbors[row, collumn, 0] = new List <Location>(); this.neighbors[row, collumn, 0].Add(new Location(row, collumn)); // for each distance from 1 to max for (int distance = 1; distance < this.neighbors.GetLength(2); distance++) { this.neighbors[row, collumn, distance] = new List <Location>(); // add all the neighbors in a windmill-like shape for (int i = 0; i < distance; i++) { // all four quarters, were the row delta is i this.neighbors[row, collumn, distance].Add(new Location(row + i, collumn + (distance - i))); this.neighbors[row, collumn, distance].Add(new Location(row - i, collumn - (distance - i))); this.neighbors[row, collumn, distance].Add(new Location(row - (distance - i), collumn + i)); this.neighbors[row, collumn, distance].Add(new Location(row + (distance - i), collumn - i)); } // remove neighbors which are not in the map this.neighbors[row, collumn, distance].RemoveAll(loc => !this.InMap(loc)); } } } // the list of availible treasures List <Pirates.Treasure> allTreasures = game.Treasures(); // initialize the lists containing the treasures by states this.treasuresByStates = new List <Treasure> [(int)TreasureState.COUNT]; for (int i = 0; i < this.treasuresByStates.Length; i++) { this.treasuresByStates[i] = new List <Treasure>(); } // initialize the allTreasures array and the treasuresSpawnOnMap dictionary this.allTreasures = new Treasure[allTreasures.Count]; this.treasuresSpawnOnMap = new Dictionary <Location, Treasure>(); // initialize all the treasures in the allTreasures array, and add them to freeToTakeTreasures and to treasuresSpawnOnMap foreach (Pirates.Treasure t in allTreasures) { Treasure newTreasure = new Treasure(t); newTreasure.NativeObject = t; this.allTreasures[t.Id] = newTreasure; this.treasuresByStates[(int)TreasureState.FreeToTake].Add(newTreasure); this.treasuresSpawnOnMap.Add(newTreasure.InitialLocation, newTreasure); } // initialize the piratesSpawnOnMap dictionary this.piratesSpawnOnMap = new Dictionary <Location, Pirate>(); foreach (Pirate p in this.MyPirateManager.GetAllPirates()) { this.piratesSpawnOnMap.Add(p.InitialLocation, p); } foreach (Pirate p in this.EnemyPirateManager.GetAllPirates()) { this.piratesSpawnOnMap.Add(p.InitialLocation, p); } // initialize the map dictionaries, and update them this.piratesOnMap = new Dictionary <Location, Pirate>(); this.updatePiratesMapDictionary(); this.treasuresOnMap = new ListsDictionary <Location, Treasure>(); this.updateTreasuresMapDictionary(); // initialize the powerups list this.powerups = new List <Powerup>(); this.repopulatePowerups(game.Powerups(), game.GetTurn()); // initialize treasuresSpawnClusters this.treasuresSpawnClusers = Cluster.Clusterify <Treasure>(this.allTreasures, this.AttackRadius); // initialize the value being carried this.myCarriedValue = 0; this.enemyCarriedValue = 0; }