internal void AddSerializedPolicies (StreamReader reader) { if (policies == null) policies = new PolicyDictionary (); foreach (ScopedPolicy policyPair in PolicyService.RawDeserializeXml (reader)) { PolicyKey key = new PolicyKey (policyPair.PolicyType, policyPair.Scope); if (policies.ContainsKey (key)) throw new InvalidOperationException ("Cannot add second policy of type '" + key.ToString () + "' to policy set '" + Id + "'"); policies[key] = policyPair.Policy; if (!policyPair.SupportsDiffSerialize) externalPolicies.Add (key); } }
public void DoMove(TicTacToe game) { if (!PolicyDictionary.ContainsKey(game.BoardState)) { int val = 0; do { val = rng.Next(9); }while ((BoardSpaceState)(game.BoardState[val / 3, val % 3]) != BoardSpaceState.None); PolicyDictionary.Add((BoardSpaceState[, ])game.BoardState.Clone(), val); } game.Place(PolicyDictionary[game.BoardState] / 3, PolicyDictionary[game.BoardState] % 3); }
private PageCommentPolicy GetDefaultPagePolicy() { var website = HttpContext.Current.GetWebsite(); var defaultPageCommentPolicySiteSetting = website.Settings.Get <string>("cms/defaultPageCommentPolicy"); if (string.IsNullOrWhiteSpace(defaultPageCommentPolicySiteSetting)) { return(PageCommentPolicy.None); } PageCommentPolicy policy; return(PolicyDictionary.TryGetValue(defaultPageCommentPolicySiteSetting, out policy) ? policy : PageCommentPolicy.None); }
internal int PlayGame(RandomMoveAgent randomagent) { var game = new TicTacToe(); var playerOneMoves = new List <BoardSpaceState[, ]>(); //var playerTwoMoves = new List<BoardSpaceState[,]>(); int alternator = 1; while (game.Player1Win() == null && !game.IsDraw()) { if (alternator == 1) { playerOneMoves.Add((BoardSpaceState[, ])game.BoardState.Clone()); DoMove(game); alternator = 2; } else if (alternator == 2) { randomagent.DoMove(game); alternator = 1; } } if (!game.IsDraw()) { bool winner = (bool)game.Player1Win(); if (winner) { //foreach (var move in playerTwoMoves) //{ // PolicyDictionary.Remove(move); //} return(1); } else { foreach (var move in playerOneMoves) { if (PolicyDictionary.Remove(move)) { } } return(2); } } return(0); }
void ICustomDataItem.Deserialize (ITypeSerializer handler, DataCollection data) { if (data.Count == 0) return; policies = new PolicyDictionary (); foreach (DataNode node in data) { try { if (!(node is DataItem)) continue; ScopedPolicy val = PolicyService.DiffDeserialize ((DataItem)node); policies.Add (val); } catch (Exception ex) { if (handler.SerializationContext.ProgressMonitor != null) handler.SerializationContext.ProgressMonitor.ReportError (ex.Message, ex); else LoggingService.LogError (ex.Message, ex); } } }
public void CopyFrom (PolicySet pset) { if (pset.policies == null && policies == null) return; // Add and update policies if (pset.policies != null) { foreach (KeyValuePair<PolicyKey, object> p in pset.policies) { object oldVal; if (policies == null || !policies.TryGetValue (p.Key, out oldVal) || oldVal == null || !oldVal.Equals (p.Value)) { if (policies == null) policies = new PolicyDictionary (); policies [p.Key] = p.Value; OnPolicyChanged (p.Key.PolicyType, p.Key.Scope); } } } // Remove policies if (policies != null) { foreach (PolicyKey k in policies.Keys.ToArray ()) { if (pset.policies == null || !pset.policies.ContainsKey (k)) { policies.Remove (k); OnPolicyChanged (k.PolicyType, k.Scope); } } } }
internal void LoadFromXml (XmlReader reader) { if (policies == null) policies = new PolicyDictionary (); else policies.Clear (); reader.MoveToContent (); string str = reader.GetAttribute ("name"); if (!string.IsNullOrEmpty (str)) Name = str; str = reader.GetAttribute ("id"); if (!string.IsNullOrEmpty (str)) Id = str; reader.MoveToElement (); //note: can't use AddSerializedPolicies as we want diff serialisation foreach (ScopedPolicy policyPair in PolicyService.DiffDeserializeXml (reader)) { PolicyKey key = new PolicyKey (policyPair.PolicyType, policyPair.Scope); if (policies.ContainsKey (key)) throw new InvalidOperationException ("Cannot add second policy of type '" + key.ToString () + "' to policy set '" + Id + "'"); policies[key] = policyPair.Policy; } }
internal void LoadFromFile (StreamReader reader) { if (policies == null) policies = new PolicyDictionary (); else policies.Clear (); //note: can't use AddSerializedPolicies as we want diff serialisation foreach (ScopedPolicy policyPair in PolicyService.DiffDeserializeXml (reader)) { PolicyKey key = new PolicyKey (policyPair.PolicyType, policyPair.Scope); if (policies.ContainsKey (key)) throw new InvalidOperationException ("Cannot add second policy of type '" + key.ToString () + "' to policy set '" + Id + "'"); policies[key] = policyPair.Policy; } }