public CardGainAvailablility(Card card, int count, StartingLocation startingLocation) { if (card == null) { throw new Exception(); } this.card = card; this.count = count; this.startingLocation = startingLocation; }
public async Task GetNearestLocations_WithValidInput_AllNeighborsWithinDistance() { // Arrange var startingLocation = new StartingLocation { Latitude = 50.91414, Longitude = 5.95549 }; const int maxDistance = 100; const int maxResults = 2; var neighborsFromTree = new Tuple <double[], string>[] { new Tuple <double[], string>(new double[] { 50.91414, 5.95549 }, "Test1"), new Tuple <double[], string>(new double[] { 50.9147729, 5.9555408 }, "Test2") }; A.CallTo(() => _locationsKdTree.GetNearestRadialNeighbors(startingLocation.Latitude, startingLocation.Longitude, maxDistance)).Returns(neighborsFromTree); // Act var actualNearestNeighbors = await _nearestLocationsFinderService.GetNearestLocations(startingLocation, maxDistance, maxResults); // Assert var locationWithDistanceFromStartingPoints = actualNearestNeighbors.ToList(); locationWithDistanceFromStartingPoints.Count().Should().BeLessOrEqualTo(maxResults); var firstNeighbor = locationWithDistanceFromStartingPoints.First(); firstNeighbor.Address.Should().Be("Test1"); firstNeighbor.DistanceFromStartingPoint.Should().Be(0); var secondNeighbor = locationWithDistanceFromStartingPoints[1]; secondNeighbor.Address.Should().Be("Test2"); secondNeighbor.DistanceFromStartingPoint.Should().BeInRange(0, maxDistance); }
public async Task GetNearestLocations_WithInvalidMaxDistance_ShouldThrowArgumentOutOfRangeException(int maxDistance) { // Arrange var startingLocation = new StartingLocation { Latitude = 0.1, Longitude = 0.2 }; // Act Func <Task> act = async() => { await _nearestLocationsFinderService.GetNearestLocations(startingLocation, maxDistance, 1); }; // Assert await act.Should().ThrowAsync <ArgumentOutOfRangeException>(); }
public CharacterCityListPacket(PacketReader reader) : base(0xA9, "Char/City List") { var characterCount = reader.ReadByte(); _characters = new CharacterListEntry[characterCount]; for (var i = 0; i < characterCount; i++) { _characters[i] = new CharacterListEntry(reader); } var locationCount = reader.ReadByte(); _locations = new StartingLocation[locationCount]; for (var i = 0; i < locationCount; i++) { _locations[i] = new StartingLocation(reader); } }
public CharacterCityListPacket(PacketReader reader) : base(0xA9, "Char/City List") { int characterCount = reader.ReadByte(); m_characters = new CharacterListEntry[characterCount]; for (int i = 0; i < characterCount; i++) { m_characters[i] = new CharacterListEntry(reader); } int locationCount = reader.ReadByte(); m_locations = new StartingLocation[locationCount]; for (int i = 0; i < locationCount; i++) { m_locations[i] = new StartingLocation(reader); } }
// Use this for initialization IEnumerator Start() { switch (simulationMode) { case SimulationMode.A: yield return(LoadGalaxyMapRoutine("GalaxyMapA")); break; case SimulationMode.B: yield return(LoadGalaxyMapRoutine("GalaxyMapB")); break; case SimulationMode.C: yield return(LoadGalaxyMapRoutine("GalaxyMapC")); break; } GalaxyMapNode defaultNode = GalaxyMapVisual.GetDefaultNode(); if (defaultNode == null) { defaultNode = FindObjectOfType <GalaxyMapNode>(); } yield return(LoadSolarSystemSceneRoutine(defaultNode.name)); ship = Instantiate(shipPrefab, transform).GetComponent <Ship>(); ship.Setup(this); StartingLocation startingLocation = FindObjectOfType <StartingLocation>(); externalCamera = Instantiate(externalCameraPrefab, transform).GetComponent <ExternalCamera>(); externalCamera.Setup(ship.transform); DynamicObjectsRoot = new GameObject("DynamicObjectsRoots").transform; DynamicObjectsRoot.SetParent(transform); }
public CardGainAvailablility(Card card, int count, StartingLocation startingLocation) { this.card = card; this.count = count; this.startingLocation = startingLocation; }
/// <summary> /// Find the K nearest neighbors. /// O(K logN) /// </summary> /// <param name="startingLocation"></param> /// <param name="maxDistance"></param> /// <param name="maxResults"></param> /// <returns></returns> public async Task <IEnumerable <LocationWithDistanceFromStartingPoint> > GetNearestLocations(StartingLocation startingLocation, int maxDistance, int maxResults) { EnsureArg.IsNotNull(startingLocation, nameof(startingLocation)); EnsureArg.IsGte(maxDistance, 0, nameof(maxDistance)); EnsureArg.IsGt(maxResults, 0, nameof(maxResults)); var startLoc = new Location(startingLocation.Latitude, startingLocation.Longitude); var nearestNeighbors = _locationsKdTree.GetNearestRadialNeighbors( startingLocation.Latitude, startingLocation.Longitude, maxDistance); var res = nearestNeighbors .Select(t => { var loc = new Location(t.Item2, t.Item1[0], t.Item1[1]); return(new LocationWithDistanceFromStartingPoint(loc, loc.CalculateDistance(startLoc))); }) .Where(l => l.DistanceFromStartingPoint <= maxDistance) .OrderBy(l => l.DistanceFromStartingPoint) .Take(maxResults) .ToList(); return(await Task.FromResult(res)); }
public async Task <IEnumerable <LocationWithDistanceFromStartingPoint> > GetNearestLocations(StartingLocation startingLocation, int maxDistance, int maxResults) { EnsureArg.IsNotNull(startingLocation, nameof(startingLocation)); EnsureArg.IsGte(maxDistance, 0, nameof(maxDistance)); EnsureArg.IsGt(maxResults, 0, nameof(maxResults)); // In the case of an actual database with lots of records, we can use caching to save time when // fetching al the records. var allLocations = await _locationsRepository.GetAllAsync(); var startLoc = new Location(startingLocation.Latitude, startingLocation.Longitude); // Time complexity depends on the size of M. Worst case if M is big then TC=O(M log M), else Omega(N) var res = allLocations .Select(l => new LocationWithDistanceFromStartingPoint(l, l.CalculateDistance(startLoc))) // Select: O(N) .Where(l => l.DistanceFromStartingPoint <= maxDistance) // Where: O(N) .OrderBy(l => l.DistanceFromStartingPoint) //O(M log M) .Take(maxResults); // Take: O(M) return(res); }
public static void SetStartingLocations(StartingLocation[] list) { _locations = list; _updateValue++; }
public CardGainAvailablility(Card card, int count, StartingLocation startingLocation) { this.card = card; this.count = count; this.startingLocation = startingLocation; }
public AiControlledAircraftScript SpawnSandboxAiFromXml(string aircraftId, string aircraftXml, bool autoDespawn, bool forceSpawnEvenIfUnflyable, StartingLocation location, AiCsSandboxAirTraffic.AiModeType?aiMode) { var aggressive = aiMode == AiCsSandboxAirTraffic.AiModeType.Aggressive; var mode = aggressive ? null : Enum.ToObject(AiCsSandboxAirTraffic.AiMode.RealType, (int)(aiMode ?? AiCsSandboxAirTraffic.AiModeType.Default)); return(AiControlledAircraftScript.Wrap(_spawnSandboxAiFromXml.Invoke(this.RealObject, new object[] { aircraftId, aircraftXml, autoDespawn, forceSpawnEvenIfUnflyable, location.RealObject, mode, aggressive }))); }
protected Card( string name, Expansion expansion, int coinCost = 0, int potionCost = 0, int debtCost = 0, Edition edition = Edition.First, bool isDeprecated = false, string pluralName = null, StartingLocation startingLocation = Dominion.StartingLocation.Supply, int plusActions = 0, int plusBuy = 0, int plusCards = 0, int plusCoins = 0, VictoryPointCounter victoryPoints = null, int plusVictoryToken = 0, int defaultSupplyCount = 10, bool isAction = false, bool isAttack = false, bool attackDependsOnPlayerChoice = false, bool isAttackBeforeAction = false, bool isCurse = false, bool isReaction = false, bool isNight = false, bool isPrize = false, bool isRuins = false, bool isTreasure = false, bool isDuration = false, bool isLooter = false, bool requiresSpoils = false, bool isShelter = false, bool isTraveller = false, bool isReserve = false, bool isGathering = false, bool isHeirloom = false, bool isFate = false, bool isDoom = false, bool isZombie = false, bool isSpirit = false, bool isCastle = false, bool canOverpay = false, bool canGivePlusAction = false, bool mightMultiplyActions = false, bool isKingdomCard = true, CardIntValue provideDiscountForWhileInPlay = null, GameStateMethod doSpecializedCleanupAtStartOfCleanup = null, GameStateCardMethod doSpecializedActionOnBuyWhileInPlay = null, GameStateCardPredicate doSpecializedActionOnTrashWhileInHand = null, GameStateCardToPlacement doSpecializedActionOnGainWhileInPlay = null, GameStateCardToPlacement doSpecializedActionOnBuyWhileInHand = null, GameStateCardToPlacement doSpecializedActionOnGainWhileInHand = null, GameStateCardMethod doSpecializedActionToCardWhileInPlay = null) : base(name, expansion, edition, isDeprecated, pluralName) { this.coinCost = coinCost; this.potionCost = potionCost; this.debtCost = debtCost; this.plusAction = plusActions; this.plusBuy = plusBuy; this.plusCard = plusCards; this.plusCoin = plusCoins; this.victoryPointCounter = victoryPoints; this.plusVictoryToken = plusVictoryToken; this.isAction = isAction; this.isAttack = isAttack; this.attackDependsOnPlayerChoice = attackDependsOnPlayerChoice; this.isAttackBeforeAction = isAttackBeforeAction; this.isCurse = isCurse; this.isReaction = isReaction; this.isNight = isNight; this.isPrize = isPrize; this.isRuins = isRuins; this.isTreasure = isTreasure; this.isFate = isFate; this.isDoom = isDoom; this.isHeirloom = isHeirloom; this.isSpirit = isSpirit; this.isZombie = isZombie; this.isCastle = isCastle; this.isLooter = isLooter; this.defaultSupplyCount = defaultSupplyCount; this.isLooter = isLooter; this.isDuration = isDuration; this.isShelter = isShelter; this.isTraveller = isTraveller; this.isReserve = isReserve; this.isGathering = isGathering; this.isKingdomCard = isKingdomCard; this.requiresSpoils = requiresSpoils; this.canOverpay = canOverpay; this.canGivePlusAction = canGivePlusAction; this.mightMultiplyActions = mightMultiplyActions; this.provideDiscountForWhileInPlay = provideDiscountForWhileInPlay; this.doSpecializedCleanupAtStartOfCleanup = doSpecializedCleanupAtStartOfCleanup; this.doSpecializedActionOnBuyWhileInPlay = doSpecializedActionOnBuyWhileInPlay; this.doSpecializedActionOnTrashWhileInHand = doSpecializedActionOnTrashWhileInHand; this.doSpecializedActionOnGainWhileInPlay = doSpecializedActionOnGainWhileInPlay; this.doSpecializedActionOnBuyWhileInHand = doSpecializedActionOnBuyWhileInHand; this.doSpecializedActionOnGainWhileInHand = doSpecializedActionOnGainWhileInHand; this.doSpecializedActionToCardWhileInPlay = doSpecializedActionToCardWhileInPlay; }