/// <summary> /// R03 /// all the visible moves the opponent has done are given in consecutive order. /// </summary> /// <param name="parts"></param> public void OpponentMoves(String[] parts) { List <PlaceArmies> opponentPlaceArmies = new List <PlaceArmies>(); List <AttackTransfer> opponentAttackTransfer = new List <AttackTransfer>(); for (int i = 1; i < parts.Length; i++) { PlayerType playerUpdate = Player.PlayerId(parts[i]); String command = parts[++i]; if (command == "place_armies") { Region region = Map.Current.Regions.GetId(parts[++i]); int armies = int.Parse(parts[++i]); opponentPlaceArmies.Add(new PlaceArmies(armies, region)); } else if (command == "attack/transfer") { Region regionSource = Map.Current.Regions.GetId(parts[++i]); Region regionTarget = Map.Current.Regions.GetId(parts[++i]); int armies = int.Parse(parts[++i]); opponentAttackTransfer.Add(new AttackTransfer(armies, regionSource, regionTarget)); } } // Save moves for further use Map.MapState.OpponentLastPlaceArmies = opponentPlaceArmies; Map.MapState.OpponentLastAttackTransfer = opponentAttackTransfer; // Update values StateCalculator.CalculateState(); // DEBUG Map.Current.SuperRegions.ForEach(SR => AnalyseSuperRegion.TestSuperRegion(SR)); Console.ReadLine(); }
public void StateInfoChanged() { string connectionString = Configuration.ConnectionBuilders(AccountType.Gross, Configuration.ConnectionType.Feed).First().ToString(); this.dataFeed = new DataFeed(connectionString); this.dataFeed.Logon += this.OnFeedLogon; connectionString = Configuration.ConnectionBuilders(AccountType.Gross, Configuration.ConnectionType.Trade).First().ToString(); this.dataTrade = new DataTrade(connectionString); this.dataTrade.Logon += this.OnTradeLogon; StateCalculator stateCalculator = new StateCalculator(dataTrade, dataFeed); stateCalculator.StateInfoChanged += StateCalculator_StateInfoChanged; this.dataFeed.Start(); this.dataTrade.Start(); var status = this.feedLogonEvent.WaitOne(LogonWaitingTimeout); Assert.IsTrue(status, "Timeout of feed logon event"); status = this.tradeLogonEvent.WaitOne(LogonWaitingTimeout); Assert.IsTrue(status, "Timeout of trade logon event"); status = this.stateInfoEvent.WaitOne(LogonWaitingTimeout * 10000); this.dataFeed.Stop(); this.dataTrade.Stop(); this.dataFeed.Logon -= this.OnFeedLogon; this.dataTrade.Logon -= this.OnTradeLogon; }
public StatsCalculator(Stats stats) { this.stats = stats; stateCalculator = new StateCalculator(stats); offensiveCalculator = new OffensiveCalculator(stats); defensiveCalculator = new DefensiveCalculator(stats); }
public void CellIsBorn() { IStateCalculator stateCalculator = new StateCalculator(); const bool currentState = false; const int neighborsNumber = 3; var newState = stateCalculator.NextState(currentState, neighborsNumber); Assert.AreEqual(IsAlive, newState); }
public State GetBeehiveState(int beehiveId) { const int countOfValues = 5; var averageStatistic = _statisticService.GetAverageStatistic(beehiveId, countOfValues); var beehive = _unitOfWork.Beehives.Get(beehiveId); if (beehive != null) { var stateCalculator = new StateCalculator(); return(stateCalculator.GetState(averageStatistic, beehive)); } return(null); }
public void CellNotBorn() { IStateCalculator stateCalculator = new StateCalculator(); const bool currentState = IsDead; int[] neighborsNumbers = { 0, 1, 2, 4, 5, 6, 7, 8 }; bool[] expectedResult = { IsDead, IsDead, IsDead, IsDead, IsDead, IsDead, IsDead, IsDead }; bool[] actualResult = new bool[8]; for (var i = 0; i < neighborsNumbers.Length; i++) { actualResult[i] = stateCalculator.NextState(currentState, neighborsNumbers[i]); } Assert.AreEqual(expectedResult, actualResult); }
public void CellStayAlive() { IStateCalculator stateCalculator = new StateCalculator(); const bool currentState = IsAlive; int[] neighborsNumbers = { 2, 3 }; bool[] expectedResult = { IsAlive, IsAlive }; bool[] actualResult = new bool[2]; for (var i = 0; i < neighborsNumbers.Length; i++) { actualResult[i] = stateCalculator.NextState(currentState, neighborsNumbers[i]); } Assert.AreEqual(expectedResult, actualResult); }
public void WhenTheInputSourceIsCompiledWithTheBerpGrammarParserForTestParser() { ParseWithErrorHandling(parser => { ruleSet = parser.Parse(new TokenScanner(new StringReader(sourceContent))); testOutputHelper.WriteLine(ruleSet.ToString()); var states = StateCalculator.CalculateStates(ruleSet); testOutputHelper.WriteLine("{0} states calculated for the parser.", states.Count); foreach (var state in states.Values) { PrintStateTransitions(state); PrintStateBranches(state.Branches, state.Id); } }); }
public void WhenTheParserGenerationIsPerformedUsing(string templateName) { var parser = new BerpGrammar.Parser(); var ruleSet = parser.Parse(new TokenScanner(new StringReader(grammarDefinition))); var states = StateCalculator.CalculateStates(ruleSet); try { var generator = new Generator(ruleSet.Settings); outputFile = TestFolders.GetTempFilePath("output.txt"); generator.Generate(Path.Combine("GeneratorTemplates", templateName), ruleSet, states, outputFile); } catch (Exception ex) { generationError = ex; } }
internal Snapshot(DataTrade trade, DataFeed feed, StateCalculator calculator, object synchronizer, AutoResetEvent syncEvent) { this.synchronizer = synchronizer; this.syncEvent = syncEvent; this.calculator = calculator; this.Quotes = new Dictionary <string, Quote>(); trade.Logon += this.OnTradeLogon; trade.SessionInfo += this.OnTradeSession; trade.AccountInfo += this.OnAccountInfo; trade.Logout += this.OnTradeLogout; feed.Logon += this.OnFeedLogon; feed.Logout += this.OnFeedLogout; feed.SymbolInfo += this.OnFeedSymbolInfo; feed.SessionInfo += this.OnFeedSessionInfo; calculator.StateInfoChanged += this.OnFinancialInfoChanged; }
void DoRun() { this.Trade.Initialize(this.dataTradeBuilder.ToString()); this.Feed.Initialize(this.dataFeedBuilder.ToString()); this.Calculator = new StateCalculator(this.Trade, this.Feed); this.Trade.Start(); this.Feed.Start(); if (!dataTradeEvent.WaitOne(this.Trade.SynchOperationTimeout)) { throw new TimeoutException("Timeout of data trade logon waiting has been reached"); } if (!dataFeedEvent.WaitOne(this.Trade.SynchOperationTimeout)) { throw new TimeoutException("Timeout of data feed logon waiting has been reached"); } this.RunExample(); }