public void SerializeCircularListsIgnore() { CircularList circularList = new CircularList(); circularList.Add(null); circularList.Add(new CircularList { null }); circularList.Add(new CircularList { new CircularList { circularList } }); string json = JsonConvert.SerializeObject(circularList, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); StringAssert.AreEqual(@"[ null, [ null ], [ [] ] ]", json); }
// Use this for initialization void Start() { // Grab our components rb = GetComponent <Rigidbody2D>(); col = GetComponent <Collider2D>(); m_SpriteRenderer = GetComponent <SpriteRenderer>(); // get player size size = col.bounds.size; colorList.Add(Color.white); colorList.Add(Color.blue); colorList.Add(Color.red); colorList.Add(Color.green); m_SpriteRenderer.color = colorList.current(); firepoint = transform.Find("FirePoint"); if (firepoint == null) { Debug.LogError("no firepoint"); } lifecounter = 3; }
public void Current_Element_Index() { var list = new CircularList <int>(); list.Add(1); list.Add(2); Assert.AreEqual(list.GetCurrentElement(), 1); Assert.AreEqual(list.CurrentIndex, 0); }
public void CurrentNextPreviousEquala() { var cl = new CircularList <int>(); cl.Add(0); cl.Add(1); cl.Add(2); Assert.AreEqual(2, cl.Previous); Assert.AreEqual(0, cl.Current); Assert.AreEqual(1, cl.Next); }
public void SerializeListsWithPreserveObjectReferences() { CircularList circularList = new CircularList(); circularList.Add(null); circularList.Add(new CircularList { null }); circularList.Add(new CircularList { new CircularList { circularList } }); string json = JsonConvert.SerializeObject( circularList, Formatting.Indented, new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.All } ); StringAssert.AreEqual( @"{ ""$id"": ""1"", ""$values"": [ null, { ""$id"": ""2"", ""$values"": [ null ] }, { ""$id"": ""3"", ""$values"": [ { ""$id"": ""4"", ""$values"": [ { ""$ref"": ""1"" } ] } ] } ] }", json ); }
public void CheckQuickSorting() { CircularList <int> list = new CircularList <int>(); list.Add(5); list.Add(2); list.Add(3); list.Add(5); list.Add(6); list.Add(2); list.Add(5); list.Add(7); list.QuickSort(); int[] expected = { 2, 2, 3, 5, 5, 5, 6, 7 }; int[] result = list.GetSlice(); Assert.AreEqual(expected.Length, result.Length, "Не совпадает количество элементов в массивах"); bool isDif = false; for (int i = 0; i < expected.Length; i++) { if (result[i] != expected[i]) { isDif = true; } } Assert.AreEqual(false, isDif, "Есть несовпадающие элементы"); int checkPoint = 8 * 6 + 6; // (n*k) + (l-1) int expectedVal = 6; Assert.AreEqual(expectedVal, list[checkPoint], "Список не работает, как кольцевой"); }
public void Get_Next_Prev_Of() { var list = new CircularList <int>(); list.Add(1); list.Add(2); list.Add(3); Assert.AreEqual(list.GetNextOf(1), 2); Assert.AreEqual(list.GetNextOf(2), 3); Assert.AreEqual(list.GetNextOf(3), 1); Assert.AreEqual(list.GetPrevOf(1), 3); Assert.AreEqual(list.GetPrevOf(2), 1); Assert.AreEqual(list.GetPrevOf(3), 2); }
public void Clear_BeforeLooping() { CircularList<SimpleElement> list = new CircularList<SimpleElement>(3); SimpleElement one = new SimpleElement() { String = "One" }; SimpleElement two = new SimpleElement() { String = "Two" }; list.Add(one); list.Add(two); list.Clear(); Assert.IsEmpty(list, "List should be empty as it has just been cleared"); Assert.AreEqual(-1, list.CurrentIndex, "The index should have been reset by the clear"); }
public void TestAdd() { CircularList <Point> points = new CircularList <Point>(); Point p1 = new Point(1, 1); Point p2 = new Point(2, 2); Point p3 = new Point(3, 3); points.Add(p1); points.Add(p2); points.Add(p3); Assert.AreEqual(points.Contains(p1), true); Assert.AreEqual(points.Contains(p2), true); Assert.AreEqual(points.Contains(p3), true); }
private void JoinGame(JoinGameMessage message) { if (string.IsNullOrEmpty(message.PlayerName)) { Sender.Tell(new PlayerLoginFailed("The name should not be empty", message.ConnectionId)); } else if (isPlayerExists(message.PlayerName)) { Sender.Tell(new PlayerLoginFailed("Player with this name is already joined", message.ConnectionId)); } else if (_players.Count >= _maxPlayersNUmber) { Sender.Tell(new PlayerLoginFailed($"Number of players is not allowed to be more than {_maxPlayersNUmber}", message.ConnectionId)); } else { var newPlayer = new Player(message.PlayerName); _players.Add(newPlayer); Sender.Tell(new PlayerJoinedMessage(newPlayer)); Sender.Tell(new PlayerLoginSuccess(message.PlayerName, message.ConnectionId)); Sender.Tell(new LogMessage($"{newPlayer.Name} has joined to the game")); } if (_players.Count >= _enoughPlayersNumberToStart && _board.State == Board.GameState.WaitingForPlayers) { startGame(); } }
public void RemoveAtWorksRandomTest() { var testInst = new CircularList <int>(); var cmpList = new List <int>(); int seed = Environment.TickCount; Random rnd = new Random(seed); for (int i = 1; i < 200; i++) { if (rnd.Next(2) == 0) { testInst.AddFirst(i); cmpList.Insert(0, i); } else { testInst.Add(i); cmpList.Add(i); } } AreEqual(cmpList, testInst, "RemoveAtWorksRandomTest.Prepare. Seed = " + seed.ToString()); for (int i = 1; i < 200; i++) { int index = rnd.Next(0, testInst.Count); testInst.RemoveAt(index); cmpList.RemoveAt(index); AreEqual(cmpList, testInst, "RemoveAtWorksRandomTest. Seed = " + seed.ToString()); } }
public void IndexOfWorksOnObjects() { var testInst = new CircularList <object>(500); for (int i = 50; i < 100; i++) { testInst.AddLast(i); } for (int i = 49; i >= 0; i--) { testInst.AddFirst(i); } for (int i = 0; i < 100; i++) { testInst.Add(i); } for (int i = 0; i < 100; i++) { Assert.AreEqual(i, testInst.IndexOf(i)); } Assert.AreEqual(-1, testInst.IndexOf(null)); testInst.AddFirst(null); Assert.AreEqual(0, testInst.IndexOf(null)); }
public void Reset() { for (int i = 0; i < iSteps * 2; i++) { double u = 2 * Math.PI * (double)i / iSteps; vParameters.Add(new CircularList <double>(jSteps)); tabAngles.Add(new CircularList <double>(jSteps)); points.Add(new CircularList <Point>(jSteps)); for (int j = 0; j < jSteps; j++) { vParameters[i].Add(2 * Math.PI * ((double)j - 0.5) / jSteps); // tabAngles[i].Add((double) 5 / 6 * Math.PI); tabAngles[i].Add((double)Math.PI); points[i].Add(Evaluate(PointUV.Create(vParameters[i][j], u), p, q, circleAngle, inverseOffset, true) * scale); } } //for (int i = 0; i < iSteps * 2; i++) { // double u = 2 * Math.PI * (double) i / iSteps; // tabAngles.Add(new CircularList<double>(jSteps)); // for (int j = 0; j < jSteps; j++) { // int iOther = (j % 2 != 0) ? i - 1 : i + 1; // double l = (points[i][j + 1] - points[i][j]).Magnitude; // double d = (new[] { points[i][j + 1], points[i][j] }.Average() - // new[] { points[iOther][j + 1], points[iOther][j] }.Average()).Magnitude; // double angle = Math.PI - 2 * Math.Asin(l * d / (Math.Pow(l / 2, 2) + Math.Pow(d, 2))); // tabAngles[i][j] = angle; // } //} }
public void TestEnumerator() { CircularList <Point> points = new CircularList <Point>(); Point p1 = new Point(1, 1); Point p2 = new Point(2, 2); Point p3 = new Point(3, 3); points.Add(p1); points.Add(p2); points.Add(p3); foreach (Point p in points) { Assert.AreEqual(points.Contains(p), true); } }
void GetCircular() { //MvvmTest.Helpers.CommonHelpers.ShowAlert("circular"); List <CircularModel> circularList = null; Task.Factory.StartNew(() => { ISyncServices syncService = new SyncServices(); circularList = syncService.GetCircular(); }).ContinueWith((obj) => { Device.BeginInvokeOnMainThread(() => { if (circularList != null) { //MvvmTest.Helpers.CommonHelpers.ShowAlert("circular success"); foreach (var item in circularList) { item.cirName = item.cirName.ToUpper(); CircularList.Add(item); } //CircularList = new ObservableCollection<CircularModel>(circularList); } }); }); }
public void SerializeCircularListsError() { CircularList circularList = new CircularList(); circularList.Add(null); circularList.Add(new CircularList { null }); circularList.Add(new CircularList { new CircularList { circularList } }); JsonConvert.SerializeObject(circularList, Formatting.Indented); }
private void Load() { _contacts.Clear(); var contacts = _persister.Read(); if (contacts == null) { return; } foreach (var contact in contacts) { _contacts.Add(contact); } }
public void TestIndexOfFindElement() { CircularList <Point> points = new CircularList <Point>(); Point p1 = new Point(1, 1); Point p2 = new Point(2, 2); Point p3 = new Point(3, 3); points.Add(p1); points.Add(p2); points.Add(p3); //цепочка 1-3-2 Assert.AreEqual(points.IndexOf(p1), 0); Assert.AreEqual(points.IndexOf(p3), 1); Assert.AreEqual(points.IndexOf(p2), 2); }
public void SetUp() { l = new CircularList <int>(); for (int i = 0; i < 5; ++i) { l.Add(i + 1); } }
public void ContainsForNullWorks() { var testInst = new CircularList <object>(); testInst.Add(null); Assert.IsFalse(testInst.Contains(new object())); Assert.IsTrue(testInst.Contains(null)); }
public void SerializeCircularListsError() { string classRef = typeof(CircularList).FullName; CircularList circularList = new CircularList(); circularList.Add(null); circularList.Add(new CircularList { null }); circularList.Add(new CircularList { new CircularList { circularList } }); ExceptionAssert.Throws <JsonSerializationException>(() => { JsonConvert.SerializeObject(circularList, Formatting.Indented); }, "Self referencing loop detected with type " + classRef + ", Path: [2][0]"); }
private void RegisterEvent(GameEventType gameEventType, Vector3 position) { m_events.Add( new GameEvent(gameEventType) { Position = position } ); }
/// <summary> /// 分析TrackerAddress /// </summary> private void buildTrackerAddresses() { foreach (var item in this.trackerList) { TrackerAddressHolder holder = new TrackerAddressHolder(item); trackerAddressCircular.Add(holder); trackerAddressMap.Add(item, holder); } }
public static CircularList <T> ToCircularList <T>(this IOrderedEnumerable <T> value) { var circularList = new CircularList <T>(value.Count()); foreach (var val in value) { circularList.Add(val); } return(circularList); }
public void TestMoveNext() { CircularList <Point> points = new CircularList <Point>(); Point p1 = new Point(1, 1); Point p2 = new Point(2, 2); Point p3 = new Point(3, 3); points.Add(p1); points.MoveNext(); points.Add(p2); points.MoveNext(); points.Add(p3); points.MoveNext(); Assert.AreEqual(points[0], p1); points.MoveNext(); Assert.AreEqual(points[0], p2); points.MoveNext(); Assert.AreEqual(points[0], p3); }
/// <summary> /// Creates a list with given conditions /// </summary> private static CircularList <T> PrepareList <T>(int capacity, int startIndex, int count) { CircularList <T> result = new CircularList <T>(capacity); Reflector.SetField(result, "startIndex", startIndex); for (int i = 0; i < count; i++) { result.Add(i.Convert <T>()); } return(result); }
public void Remove_Complex() { const int MAX = 10; const int SENTINEL = 999; var list = new CircularList <int>(MAX); // Initialize for (var n = 1; n <= MAX; ++n) { list.Add(n); } list.Add(SENTINEL); // This list should now contain 2, 3, 4, 5, 6, 7, 8, 9, 10, 999 Assert.Equal(2, list[0]); Assert.Equal(SENTINEL, list[MAX - 1]); // Now remove something and check that things shuffle correctly. list.RemoveAt(0); Assert.Equal(MAX - 1, list.Count); Assert.Equal(3, list[0]); Assert.Equal(SENTINEL, list[MAX - 2]); // Now try removing by value rather than position/ Assert.True(list.Remove(SENTINEL)); Assert.Equal(MAX - 2, list.Count); Assert.Equal(3, list[0]); Assert.Equal(MAX, list[MAX - 3]); Assert.False(list.Contains(SENTINEL)); // Now try upper boundary list.Clear(); for (var n = 1; n <= MAX; ++n) { list.Add(n); } list.RemoveAt(MAX - 1); Assert.Equal(MAX - 1, list.Count); Assert.Equal(1, list[0]); Assert.Equal(MAX - 1, list[MAX - 2]); }
public void FillingListCheck() { CircularList <string> list = new CircularList <string>(); list.Add("something"); int equal = list.Count; int expected = 1; int equal2 = list.GetSlice().Length; Assert.AreEqual(expected, equal, "После добавления элемента количество не изменилось на 1"); Assert.AreEqual(expected, equal2, "Срез кольцевого списка возвращает не корректное количество элементов"); }
public void Add_Basic() { const int MAX = 10; const int SENTINEL = 999; var list = new CircularList <int>(MAX); // Make sure some basic facts are true after inserting items list.Add(SENTINEL); Assert.Equal(1, list.Count); Assert.Equal(SENTINEL, list[0]); Assert.True(list.Contains(SENTINEL)); }
public void MoveBack_WhenAddThreeItemsAndOneMoveBackAndAddItem_CurrentAndPreviousAndNextWorksGood() { var list = new CircularList <int>() { 0, 1, 2 }; list.MoveBack(); list.Add(3); AssertCurrentPreviousNext(list, 2, 1, 3); }
public static void Recovery(CircularList circlist) { try { string[] lines = System.IO.File.ReadAllLines("Contatos.txt"); int l = 0; while (l < lines.Length) { Contato contato = new Contato(); string[] aux = lines[l].Split("-"); contato.Name = aux[0]; contato.Telephone = aux[1]; contato.Email = aux[2]; circlist.Add(contato); l++; } Console.WriteLine("----{ Contact Recovered Successfully }----"); //List(circlist); } catch (Exception ex) { Console.WriteLine("The file could not be read:"); Console.WriteLine(ex.ToString()); } // try // { // using (StreamReader file = new StreamReader("lista.txt")) // { // string name; // string email; // string telephone; // while(true) // { // name = file.ReadLine(); // if(name == null) break; // email = file.ReadLine(); // if(email == null) break; // telephone = file.ReadLine(); // if(telephone == null) break; // circlist.Add(new Contato(name, email, telephone)); // } // } // } // catch(Exception ex) // { // Console.WriteLine(ex.ToString()); // } }
private static void CircularList() { CircularList<String> circularList = new CircularList<String>(); circularList.Add("Tomas"); circularList.Add("Nico"); circularList.Add("Andreas"); Console.WriteLine(circularList.Current()); circularList.Next(); Console.WriteLine(circularList.Current()); circularList.Next(); Console.WriteLine(circularList.Current()); circularList.Next(); Console.WriteLine(circularList.Current()); Console.WriteLine("Virker foreach?"); foreach (var str in circularList) { Console.WriteLine(str); } }
public void CircularListTest1() { ICircularList<int> lst = new CircularList<int>(5); for (int i = 0; i < 5; ++i) lst.Add(i); // verify assert's integrity Assert.True(lst.Count == 5); Assert.True(lst.GetItem(0) == 0); Assert.True(lst.GetItem(4) == 4); lst.Add(5); // step out from the max size Assert.True(lst.Count == 5); Assert.True(lst.GetItem(0) == 1); Assert.True(lst.GetItem(4) == 5); // complete count items for (int i = 0; i < 4; ++i) lst.Add(6 + i); // verify assert's integrity Assert.True(lst.Count == 5); Assert.True(lst.GetItem(0) == 5); Assert.True(lst.GetItem(4) == 9); }
public void CircularListTest2() { ICircularList<int> lst = new CircularList<int>(5); for (int i = 0; i < 15; ++i) lst.Add(i); // verify assert's integrity Assert.True(lst.Count == 5); Assert.True(lst.GetItem(0) == 10); Assert.True(lst.GetItem(4) == 14); var l = lst.Items.ToList(); Assert.True(l.Count == 5); Assert.True(l[0] == 10); Assert.True(l[4] == 14); }
public HandHistory Resume(PokerHand savedHand, CachedHand cache) { _cache = cache; #region Restore hand context _seats = new Seat[savedHand.Players.Length]; var orderedPlayers = savedHand.Players.OrderBy(p => p.Seat); for (int i = 0; i < _seats.Length; i++) { var player = orderedPlayers.ElementAt(i); _seats[i] = new Seat(player.Seat, player.Name, (double)player.Stack); } ulong handNum = ulong.Parse(savedHand.Context.ID); uint button = (uint)savedHand.Context.Button; List<double> blinds = new List<double>(); if (savedHand.Context.SmallBlind > 0m) blinds.Add((double)savedHand.Context.SmallBlind); if (savedHand.Context.BigBlind > 0m) blinds.Add((double)savedHand.Context.BigBlind); double ante = (double)savedHand.Context.Ante; BettingStructure bs = BettingStructure.None; switch (savedHand.Context.BettingType) { case BettingType.FixedLimit: bs = BettingStructure.Limit; break; case BettingType.NoLimit: bs = BettingStructure.NoLimit; break; case BettingType.PotLimit: bs = BettingStructure.PotLimit; break; default: throw new Exception("Unspecified betting structure."); } _history = new HandHistory(_seats, handNum, button, blinds.ToArray(), ante, bs); #endregion //Create a new map from player names to player chips for the BetManager Dictionary<string, double> namesToChips = new Dictionary<string, double>(); //Create a new list of players for the PlayerManager _playerIndices = new CircularList<int>(); _playerIndices.Loop = true; // Initialize the names to chips map and find the index of the button for (int i = 0; i < _seats.Length; i++) { namesToChips[_seats[i].Name] = _seats[i].Chips; if (_seats[i].SeatNumber == _history.Button) { _buttonIdx = i; _utgIdx = (i + 1) % _seats.Length; } } // Create a circular list of players, in order of first to act for (int i = (_buttonIdx + 1) % _seats.Length; _playerIndices.Count < _seats.Length; ) { _playerIndices.Add(i); i = (i + 1) % _seats.Length; } _betManager = new BetManager(namesToChips, _history.BettingStructure, _history.AllBlinds, _history.Ante); _potManager = new PotManager(_seats); _history.CurrentRound = Round.Predeal; if(savedHand.Blinds == null) savedHand.Blinds = new Blind[0]; if (!restoreBlinds(savedHand)) return _history; DealHoleCards(); if (_betManager.In <= 1) { _history.CurrentRound = Round.Over; return _history; } _history.CurrentRound = Round.Preflop; if (_betManager.CanStillBet > 1) { if(savedHand.Rounds == null || savedHand.Rounds.Length == 0) savedHand.Rounds = new PokerHandHistory.Round[] { new PokerHandHistory.Round(){Actions = new PokerHandHistory.Action[0]} }; else if(savedHand.Rounds[0].Actions == null) savedHand.Rounds[0].Actions = new PokerHandHistory.Action[0]; if (!restoreBets(savedHand.Rounds[0].Actions, _history.PreflopActions)) return _history; } if (_betManager.In <= 1) { payWinners(); _history.CurrentRound = Round.Over; return _history; } DealFlop(); _history.CurrentRound = Round.Flop; if (_betManager.CanStillBet > 1) { if (savedHand.Rounds.Length < 2) savedHand.Rounds = new PokerHandHistory.Round[]{savedHand.Rounds[0], new PokerHandHistory.Round(){Actions = new PokerHandHistory.Action[0]}}; else if(savedHand.Rounds[1].Actions == null) savedHand.Rounds[1].Actions = new PokerHandHistory.Action[0]; if (!restoreBets(savedHand.Rounds[1].Actions, _history.FlopActions)) return _history; } if (_betManager.In <= 1) { payWinners(); _history.CurrentRound = Round.Over; return _history; } DealTurn(); _history.CurrentRound = Round.Turn; if (_betManager.CanStillBet > 1) { if (savedHand.Rounds.Length < 3) savedHand.Rounds = new PokerHandHistory.Round[]{savedHand.Rounds[0], savedHand.Rounds[1], new PokerHandHistory.Round(){Actions = new PokerHandHistory.Action[0]}}; else if(savedHand.Rounds[2].Actions == null) savedHand.Rounds[2].Actions = new PokerHandHistory.Action[0]; if (!restoreBets(savedHand.Rounds[2].Actions, _history.TurnActions)) return _history; } if (_betManager.In <= 1) { payWinners(); _history.CurrentRound = Round.Over; return _history; } DealRiver(); _history.CurrentRound = Round.River; if (_betManager.CanStillBet > 1) { if (savedHand.Rounds.Length < 4) savedHand.Rounds = new PokerHandHistory.Round[]{savedHand.Rounds[0], savedHand.Rounds[1], savedHand.Rounds[2], new PokerHandHistory.Round(){Actions = new PokerHandHistory.Action[0]}}; else if(savedHand.Rounds[3].Actions == null) savedHand.Rounds[3].Actions = new PokerHandHistory.Action[0]; if (!restoreBets(savedHand.Rounds[3].Actions, _history.RiverActions)) return _history; } if (_betManager.In <= 1) { payWinners(); _history.CurrentRound = Round.Over; return _history; } payWinners(); _history.ShowDown = true; _history.CurrentRound = Round.Over; return _history; }
public void Enumerator_AfterLooping_LongerList() { CircularList<SimpleElement> list = new CircularList<SimpleElement>(3); SimpleElement one = new SimpleElement() { String = "One" }; SimpleElement two = new SimpleElement() { String = "Two" }; SimpleElement three = new SimpleElement() { String = "Three" }; SimpleElement four = new SimpleElement() { String = "Four" }; SimpleElement five = new SimpleElement() { String = "Five" }; list.Add(one); // ==> 0 list.Add(two); // ==> 1 list.Add(three); // ==> 2 list.Add(four); // ==> 0 list.Add(five); // ==> 1 List<SimpleElement> actual = new List<SimpleElement>(); foreach (SimpleElement cur in list) { actual.Add(cur); } Assert.AreEqual(3, actual.Count, "The foreach should have yielded 3 items"); Assert.AreEqual(three, actual[0], "First yielded item is wrong"); Assert.AreEqual(four, actual[1], "Second yielded item is wrong"); Assert.AreEqual(five, actual[2], "Third yielded item is wrong"); }
public void CopyTo_BeforeLooping_IndexGreaterThanZero() { CircularList<SimpleElement> list = new CircularList<SimpleElement>(3); SimpleElement one = new SimpleElement() { String = "One" }; SimpleElement two = new SimpleElement() { String = "Two" }; list.Add(one); list.Add(two); SimpleElement[] array = new SimpleElement[3]; list.CopyTo(array, 1); Assert.AreEqual(default(SimpleElement), array[0]); Assert.AreEqual(one, array[1]); }
public void Contains_AboutToLoop() { CircularList<SimpleElement> list = new CircularList<SimpleElement>(2); SimpleElement one = new SimpleElement() { String = "One" }; SimpleElement two = new SimpleElement() { String = "Two" }; SimpleElement three = new SimpleElement() { String = "Three" }; list.Add(one); list.Add(two); Assert.IsTrue(list.Contains(two), "The element should be in the list"); Assert.IsTrue(list.Contains(one), "The element should be in the list"); Assert.IsFalse(list.Contains(three), "The element should not be in the list"); }
public void IndexOf_BeforeLooping() { CircularList<SimpleElement> list = new CircularList<SimpleElement>(3); SimpleElement one = new SimpleElement() { String = "One" }; SimpleElement two = new SimpleElement() { String = "Two" }; SimpleElement three = new SimpleElement() { String = "Three" }; list.Add(one); list.Add(two); Assert.AreEqual(1, list.IndexOf(two), "Index should be 1 as this is the second element"); Assert.AreEqual(0, list.IndexOf(one), "Index should be 0 as this is the first element"); Assert.AreEqual(-1, list.IndexOf(three), "Index should be -1 as the item is not in the list"); }
public void Count_BeforeLooping() { CircularList<SimpleElement> list = new CircularList<SimpleElement>(3); SimpleElement one = new SimpleElement() { String = "One" }; SimpleElement two = new SimpleElement() { String = "Two" }; list.Add(one); list.Add(two); Assert.AreEqual(2, list.Count); }
public void IndexOf_AfterLooping() { CircularList<SimpleElement> list = new CircularList<SimpleElement>(2); SimpleElement one = new SimpleElement() { String = "One" }; SimpleElement two = new SimpleElement() { String = "Two" }; SimpleElement three = new SimpleElement() { String = "Three" }; list.Add(one); list.Add(two); list.Add(three); Assert.AreEqual(1, list.IndexOf(two), "Index should be 1 as this is the second element"); Assert.AreEqual(-1, list.IndexOf(one), "Index should be -1 as this item has been replaced by new content"); Assert.AreEqual(0, list.IndexOf(three), "Index should be 0 as the item is the first to be added after looping"); }
public void ForLoop_BeforeLooping() { CircularList<SimpleElement> list = new CircularList<SimpleElement>(3); var elements = new List<SimpleElement>() { new SimpleElement() { String = "One" }, new SimpleElement() { String = "Two" } }; foreach (var cur in elements) { list.Add(cur); } for (int i=0; i!=list.Count; i++) { Assert.AreEqual(elements[i], list[i], "Item {0} is wrong"); } }
public void CopyTo_AfterLooping_FromIndexZero() { CircularList<SimpleElement> list = new CircularList<SimpleElement>(2); SimpleElement one = new SimpleElement() { String = "One" }; SimpleElement two = new SimpleElement() { String = "Two" }; SimpleElement three = new SimpleElement() { String = "Three" }; list.Add(one); list.Add(two); list.Add(three); SimpleElement[] array = new SimpleElement[2]; list.CopyTo(array, 0); Assert.AreEqual(two, array[0]); Assert.AreEqual(three, array[1]); }
public void Iterate() { Iteration++; var newVParameters = new CircularList<CircularList<double>>(iSteps * 2); var backupVParameters = new CircularList<CircularList<double>>(iSteps * 2); var newTabAngles = new CircularList<CircularList<double>>(iSteps * 2); for (int i = 0; i < iSteps * 2; i++) { newVParameters.Add(new CircularList<double>(jSteps)); backupVParameters.Add(new CircularList<double>(jSteps)); newTabAngles.Add(new CircularList<double>(jSteps)); for (int j = 0; j < jSteps; j++) { newVParameters[i].Add(vParameters[i][j]); backupVParameters[i].Add(vParameters[i][j]); newTabAngles[i].Add(tabAngles[i][j]); } } double cumulativeErrorTally = 0; MaxError = 0; for (int i = 0; i < iSteps * 2; i++) { for (int j = 0; j < jSteps; j++) { bool swap = j % 2 == 0; int iOtherDir = swap ? -1 : 1; int iOther = i + iOtherDir; Circle baseCircle = GetTabFromPoints(true, i, j, iOther); Circle circle0 = GetTabFromPoints(true, iOther, j - 1, i); Circle circle1 = GetTabFromPoints(true, iOther, j + 1, i); double distance0 = (baseCircle.Frame.Origin - circle0.Frame.Origin).Magnitude - baseCircle.Radius - circle0.Radius; double distance1 = (baseCircle.Frame.Origin - circle1.Frame.Origin).Magnitude - baseCircle.Radius - circle1.Radius; cumulativeErrorTally += distance0 * distance0 + distance1 * distance1; MaxError = Math.Max(Math.Abs(distance0), MaxError); MaxError = Math.Max(Math.Abs(distance1), MaxError); double angleAdjust = (distance0 + distance1) / 2 * AngleForce / GetSpanAt(i, j) / baseCircle.Radius;// / GetSpanAt(i, j) / baseCircle.Radius; // / baseCircle.Radius; newTabAngles[i][j] -= angleAdjust; newTabAngles[i][j - 1] -= angleAdjust / 2; newTabAngles[i][j + 1] -= angleAdjust / 2; double iAngle = AddInHelper.AngleBetween( circle0.Frame.Origin - baseCircle.Frame.Origin, circle1.Frame.Origin - baseCircle.Frame.Origin ); double vOffset = (distance1 - distance0) * VForce; //double uAngleOffset = -(Math.PI / 2 - Math.Abs(iAngle)) * UAngleForce; double uAngleOffset = -(Math.PI * 2 / 3 - Math.Abs(iAngle)) * UAngleForce; Circle circleV = GetTabFromPoints(true, iOther, j, i); double distanceV = (baseCircle.Frame.Origin - circleV.Frame.Origin).Magnitude - baseCircle.Radius - circleV.Radius; double uTouchOffset = -distanceV * UTouchForce; double averageOffset = 0; double averageAngle = 0; double count = 0; #if false for (int ii = i - 1; ii <= i + 1; ii++) { for (int jj = j - 2; jj <= j + 2; jj++) { if (i == ii && j == jj) continue; double weight = (double) 1 / (Math.Pow(i - ii, 2) + Math.Pow(j - jj, 2)); averageOffset += GetSpanAt(ii, jj) * weight; averageAngle += GetTabFromPoints(true, i, j, j % 2 == 0 ? i - 1 : i + 1).Radius * weight; count += weight; } } averageOffset = averageOffset / count - GetSpanAt(i, j); averageOffset *= -AverageVForce / 2; averageAngle = averageAngle / count - baseCircle.Radius; newTabAngles[i][j] += averageAngle * AverageTabAngleForce; #elif true foreach (int ii in new int[] { i, iOther }) { foreach (int jj in new int[] { j - 1, j + 1 }) { averageAngle += GetTabFromPoints(true, ii, jj, ii == i ? iOther : i).Radius; count++; } } averageOffset += GetSpanAt(i - 1, j); averageOffset += GetSpanAt(i + 1, j); averageOffset += GetSpanAt(i, j - 1); averageOffset += GetSpanAt(i, j + 1); averageOffset /= 4; averageOffset = averageOffset / count - GetSpanAt(i, j); averageOffset *= -AverageVForce / 2; averageAngle = averageAngle / count - baseCircle.Radius; newTabAngles[i][j] -= averageAngle * AverageTabAngleForce; #else Point midpointV = GetFivePointNurbsAverage(new int[,] { {i, j-2}, {i, j-1}, {i, j}, {i, j+1}, {i, j+2} }); Point midpointD0 = GetFivePointNurbsAverage(new int[,] { {i-iOtherDir, j-2}, {i, j-1}, {i, j}, {i+iOtherDir, j+1}, {i+ 2 * iOtherDir, j+2} }); Point midpointD1 = GetFivePointNurbsAverage(new int[,] { {i-iOtherDir, j+2}, {i, j+1}, {i, j}, {i+iOtherDir, j-1}, {i+ 2 * iOtherDir, j-2} }); Point midpointU = GetFivePointNurbsAverage(new int[,] { {i - 2* iOtherDir, j}, {i - iOtherDir, j}, {i, j}, {i + iOtherDir, j}, {i + 2 * iOtherDir, j} }); averageOffset = (midpointV.Y + midpointU.Y) / 2 - GetSpanAt(i, j); averageOffset *= -AverageVForce / 2; averageAngle = (midpointV.X + 2 * midpointD0.X + 2 * midpointD1.X) / 5 - tabAngles[i][j]; newTabAngles[i][j] += averageAngle * AverageTabAngleForce; #endif double size = 1;// (points[i][j + 1] - points[i][j]).Magnitude; double slip = (uAngleOffset + averageOffset + uTouchOffset) * size; newVParameters[i][j] += vOffset + slip; newVParameters[i][j + 1] += vOffset - slip; newVParameters[i][j - 1] += (vOffset + slip) / 2; newVParameters[i][j + 2] += (vOffset - slip) / 2; // double oldSpan = (points[i][j + 1] - points[i][j]).Magnitude; // double newSpan = (points[i][j + 1] - points[i][j]).Magnitude; Trace.WriteIf(Iteration % 400 == 0, tabAngles[i][j] + " "); // Trace.WriteIf(Iteration % 400 == 0, iAngle + " "); // Trace.WriteIf(Iteration % 400 == 0, GetSpanAt(i,j) + " "); } Trace.WriteLineIf(Iteration % 400 == 0, ""); } for (int i = 0; i < iSteps * 2; i++) { for (int j = 0; j < jSteps; j++) { newTabAngles[i][j] = Math.Max(Math.PI / 2, newTabAngles[i][j]); newTabAngles[i][j] = Math.Min(Math.PI * 3 / 4, newTabAngles[i][j]); double l1 = backupVParameters[i][j + 1] - backupVParameters[i][j]; double l2 = newVParameters[i][j + 1] - newVParameters[i][j]; double b1 = Math.PI - tabAngles[i][j]; double a = l1 / l2 / Math.Tan(b1 / 2) * (1 + 1 / Math.Cos(b1 / 2)); double phi = 2 * Math.Atan(1 / a); tabAngles[i][j] = Math.PI - 2 * phi; //double b2 = 2 * Math.Asin(l2 / l1 * Math.Sin(b1 / 2)); //tabAngles[i][j] = Math.PI - b2; } } for (int i = 0; i < iSteps * 2; i++) { // make intersecting tabs identical //double angle = ( // newTabAngles[i][0] + // newTabAngles[i + iSteps][0] + // newTabAngles[i + iSteps / 2][jSteps / 2] + // newTabAngles[i + 3 * iSteps / 2][jSteps / 2] //) / 4; //newTabAngles[i][0] = angle; //newTabAngles[i + iSteps][0] = angle; //newTabAngles[i + iSteps / 2][jSteps / 2] = angle; //newTabAngles[i + 3 * iSteps / 2][jSteps / 2] = angle; double span = ( (newVParameters[i][1] - newVParameters[i][0]) + (newVParameters[i + iSteps][1] - newVParameters[i + iSteps][0]) + (newVParameters[i + iSteps / 2][jSteps / 2 + 1] - newVParameters[i + iSteps / 2][jSteps / 2]) + (newVParameters[i + 3 * iSteps / 2][jSteps / 2 + 1] - newVParameters[i + 3 * iSteps / 2][jSteps / 2]) ) / 8; newVParameters[i][0] = -span; newVParameters[i][1] = span; newVParameters[i + iSteps][0] = -span; newVParameters[i + iSteps][1] = span; newVParameters[i + iSteps / 2][jSteps / 2] = Math.PI - span; newVParameters[i + iSteps / 2][jSteps / 2 + 1] = Math.PI + span; newVParameters[i + 3 * iSteps / 2][jSteps / 2] = Math.PI - span; newVParameters[i + 3 * iSteps / 2][jSteps / 2 + 1] = Math.PI + span; } // Average antipodal points // for l(i, j), // l(i, j) == l(-i, pi+j)* == l(i+2pi, -j) == l(-i-2pi, pi-j)* // Where * means x=x, y=-y, z=-z for (int i = 0; i < iSteps * 2; i++) { for (int j = 0; j < jSteps / 2; j++) { double average = ( newVParameters[i][j] + newVParameters[-i][j + jSteps / 2] - Math.PI + (j < 2 ? 0 : 2 * Math.PI) - newVParameters[i + iSteps][-j + 1] + Math.PI - newVParameters[-i - iSteps][-j + jSteps / 2 + 1] ) / 4; newVParameters[i][j] = average; newVParameters[-i][j + jSteps / 2] = average + Math.PI; newVParameters[i + iSteps][-j + 1] = (j < 2 ? 0 : 2 * Math.PI) - average; newVParameters[-i - iSteps][-j + jSteps / 2 + 1] = Math.PI - average; average = ( tabAngles[i][j] + tabAngles[-i][j + jSteps / 2 + 1] + tabAngles[i + iSteps][-j] + tabAngles[-i - iSteps][-j + jSteps / 2 + 1] ) / 4; tabAngles[i][j] = average; tabAngles[-i][j + jSteps / 2 + 1] = average; tabAngles[i + iSteps][-j] = average; tabAngles[-i - iSteps][-j + jSteps / 2 + 1] = average; } } CumulativeError = Math.Sqrt(cumulativeErrorTally / (iSteps * 2 * jSteps * 2)); // Trace.WriteLine(lastCumulativeError); // We're not calculating the points for the last iteration. Whatevs. vParameters = newVParameters; tabAngles = newTabAngles; for (int i = 0; i < iSteps * 2; i++) { double u = 2 * Math.PI * (double) i / iSteps; for (int j = 0; j < jSteps; j++) { points[i][j] = Lawson.Evaluate(PointUV.Create(vParameters[i][j], u), p, q, circleAngle, inverseOffset, true) * scale; // Trace.WriteLine(string.Format("{0} {1} {2}", i, j, tabAngles[i][j])); } } }
/// <summary> /// Plays a hand from the start. Note that this method will <b>not</b> resume a game from a saved hand _history. /// </summary> /// <param name="handHistory">An new hand _history with the list of players and the game parameters.</param> public void PlayHand(HandHistory handHistory) { #region Hand Setup _seats = handHistory.Players; handHistory.HoleCards = new ulong[_seats.Length]; handHistory.DealtCards = 0UL; handHistory.Flop = 0UL; handHistory.Turn = 0UL; handHistory.River = 0UL; //Setup the hand _history this._history = handHistory; //Create a new map from player names to player chips for the BetManager Dictionary<string, double> namesToChips = new Dictionary<string, double>(); //Create a new list of players for the PlayerManager _playerIndices = new CircularList<int>(); _playerIndices.Loop = true; for (int i = 0; i < _seats.Length; i++) { namesToChips[_seats[i].Name] = _seats[i].Chips; if (_seats[i].SeatNumber == _history.Button) { _buttonIdx = i; _utgIdx = (i + 1) % _seats.Length; } } for (int i = (_buttonIdx + 1) % _seats.Length; _playerIndices.Count < _seats.Length;) { _playerIndices.Add(i); i = (i + 1) % _seats.Length; } _betManager = new BetManager(namesToChips, _history.BettingStructure, _history.AllBlinds, _history.Ante); _potManager = new PotManager(_seats); #endregion if (_betManager.In > 1) { GetBlinds(); DealHoleCards(); } _history.CurrentRound = Round.Preflop; if (_betManager.CanStillBet > 1) { GetBets(_history.PreflopActions); } if (_betManager.In <= 1) { payWinners(); return; } DealFlop(); _history.CurrentRound = Round.Flop; if (_betManager.CanStillBet > 1) { GetBets(_history.FlopActions); } if (_betManager.In <= 1) { payWinners(); return; } DealTurn(); _history.CurrentRound = Round.Turn; if (_betManager.CanStillBet > 1) { GetBets(_history.TurnActions); } if (_betManager.In <= 1) { payWinners(); return; } DealRiver(); _history.CurrentRound = Round.River; if (_betManager.CanStillBet > 1) { GetBets(_history.RiverActions); } if (_betManager.In <= 1) { payWinners(); return; } payWinners(); _history.ShowDown = true; _history.CurrentRound = Round.Over; }
public void Enumerator_BeforeLooping() { CircularList<SimpleElement> list = new CircularList<SimpleElement>(3); SimpleElement one = new SimpleElement() { String = "One" }; SimpleElement two = new SimpleElement() { String = "Two" }; list.Add(one); list.Add(two); List<SimpleElement> actual = new List<SimpleElement>(); foreach (SimpleElement cur in list) { actual.Add(cur); } Assert.AreEqual(2, actual.Count, "The foreach should have yielded 2 items"); Assert.AreEqual(one, actual[0], "First yielded item is wrong"); Assert.AreEqual(two, actual[1], "Second yielded item is wrong"); }
public void Enumerator_AboutToLoop_LongerList() { CircularList<SimpleElement> list = new CircularList<SimpleElement>(5); SimpleElement one = new SimpleElement() { String = "One" }; SimpleElement two = new SimpleElement() { String = "Two" }; SimpleElement three = new SimpleElement() { String = "Three" }; SimpleElement four = new SimpleElement() { String = "Four" }; SimpleElement five = new SimpleElement() { String = "FIve" }; list.Add(one); list.Add(two); list.Add(three); list.Add(four); list.Add(five); List<SimpleElement> actual = new List<SimpleElement>(); foreach (SimpleElement cur in list) { actual.Add(cur); } Assert.AreEqual(5, actual.Count, "The foreach should have yielded 5 items"); Assert.AreEqual(one, actual[0], "First yielded item is wrong"); Assert.AreEqual(two, actual[1], "Second yielded item is wrong"); Assert.AreEqual(three, actual[2], "Third yielded item is wrong"); Assert.AreEqual(four, actual[3], "Fourth yielded item is wrong"); Assert.AreEqual(five, actual[4], "Fifth yielded item is wrong"); }