public void DynamicMapNullAssignmentFiresAddAndDelete() { var three = new MyIntItem(3); var four = new MyIntItem(4); DynamicMap <MyIntItem> dm = new DynamicMap <MyIntItem> { { "fromnull", null }, { "tonull", three } }; DynamicMap <MyIntItem> dm2 = new DynamicMap <MyIntItem> { { "fromnull", four }, { "tonull", null } }; bool added = false; dm.ItemAdded += (sender, args) => { Assert.False(added); added = true; Assert.Equal("fromnull", args.Key); Assert.Same(four, args.NewItem); }; dm.ItemUpdated += (sender, args) => Assert.False(true); bool deleted = false; dm.ItemDeleted += (sender, args) => { Assert.False(deleted); deleted = true; Assert.Equal("tonull", args.Key); Assert.Same(three, args.OldItem); }; dm.Assign(dm2); Assert.True(added); Assert.True(deleted); }
public void DynamicMapHoldsValues() { { DynamicMap <SingleValue <int> > dm = new DynamicMap <SingleValue <int> > { { "a", 3 }, { "b", 4 } }; Assert.Equal((SingleValue <int>) 3, dm["a"]); Assert.Equal((SingleValue <int>) 4, dm["b"]); } { DynamicMap <SingleItem <string> > dm = new DynamicMap <SingleItem <string> > { { "a", "foo" }, { "b", "bar" } }; Assert.Equal((SingleItem <string>) "foo", dm["a"]); Assert.Equal((SingleItem <string>) "bar", dm["b"]); } { MyComposite sm = new MyComposite { si = 42, ss1 = "foo", ss2 = null, nested = new MyComposite.MyNested { x = 10, y = 20, s = "bar" }, ci = null }; DynamicMap <ConfigItem> dm = new DynamicMap <ConfigItem> { { "name", (SingleItem <string>) "foo" }, { "number", (SingleValue <int>) 42 }, { "smap", sm } }; Assert.Equal("foo", (SingleItem <string>)dm["name"]); Assert.Equal <int>(42, (SingleValue <int>)dm["number"]); Assert.Same(sm, dm["smap"]); Assert.Throws <System.Collections.Generic.KeyNotFoundException>(() => dm["ThisKeyShouldNotExist"]); } }
public void Test__VeryComplex() { // Arrange var objs = new List <Dictionary <string, object> > { new Dictionary <string, object> { { "prop", new Dictionary <string, object> { { "nestedProp1", _fixture.Create <string>() }, { "nestedProp", _fixture.Create <string>() } } } }, new Dictionary <string, object> { { "prop", new Dictionary <string, object> { { "nestedProp2", _fixture.Create <string>() }, { "nestedProp", _fixture.Create <string>() } } } } }; var expected = new Dictionary <string, object> { { "prop", objs.First()["prop"] } }; // Act var result = DynamicMap.Merge <Dictionary <string, object> >(objs); // Assert Xunit.Assert.Equal(expected, result); }
public void DynamicMapAssignmentChangesValue() { MyComposite sm1 = new MyComposite { si = 42, ss1 = "foo", ss2 = null, nested = new MyComposite.MyNested { x = 10, y = 20, s = "bar" }, ci = null }; MyComposite sm2 = new MyComposite { si = 43, ss1 = "foo", ss2 = null, nested = new MyComposite.MyNested { x = 10, y = 20, s = "bar" }, ci = null }; DynamicMap <ConfigItem> dm = new DynamicMap <ConfigItem> { { "name", (SingleItem <string>) "foo" }, { "number", (SingleValue <int>) 42 }, { "smap", sm1 } }; DynamicMap <ConfigItem> dm2 = new DynamicMap <ConfigItem> { { "name", (SingleItem <string>) "bar" }, { "number", (SingleValue <int>) 40 }, { "smap", sm2 } }; dm.Assign(dm2); Assert.Equal("bar", (SingleItem <string>)dm["name"]); Assert.Equal <int>(40, (SingleValue <int>)dm["number"]); Assert.Equal <int>(43, ((MyComposite)dm["smap"]).si); Assert.Same(sm1, dm["smap"]); }
public void Test__Basic() { // Arrange var expected = _fixture.Create <ComplexModelSource>(); var childObj = new ExpandoObject(); var childObjDictionary = (IDictionary <string, object>)childObj; childObjDictionary["Name"] = expected.ParentInfo.Name; childObjDictionary["Age"] = expected.ParentInfo.Age; childObjDictionary["DateOfBith"] = expected.ParentInfo.DateOfBith; var rootObj = new ExpandoObject(); var rootObjDictionary = (IDictionary <string, object>)rootObj; rootObjDictionary["Name"] = expected.Name; rootObjDictionary["Age"] = expected.Age; rootObjDictionary["DateOfBith"] = expected.DateOfBith; rootObjDictionary["ParentInfo"] = expected.ParentInfo; // Act var result = DynamicMap.Map(typeof(ComplexModelDestination), rootObj); // Assert Assert(expected, result, new ComplexModelComparer()); }
void Start() { map = DynamicMap.instance; DynamicMap.instance.Reset(); map.AddSegment(); map.AddSegment(); map.AddSegment(); LastPos = new Vector2Int(Mathf.RoundToInt(transform.GetChild(0).position.x / map.TileSize), Mathf.RoundToInt(transform.GetChild(0).position.z / map.TileSize)); }
public void Test__Basic() { // Arrange var obj = _fixture.Create <List <string> >(); // Act var result = DynamicMap.Map(typeof(List <string>), obj); // Assett Assert.Equal(obj, result); }
public void Test__string_to_int() { // Arrange var value = _fixture.Create <int>(); // Act var result = DynamicMap.Map <int>(value.ToString()); // Assert Assert.Equal(value, result); }
public void Test__int_to_decimal() { // Arrange var value = _fixture.Create <int>(); // Act var result = DynamicMap.Map <decimal>(value); // Assert Assert.Equal(new decimal(value), result); }
public void Test__decimal_to_int() { // Arrange var value = _fixture.Create <decimal>(); // Act var result = DynamicMap.Map <int>(value); // Assert Assert.Equal((int)value, result); }
public void Test__Basic() { // Arrange var obj = _fixture.Create <EnumerableModelSource>(); // Act var result = DynamicMap.Map(typeof(EnumerableModelDestination), obj); // Assert Assert(obj, result, new EnumerableModelComparer()); }
public void Test__Basic() { // Arrange var obj = _fixture.Create <ComplexModelSource>(); var json = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(obj)); // Act var result = DynamicMap.Map(typeof(ComplexModelSource), json); // Assert Assert.Equal(obj, result); }
public void TestThatConstructorInitializeDanymicMap() { var dynamicMap = new DynamicMap <int, string>(); Assert.That(dynamicMap, Is.Not.Null); Assert.That(dynamicMap.ExceptionInfo, Is.Not.Null); Assert.That(dynamicMap.ExceptionInfo, Is.Not.Empty); Assert.That(dynamicMap.ExceptionInfo, Is.EqualTo(string.Format("{0}, TSource={1}, TTarget={2}", dynamicMap.GetType().Name, typeof(int).Name, typeof(string).Name))); Assert.That(dynamicMap.MappingObject, Is.Not.Null); Assert.That(dynamicMap.MappingObject, Is.EqualTo(dynamicMap)); Assert.That(dynamicMap.MappingObjectData, Is.Null); }
public void Test__Basic() { // Arrange var obj = _fixture.Create <CustomClass>(); // Act DynamicMap.GetDynamicMapBuilder().RegisterCustomMapper(new CustomClassSpecialMapper()); var result = (CustomClass)DynamicMap.Map(typeof(CustomClass), new { CustomProp = obj.CustomProp }); // Assert Assert.True(obj.CustomProp == result.CustomProp && Flag.FlagValue); }
public void DynamicMapAssignKeepsReferences() { var three = new MyIntItem(3); var four = new MyIntItem(4); var newFive = new MyIntItem(5); DynamicMap <MyIntItem> dm = new DynamicMap <MyIntItem> { { "a", three }, { "b", four } }; DynamicMap <MyIntItem> dm2 = new DynamicMap <MyIntItem> { { "a", new MyIntItem(3) }, { "b", four }, { "c", newFive } }; dm.Assign(dm2); Assert.Same(three, dm["a"]); Assert.Same(four, dm["b"]); Assert.Same(newFive, dm["c"]); }
public void Test__Basic() { // Arrange var objs = new List <MergingModel> { _fixture.Build <MergingModel>() .With(x => x.StrProp1, _fixture.Create <string>()) .Without(x => x.StrProp2) .Without(x => x.StrProp3) .With(x => x.DateTimeProp1, _fixture.Create <DateTime>()) .Without(x => x.DateTimeProp2) .Without(x => x.DateTimeProp3) .Create(), _fixture.Build <MergingModel>() .Without(x => x.StrProp1) .With(x => x.StrProp2, _fixture.Create <string>()) .Without(x => x.StrProp3) .Without(x => x.DateTimeProp1) .With(x => x.DateTimeProp2, _fixture.Create <DateTime>()) .Without(x => x.DateTimeProp3) .Create(), _fixture.Build <MergingModel>() .Without(x => x.StrProp1) .Without(x => x.StrProp2) .With(x => x.StrProp3, _fixture.Create <string>()) .Without(x => x.DateTimeProp1) .Without(x => x.DateTimeProp2) .With(x => x.DateTimeProp3, _fixture.Create <DateTime>()) .Create() }; var expected = new MergingModel { StrProp1 = objs[0].StrProp1, StrProp2 = objs[1].StrProp2, StrProp3 = objs[2].StrProp3, DateTimeProp1 = objs[0].DateTimeProp1, DateTimeProp2 = objs[1].DateTimeProp2, DateTimeProp3 = objs[2].DateTimeProp3, }; // Act var result = DynamicMap.Merge <MergingModel>(objs); // Assert Assert(expected, result, new MergingModelComparer()); }
public void DynamicMapInvalidAssignmentThrows() { { DynamicMap <ConfigItem> dm = new DynamicMap <ConfigItem> { { "name", (SingleItem <string>) "foo" }, { "number", (SingleValue <int>) 42 } }; ConfigItem ci = new MyFalseEquatableItem(); Assert.Throws <ConfigItem.InvalidTypeAssignmentException>(() => dm.Assign(ci)); } { DynamicMap <ConfigItem> dm = new DynamicMap <ConfigItem> { { "name", (SingleItem <string>) "foo" }, { "comp", new MyComposite { ss1 = "foo" } } }; DynamicMap <ConfigItem> dm2 = new DynamicMap <ConfigItem> { { "name", (SingleItem <string>) "foo" }, { "comp", new MyComposite { ss1 = null } } }; bool thrown = false; try { dm.Assign(dm2); } catch (ConfigItem.InvalidChildAssignmentException e) { thrown = true; Assert.Single(e.ChildExceptions); var ce = e.ChildExceptions.First(); Assert.IsType <ConfigItem.InvalidChildAssignmentException>(ce); var ceces = ((ConfigItem.InvalidChildAssignmentException)ce).ChildExceptions; Assert.Single(ceces); var cecesFirst = ceces.First(); Assert.IsType <ConfigItem.InvalidTypeAssignmentException>(cecesFirst); var cece = (ConfigItem.InvalidTypeAssignmentException)cecesFirst; Assert.Equal(new SingleItem <string>("foo"), cece.OldItem); Assert.Null(cece.NewItem); } Assert.True(thrown); } }
public void DynamicMapEqualsCallsItemEquals() { { MyFalseEquatableItem e = new MyFalseEquatableItem(); DynamicMap <MyFalseEquatableItem> dm1 = new DynamicMap <MyFalseEquatableItem> { { "eq", e } }; DynamicMap <MyFalseEquatableItem> dm2 = new DynamicMap <MyFalseEquatableItem> { { "eq", e } }; Assert.False(dm1.Equals(dm2)); } { DynamicMap <MyTrueEquatableItem> dm1 = new DynamicMap <MyTrueEquatableItem> { { "eq", new MyTrueEquatableItem() } }; DynamicMap <MyTrueEquatableItem> dm2 = new DynamicMap <MyTrueEquatableItem> { { "eq", new MyTrueEquatableItem() } }; Assert.True(dm1.Equals(dm2)); } }
static DynamicMap[,] GenerateDynamicMap(StaticMap[,] static_map, DynamicPlayer[] players, int player_quantity) { int sizex = static_map.GetLength(0); int sizey = static_map.GetLength(1); DynamicMap[,] new_map = new DynamicMap[sizex, sizey]; for (int y = 0; y < sizey; y++) { for (int x = 0; x < sizex; x++) { DynamicMap new_cell = new DynamicMap(); new_cell.is_capital = false; new_cell.owner_id = -1; new_cell.coordinates = new Vector2(x, y); new_map[x, y] = new_cell; } } //Get the empty cells List <DynamicMap> empty_cells = new List <DynamicMap>(); for (int y = 0; y < sizey; y++) { for (int x = 0; x < sizex; x++) { if (static_map[x, y].type == 1) { empty_cells.Add(new_map[x, y]); } } } Debug.Log("Generated empty cells list with " + empty_cells.Count); //Each player will receive a capital that will be removed from the empty cells general list List <Vector2> capitals = new List <Vector2>(); for (int i = 0; i < players.Length; i++) { DynamicPlayer new_player = players[i]; new_player.occupied_cells = new List <DynamicMap>(); int r = -1; bool is_valid; bool is_done = false; while (!is_done) { is_valid = true; r = Random.Range(0, empty_cells.Count); for (int o = 0; o < capitals.Count; o++) { if (Vector2.Distance(capitals[o], empty_cells[r].coordinates) < 25) { is_valid = false; } } if (is_valid) { capitals.Add(empty_cells[r].coordinates); is_done = true; } } empty_cells[r].is_capital = true; new_player.occupied_cells.Add(empty_cells[r]); new_player.capital_coord = empty_cells[r].coordinates; empty_cells.RemoveAt(r); players[i] = new_player; Debug.Log("Created a capital for player ID: " + i); } //Each player will take the empty list and create its own, ordered by the closest to furthest for (int i = 0; i < players.Length; i++) { players[i].empty_cells = new List <DynamicMap>(); List <float> distances = new List <float>(); for (int o = 0; o < empty_cells.Count; o++) { float distance_from_capital = Vector2.Distance(empty_cells[o].coordinates, players[i].capital_coord); int add_at = 0; for (int p = 0; p < players[i].empty_cells.Count; p++) { if (distance_from_capital < distances[p]) { add_at = p; p = players[i].empty_cells.Count; } else { add_at = p + 1; } } players[i].empty_cells.Insert(add_at, empty_cells[o]); distances.Insert(add_at, distance_from_capital); } Debug.Log("Created empty list for player id " + i + " with " + players[i].empty_cells.Count + " 1st " + players[i].empty_cells[0].coordinates + " last " + players[i].empty_cells[players[i].empty_cells.Count - 1].coordinates); } //Enquanto estiverem celulas vazias while (empty_cells.Count > 0) { //Pra cada jogador até acabarem as células vazias for (int id = 0; id < player_quantity; id++) { int provinces_it_had = players[id].occupied_cells.Count; //For each occupied cells DynamicPlayer current_player = players[id]; DynamicMap checking_dynamic; StaticMap checking_static; bool found_neighbour = false; for (int c = current_player.occupied_cells.Count - 1; c >= 0; c--) { checking_dynamic = current_player.occupied_cells[c]; checking_static = static_map[(int)checking_dynamic.coordinates.x, (int)checking_dynamic.coordinates.y]; //Check if it has any available neighbours List <DynamicMap> neighbours = new List <DynamicMap>(); for (int i = 0; i < checking_static.adjacent_land.Length; i++) { neighbours.Add(new_map[(int)checking_static.adjacent_land[i].x, (int)checking_static.adjacent_land[i].y]); } bool has_available_neighbour = false; while (neighbours.Count > 0) { int r = Random.Range(0, neighbours.Count); DynamicMap checking_neighbour = neighbours[r]; neighbours.RemoveAt(r); if (!found_neighbour) { if (checking_neighbour.owner_id == -1 && checking_neighbour.owner_id != id) { //Found available neighbour checking_neighbour.owner_id = id; current_player.occupied_cells.Add(checking_neighbour); //Remove it from general and private list for (int i = empty_cells.Count - 1; i >= 0; i--) { if (empty_cells[i] == checking_neighbour) { empty_cells.RemoveAt(i); } } for (int i = 0; i < players.Length; i++) { for (int o = players[i].empty_cells.Count - 1; o >= 0; o--) { if (players[i].empty_cells[o] == checking_neighbour) { players[i].empty_cells.RemoveAt(o); } } } c = -1; found_neighbour = true; has_available_neighbour = true; } } } //If not, remove it from list if (!has_available_neighbour) { current_player.occupied_cells.RemoveAt(c); } } if (current_player.empty_cells.Count > 0) { if (!found_neighbour) { if (current_player.empty_cells[0].owner_id == -1) { //Get a random cell from its ordered list DynamicMap new_cell = current_player.empty_cells[0]; new_cell.owner_id = id; current_player.occupied_cells.Add(new_cell); //Remove it from the general list for (int i = empty_cells.Count - 1; i >= 0; i--) { if (empty_cells[i] == new_cell) { empty_cells.RemoveAt(i); } } for (int i = 0; i < players.Length; i++) { for (int o = players[i].empty_cells.Count - 1; o >= 0; o--) { if (players[i].empty_cells[o] == new_cell) { players[i].empty_cells.RemoveAt(o); } } } } } } //Debug.Log("Player of id "+id+" from "+provinces_it_had+ " to "+players[id].occupied_cells.Count+ " gain "+(players[id].occupied_cells.Count-provinces_it_had)); } } return(new_map); }
public TwoDimensionSorter(DynamicMap <K, V> newMap) { Map = newMap; }
public void DynamicMapEventsAreCalled() { SingleValue <int> three = 3; SingleValue <int> four = 4; SingleValue <int> five = 5; SingleValue <int> n2 = 6; DynamicMap <SingleValue <int> > dm = new DynamicMap <SingleValue <int> > { { "a", three }, { "b", four }, { "n1", null }, { "n2", null } }; DynamicMap <SingleValue <int> > dm2 = new DynamicMap <SingleValue <int> > { { "b", 42 }, { "c", five }, { "n1", null }, { "n2", n2 } }; bool threeDeleted = false; bool othersDeleted = false; void deleteHandler(object sender, DynamicMap <SingleValue <int> > .ItemDeletedArgs args) { Assert.Same(dm, sender); if (args.Key == "a" && object.ReferenceEquals(args.OldItem, three)) { Assert.False(threeDeleted); threeDeleted = true; } else { othersDeleted = true; } } dm.ItemDeleted += deleteHandler; bool fiveAdded = false; bool n2Added = false; bool othersAdded = false; void addHandler(object sender, DynamicMap <SingleValue <int> > .ItemAddedArgs args) { Assert.Same(dm, sender); if (args.Key == "c" && object.ReferenceEquals(args.NewItem, five)) { Assert.False(fiveAdded); fiveAdded = true; } else if (args.Key == "n2" && object.ReferenceEquals(args.NewItem, n2)) { Assert.False(n2Added); n2Added = true; } else { othersAdded = true; } } dm.ItemAdded += addHandler; bool fourUpdated = false; bool othersUpdated = false; void updateHandler(object sender, DynamicMap <SingleValue <int> > .ItemUpdatedArgs args) { Assert.Same(dm, sender); if (args.Key == "b" && object.ReferenceEquals(args.Item, four)) { Assert.False(fourUpdated); fourUpdated = true; } else { othersUpdated = true; } } dm.ItemUpdated += updateHandler; bool fourObjectUpdated = false; void fourUpdateHandler(object sender, SingleValue <int> .UpdatedArgs args) { Assert.False(fourObjectUpdated); fourObjectUpdated = true; } dm["b"].Updated += fourUpdateHandler; bool mapUpdateCalled = false; dm.Updated += (sender, args) => { Assert.False(mapUpdateCalled); mapUpdateCalled = true; var deleted = new List <KeyValuePair <string, SingleValue <int> > >(args.DeletedItems); Assert.Single(deleted); Assert.Equal("a", deleted[0].Key); Assert.Same(three, deleted[0].Value); var added = new List <KeyValuePair <string, SingleValue <int> > >(args.AddedItems); Assert.Equal(2, added.Count); Assert.Equal("c", added[0].Key); Assert.Same(five, added[0].Value); Assert.Equal("n2", added[1].Key); Assert.Same(n2, added[1].Value); var updated = new List <KeyValuePair <string, SingleValue <int> > >(args.UpdatedItems); Assert.Single(updated); Assert.Equal("b", updated[0].Key); Assert.Same(four, updated[0].Value); }; dm.Assign(dm2); Assert.True(threeDeleted); Assert.False(othersDeleted); Assert.True(fiveAdded); Assert.True(n2Added); Assert.False(othersAdded); Assert.True(fourUpdated); Assert.False(othersUpdated); Assert.True(fourObjectUpdated); Assert.True(mapUpdateCalled); Assert.Equal(four, dm["b"]); Assert.Equal <SingleValue <int> >(42, four); Assert.Equal(five, dm["c"]); }
/// <summary> /// Loopback to map complex types /// </summary> /// <param name="destinationType"></param> /// <param name="sourceType"></param> /// <param name="sourceObj"></param> /// <returns></returns> public virtual object LoopBackMapper(Type destinationType, Type sourceType, object sourceObj) => DynamicMap.GetDynamicMapBuilder().RecursiveMap(destinationType, sourceType, sourceObj, destinationObj: (_mappingMode == MappingMode.Merge ? sourceObj : null), mappingMode: _mappingMode);
/// <summary> /// Tries to get a dynamic map. /// </summary> /// <param name="dynamicId">The dynamic map id.</param> /// <param name="map">The dynamic map.</param> /// <returns>True if the dynamic map was found, false otherwise.</returns> public static bool TryGetDynamicMap(int dynamicId, out DynamicMap map) { return(_dynamicMaps.TryGetValue(dynamicId, out map)); }
/// <summary> /// Tries to add a dynamic map. /// </summary> /// <param name="map">The dynamic map.</param> /// <returns>True if the dynamic map was added, false otherwise.</returns> public static bool TryAddDynamicMap(DynamicMap map) { return(_dynamicMaps.TryAdd(map.Id, map)); }
public void DynamicMapEqualsWorks() { { DynamicMap <ConfigItem> dm1 = new DynamicMap <ConfigItem> { }; DynamicMap <ConfigItem> dm2 = new DynamicMap <ConfigItem> { { "number", (SingleValue <int>) 42 } }; Assert.NotEqual(dm1, dm2); Assert.NotEqual(dm2, dm1); Assert.False(dm1.Equals(dm2)); Assert.False(dm2.Equals(dm1)); } { DynamicMap <ConfigItem> dm1 = new DynamicMap <ConfigItem> { { "number", null } }; DynamicMap <ConfigItem> dm2 = new DynamicMap <ConfigItem> { { "number", (SingleValue <int>) 42 } }; Assert.NotEqual(dm1, dm2); Assert.NotEqual(dm2, dm1); Assert.False(dm1.Equals(dm2)); Assert.False(dm2.Equals(dm1)); } { DynamicMap <ConfigItem> dm1 = new DynamicMap <ConfigItem> { { "name", null } }; DynamicMap <ConfigItem> dm2 = new DynamicMap <ConfigItem> { { "name", null } }; Assert.Equal(dm1, dm2); Assert.Equal(dm2, dm1); Assert.True(dm1.Equals(dm2)); Assert.True(dm2.Equals(dm1)); } { MyComposite sm = new MyComposite { si = 42, ss1 = "foo", ss2 = null, nested = new MyComposite.MyNested { x = 10, y = 20, s = "bar" }, ci = null }; DynamicMap <ConfigItem> dm1 = new DynamicMap <ConfigItem> { { "name", (SingleItem <string>) "foo" }, { "number", (SingleValue <int>) 42 }, { "smap", sm } }; DynamicMap <ConfigItem> dm2 = new DynamicMap <ConfigItem> { { "number", (SingleValue <int>) 42 }, { "smap", sm }, { "name", (SingleItem <string>) "foo" } }; Assert.Equal(dm1, dm2); Assert.True(dm1.Equals(dm2)); } { DynamicMap <SingleItem <string> > dm1 = new DynamicMap <SingleItem <string> > { { "name", "foo" }, { "number", "42" } }; DynamicMap <SingleItem <string> > dm2 = new DynamicMap <SingleItem <string> > { { "name", "bar" }, { "number", "42" } }; Assert.NotEqual(dm1, dm2); Assert.False(dm1.Equals(dm2)); } { DynamicMap <SingleItem <string> > dm1 = new DynamicMap <SingleItem <string> > { { "name", "foo" }, { "number", "42" } }; DynamicMap <SingleItem <string> > dm2 = new DynamicMap <SingleItem <string> > { { "foo", null }, { "bar", null } }; Assert.NotEqual(dm1, dm2); Assert.False(dm1.Equals(dm2)); } { DynamicMap <ConfigItem> dm = new DynamicMap <ConfigItem> { { "name", (SingleItem <string>) "foo" }, { "number", (SingleValue <int>) 42 } }; Assert.False(dm.Equals(null)); Assert.False(dm.Equals((DynamicMap <ConfigItem>)null)); Assert.False(dm.Equals((DynamicMap <DynamicMap <ConfigItem> >)null)); Assert.False(dm.Equals((ConfigItem)null)); } }
public static void Main() { Random random = new Random(); Console.WriteLine("--------------------Static store"); StaticStore <Byte> staticByteStore = new StaticStore <Byte>(4); staticByteStore.Add(Byte.MinValue); staticByteStore.Add(Byte.MaxValue); staticByteStore.Add(1); staticByteStore.Add(8); //staticByteStore.Add(5); Console.WriteLine(staticByteStore); //StaticStore<Int16> staticInvalidShortStore = new StaticStore<Int16>(-1); StaticStore <Int16> staticShortStore = new StaticStore <Int16>(4); staticShortStore.Add(Int16.MinValue); staticShortStore.Add(Int16.MaxValue); staticShortStore.Add(2); staticShortStore.Add(16); Console.WriteLine(staticShortStore); StaticStore <Int32> staticIntegerStore = new StaticStore <Int32>(4); staticIntegerStore.Add(Int32.MinValue); staticIntegerStore.Add(Int32.MaxValue); staticIntegerStore.Add(4); staticIntegerStore.Add(32); Console.WriteLine(staticIntegerStore); StaticStore <Int64> staticLongStore = new StaticStore <Int64>(4); staticLongStore.Add(Int64.MinValue); staticLongStore.Add(Int64.MaxValue); staticLongStore.Add(8); staticLongStore.Add(64); Console.WriteLine(staticLongStore); StaticStore <Single> staticFloatStore = new StaticStore <Single>(6); staticFloatStore.Add(Single.MinValue); staticFloatStore.Add(Single.MaxValue); staticFloatStore.Add(Single.NegativeInfinity); staticFloatStore.Add(Single.PositiveInfinity); staticFloatStore.Add(Single.Epsilon); staticFloatStore.Add(Single.NaN); Console.WriteLine(staticFloatStore); StaticStore <Double> staticDoubleStore = new StaticStore <Double>(6); staticDoubleStore.Add(Double.MinValue); staticDoubleStore.Add(Double.MaxValue); staticDoubleStore.Add(Double.NegativeInfinity); staticDoubleStore.Add(Double.PositiveInfinity); staticDoubleStore.Add(Double.Epsilon); staticDoubleStore.Add(Double.NaN); Console.WriteLine(staticDoubleStore); StaticStore <Char> staticCharacterStore = new StaticStore <Char>(2); staticCharacterStore.Add(Char.MinValue); staticCharacterStore.Add(Char.MaxValue); Console.WriteLine(staticCharacterStore); StaticStore <Boolean> staticBooleanStore = new StaticStore <Boolean>(2); staticBooleanStore.Add(false); staticBooleanStore.Add(true); Console.WriteLine(staticBooleanStore); StaticStore <String> staticStringStore = new StaticStore <String>(4); staticStringStore.Add("Fellow"); staticStringStore.Add("Mellow"); staticStringStore.Add("Yellow"); staticStringStore.Add("Bellow"); Console.WriteLine(staticStringStore); StaticStore <Object> staticObjectStore = new StaticStore <Object>(2); staticObjectStore.Add(null); staticObjectStore.Add(new Object()); Console.WriteLine(staticObjectStore); Console.WriteLine("--------------------Static store replace item"); StaticStore <Int32> staticReplacedIntegerStore = new StaticStore <Int32>(4); Console.WriteLine(staticReplacedIntegerStore); //staticReplacedIntegerStore.ReplaceAll(0); //Console.WriteLine(staticReplacedIntegerStore); staticReplacedIntegerStore.Add(1); //staticReplacedIntegerStore.Replace(1, 7); staticReplacedIntegerStore.Add(3); staticReplacedIntegerStore.Add(9); staticReplacedIntegerStore.Add(5); Console.WriteLine(staticReplacedIntegerStore); staticReplacedIntegerStore.ReplaceAll(0); Console.WriteLine(staticReplacedIntegerStore); staticReplacedIntegerStore.Replace(1, 7); Console.WriteLine(staticReplacedIntegerStore); //Console.WriteLine("Index of 9 = " + Convert.ToString(staticReplacedIntegerStore.GetIndex(9))); Console.WriteLine("Item at index 3 = " + Convert.ToString(staticReplacedIntegerStore.Get(3))); Console.WriteLine("--------------------Dynamic store"); DynamicStore <Byte> dynamicByteStore = new DynamicStore <Byte>(); dynamicByteStore.Add(Byte.MinValue); dynamicByteStore.Add(Byte.MaxValue); dynamicByteStore.Add(1); dynamicByteStore.Add(8); Console.WriteLine(dynamicByteStore); DynamicStore <Int16> dynamicShortStore = new DynamicStore <Int16>(); dynamicShortStore.Add(Int16.MinValue); dynamicShortStore.Add(Int16.MaxValue); dynamicShortStore.Add(2); dynamicShortStore.Add(16); Console.WriteLine(dynamicShortStore); DynamicStore <Int32> dynamicIntegerStore = new DynamicStore <Int32>(); dynamicIntegerStore.Add(Int32.MinValue); dynamicIntegerStore.Add(Int32.MaxValue); dynamicIntegerStore.Add(4); dynamicIntegerStore.Add(32); Console.WriteLine(dynamicIntegerStore); DynamicStore <Int64> dynamicLongStore = new DynamicStore <Int64>(); dynamicLongStore.Add(Int64.MinValue); dynamicLongStore.Add(Int64.MaxValue); dynamicLongStore.Add(8); dynamicLongStore.Add(64); Console.WriteLine(dynamicLongStore); DynamicStore <Single> dynamicFloatStore = new DynamicStore <Single>(); dynamicFloatStore.Add(Single.MinValue); dynamicFloatStore.Add(Single.MaxValue); dynamicFloatStore.Add(Single.NegativeInfinity); dynamicFloatStore.Add(Single.PositiveInfinity); dynamicFloatStore.Add(Single.Epsilon); dynamicFloatStore.Add(Single.NaN); Console.WriteLine(dynamicFloatStore); DynamicStore <Double> dynamicDoubleStore = new DynamicStore <Double>(); dynamicDoubleStore.Add(Double.MinValue); dynamicDoubleStore.Add(Double.MaxValue); dynamicDoubleStore.Add(Double.NegativeInfinity); dynamicDoubleStore.Add(Double.PositiveInfinity); dynamicDoubleStore.Add(Double.Epsilon); dynamicDoubleStore.Add(Double.NaN); Console.WriteLine(dynamicDoubleStore); DynamicStore <Char> dynamicCharacterStore = new DynamicStore <Char>(); dynamicCharacterStore.Add(Char.MinValue); dynamicCharacterStore.Add(Char.MaxValue); Console.WriteLine(dynamicCharacterStore); DynamicStore <Boolean> dynamicBooleanStore = new DynamicStore <Boolean>(); dynamicBooleanStore.Add(false); dynamicBooleanStore.Add(true); Console.WriteLine(dynamicBooleanStore); DynamicStore <String> dynamicStringStore = new DynamicStore <String>(); dynamicStringStore.Add("Fellow"); dynamicStringStore.Add("Mellow"); dynamicStringStore.Add("Yellow"); dynamicStringStore.Add("Bellow"); Console.WriteLine(dynamicStringStore); DynamicStore <Object> dynamicObjectStore = new DynamicStore <Object>(); dynamicObjectStore.Add(null); dynamicObjectStore.Add(new Object()); Console.WriteLine(dynamicObjectStore); Console.WriteLine("--------------------Dynamic sorted store"); DynamicStore <Int32> dynamicSortedIntegerStore = new DynamicStore <Int32>(); for (Int32 i = 0; i < 52; i++) { dynamicSortedIntegerStore.Add(random.Next(2000)); } OneDimensionSorter <Int32> dynamicSortedIntegerStoreSingularSorter = new OneDimensionSorter <Int32>(dynamicSortedIntegerStore); dynamicSortedIntegerStoreSingularSorter.Sort(); Console.WriteLine(dynamicSortedIntegerStore); DynamicStore <String> dynamicSortedStringStore = new DynamicStore <String>(); dynamicSortedStringStore.Add("Fellow"); dynamicSortedStringStore.Add("Mellow"); dynamicSortedStringStore.Add("Yellow"); dynamicSortedStringStore.Add("Bellow"); OneDimensionSorter <String> dynamicSortedStringStoreSingularSorter = new OneDimensionSorter <String>(dynamicSortedStringStore); dynamicSortedStringStoreSingularSorter.Sort(); Console.WriteLine(dynamicSortedStringStore); Console.WriteLine("--------------------Dynamic store replace item"); DynamicStore <Int32> dynamicReplacedIntegerStore = new DynamicStore <Int32>(); dynamicReplacedIntegerStore.Add(1); dynamicReplacedIntegerStore.Add(3); //dynamicReplacedIntegerStore.Replace(2, 7); dynamicReplacedIntegerStore.Add(9); dynamicReplacedIntegerStore.Add(5); Console.WriteLine(dynamicReplacedIntegerStore); dynamicReplacedIntegerStore.Replace(2, 7); Console.WriteLine(dynamicReplacedIntegerStore); Console.WriteLine("--------------------Dynamic store insert item"); DynamicStore <Int32> dynamicInsertedIntegerStore = new DynamicStore <Int32>(); dynamicInsertedIntegerStore.Add(1); dynamicInsertedIntegerStore.Add(3); dynamicInsertedIntegerStore.Add(9); dynamicInsertedIntegerStore.Add(5); Console.WriteLine(dynamicInsertedIntegerStore); dynamicInsertedIntegerStore.Insert(2, 7); Console.WriteLine(dynamicInsertedIntegerStore); dynamicInsertedIntegerStore.Insert(0, 8); Console.WriteLine(dynamicInsertedIntegerStore); dynamicInsertedIntegerStore.Insert(6, 4); Console.WriteLine(dynamicInsertedIntegerStore); //dynamicInsertedIntegerStore.Insert(9, 0); //Console.WriteLine(dynamicInsertedIntegerStore); //dynamicInsertedIntegerStore.Insert(-1, 6); //Console.WriteLine(dynamicInsertedIntegerStore); Console.WriteLine("Index of 9 = " + Convert.ToString(dynamicInsertedIntegerStore.GetIndex(9))); Console.WriteLine("Item at index 3 = " + Convert.ToString(dynamicInsertedIntegerStore.Get(3))); Console.WriteLine(); Console.WriteLine("--------------------Dynamic unique item store"); DynamicUniqueStore <Int32> dynamicUniqueIntegerStore = new DynamicUniqueStore <Int32>(); dynamicUniqueIntegerStore.Add(1); dynamicUniqueIntegerStore.Add(2); dynamicUniqueIntegerStore.Add(1); dynamicUniqueIntegerStore.Add(3); Console.WriteLine(dynamicUniqueIntegerStore); Console.WriteLine("--------------------Dynamic key value store"); DynamicMap <String, Int32> dynamicKeyValueStore = new DynamicMap <String, Int32>(); dynamicKeyValueStore.Add("Yukon", 8); dynamicKeyValueStore.Add("Bicker", 9); dynamicKeyValueStore.Add("Shulz", 7); dynamicKeyValueStore.Add("Jems", 3); Console.WriteLine(dynamicKeyValueStore); DynamicMap <Int32, ItemStore <Int32> > dynamicKeyValueStoreWithListValue = new DynamicMap <Int32, ItemStore <Int32> >(); dynamicKeyValueStoreWithListValue.Add(1, new StaticStore <Int32>(4)); dynamicKeyValueStoreWithListValue.Add(2, new DynamicStore <Int32>()); dynamicKeyValueStoreWithListValue.Add(3, new DynamicUniqueStore <Int32>()); Console.WriteLine(dynamicKeyValueStoreWithListValue); Console.WriteLine("--------------------Dynamic sorted key value store"); DynamicMap <Int32, String> dynamicSortedIntegerKeyValueStore = new DynamicMap <Int32, String>(); dynamicSortedIntegerKeyValueStore.Add(88, "Yukon"); dynamicSortedIntegerKeyValueStore.Add(832, "Bicker"); dynamicSortedIntegerKeyValueStore.Add(832, "Blitzer"); dynamicSortedIntegerKeyValueStore.Add(7, "Shulz"); dynamicSortedIntegerKeyValueStore.Add(17, "Shulz"); dynamicSortedIntegerKeyValueStore.Add(3, "Jems"); TwoDimensionSorter <Int32, String> dynamicSortedIntegerKeyValueStoreSingularSorter = new TwoDimensionSorter <Int32, String>(dynamicSortedIntegerKeyValueStore); dynamicSortedIntegerKeyValueStoreSingularSorter.Sort(TwoDimensionConstants.KEY); Console.WriteLine(dynamicSortedIntegerKeyValueStore); Console.WriteLine("7 -> " + Convert.ToString(dynamicSortedIntegerKeyValueStore.GetValue(7))); //Console.WriteLine("Bicker <- " + Convert.ToString(dynamicSortedIntegerKeyValueStore.GetKey("Bicker"))); Console.WriteLine("Blitzer <- " + Convert.ToString(dynamicSortedIntegerKeyValueStore.GetKey("Blitzer"))); Console.WriteLine(); DynamicMap <String, Int32> dynamicSortedStringKeyValueStore = new DynamicMap <String, Int32>(); dynamicSortedStringKeyValueStore.Add("Yukon", 8); dynamicSortedStringKeyValueStore.Add("Bicker", 9); dynamicSortedStringKeyValueStore.Add("Shulz", 7); dynamicSortedStringKeyValueStore.Add("Jems", 3); TwoDimensionSorter <String, Int32> dynamicSortedStringKeyValueStoreSingularSorter = new TwoDimensionSorter <String, Int32>(dynamicSortedStringKeyValueStore); dynamicSortedStringKeyValueStoreSingularSorter.Sort(TwoDimensionConstants.VALUE); Console.WriteLine(dynamicSortedStringKeyValueStore); Console.WriteLine("Yukon -> " + Convert.ToString(dynamicSortedStringKeyValueStore.GetValue("Yukon"))); Console.WriteLine("3 <- " + Convert.ToString(dynamicSortedStringKeyValueStore.GetKey(3))); Console.WriteLine(); }
static DynamicMap[,] SmoothDynamicMap(DynamicMap[,] smoothing_map, StaticMap[,] static_map) { int xsize = smoothing_map.GetLength(0); int ysize = smoothing_map.GetLength(1); DynamicMap[,] result = new DynamicMap[xsize, ysize]; for (int y = 0; y < ysize; y++) { for (int x = 0; x < xsize; x++) { result[x, y] = smoothing_map[x, y]; } } for (int y = 0; y < ysize; y++) { for (int x = 0; x < xsize; x++) { //Get influences over this cell and store it DynamicMap d = result[x, y]; StaticMap s = static_map[x, y]; List <Influence> influences = new List <Influence>(); Vector2[] adjacents = { new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0), new Vector2(1, -1), new Vector2(0, -1), new Vector2(-1, -1), new Vector2(-1, 0), new Vector2(-1, 1) }; //if(s.adjacent_land != null){ if (d.owner_id != -1) { for (int i = 0; i < adjacents.Length; i++) { int cx = (int)(adjacents[i].x + d.coordinates.x); int cy = (int)(adjacents[i].y + d.coordinates.y); if (CheckIfCellExists(static_map, cx, cy)) { if (result[cx, cy].owner_id != -1) { DynamicMap c = result[cx, cy]; bool created_already = false; for (int o = 0; o < influences.Count; o++) { if (influences[o].owner_id == c.owner_id) { influences[o] = new Influence { owner_id = influences[o].owner_id, quantity = influences[o].quantity + 1 }; created_already = true; } } if (!created_already) { influences.Add(new Influence { owner_id = c.owner_id, quantity = 0 }); } } } } } //Find the most influential player on this cell Influence influencer = new Influence { owner_id = d.owner_id, quantity = -1 }; for (int i = 0; i < influences.Count; i++) { if (influences[i].quantity > influencer.quantity) { influencer = influences[i]; } else if (influences[i].quantity == influencer.quantity) { int coin = Random.Range(0, 2); if (coin == 0) { influencer = influences[i]; } } } d.owner_id = influencer.owner_id; //} } } return(result); }
/// <summary> /// Teleports the map object to a dynamic map. /// </summary> /// <param name="map">The dynamic map.</param> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> public void TeleportDynamic(DynamicMap map, ushort x, ushort y) { if (MapObject.Map != null) { if (map.Id == MapObject.MapId && x == MapObject.X && y == MapObject.Y) { return; } else if (!MapObject.Map.RemoveFromMap(MapObject)) { return; } } if (map == null) { return; } if (!map.AddToMap(MapObject)) { return; } MapObject.X = x; MapObject.Y = y; if (MapObject is Models.Entities.Player) { var player = (Models.Entities.Player)MapObject; if (player.LoggedIn) { player.AttackPacket = null; uint sendMap = (uint)player.Map.ClientMapId; player.ClientSocket.Send(new Models.Packets.Client.DataExchangePacket { ClientId = player.ClientId, Data1 = sendMap, Timestamp = Drivers.Time.GetSystemTime(), ExchangeType = Enums.ExchangeType.Teleport, Data3Low = x, Data3High = y }); player.ClientSocket.Send(new Models.Packets.Client.DataExchangePacket { ClientId = player.ClientId, Data1 = sendMap, Timestamp = Drivers.Time.GetSystemTime(), ExchangeType = Enums.ExchangeType.ChangeMap, Data3Low = x, Data3High = y }); player.ClientSocket.Send(new Models.Packets.Location.MapInfoPacket { Map = player.Map }); } player.DbPlayer.Update(); } UpdateScreen(true); }
void Start() { instance = this; }