List<List<WeightedGroupItem>> InitializePermutations(List<WeightedValue> groups) { PSDebug.Log ("Initialize permutations: {0}", groups.ToDebugString ()); var templates = new List<List<WeightedGroupItem>> (); var numPerms = 1; var digits = new int[groups.Count]; for (int i = 0; i < groups.Count; i++) { var item = groups [i]; var supplements = _supplements (item); supplements.ForEach (spm => spm.Weight *= item.Weight); numPerms *= digits [i] = supplements.Count; templates.Add (supplements); } var idx = new GenericNumber (digits); var perms = new List<List<WeightedGroupItem>> (numPerms); for (var i = 0; i < numPerms; ++i) { var row = new List<WeightedGroupItem> (); perms.Add (row); for (var digit = 0; digit < idx.Value.Length; ++digit) { row.Add (templates [digit] [idx.Value [digit]]); } idx.Incr (); } return perms; }
public override string ToString() { return($"{nameof(PersistentColonyGameData)} " + $"({nameof(CurrentMapIndex)}={CurrentMapIndex}, " + $"{nameof(MapSize)}={MapSize}, " + $"{nameof(info)}={info}, " + $"{nameof(rules)}={rules}, " + $"{nameof(scenario)}={scenario}, " + $"{nameof(playSettings)}={playSettings}, " + $"{nameof(storyWatcher)}={storyWatcher}, " + $"{nameof(gameEnder)}={gameEnder}, " + $"{nameof(letterStack)}={letterStack}, " + $"{nameof(researchManager)}={researchManager}, " + $"{nameof(storyteller)}={storyteller}, " + $"{nameof(history)}={history}, " + $"{nameof(taleManager)}={taleManager}, " + $"{nameof(playLog)}={playLog}, " + $"{nameof(battleLog)}={battleLog}, " + $"{nameof(outfitDatabase)}={outfitDatabase}, " + $"{nameof(drugPolicyDatabase)}={drugPolicyDatabase}, " + $"{nameof(foodRestrictionDatabase)}={foodRestrictionDatabase}, " + $"{nameof(tutor)}={tutor}, " + $"{nameof(dateNotifier)}={dateNotifier}, " + $"{nameof(gameComponents)}={gameComponents.ToDebugString()}, " + $"{nameof(CamRootPos)}={CamRootPos}, " + $"{nameof(DesiredSize)}={DesiredSize})"); }
public override string ToString() { return($"{nameof(PersistentWorld)} " + $"({nameof(Game)}={Game}, " + $"{nameof(Colony)}={Colony}, " + $"{nameof(LoadedMaps)}={LoadedMaps.ToDebugString()}, " + $"{nameof(Colonies)}={Colonies.ToDebugString()})"); }
public void RemoveActivities(List <string> activityIds, Action onSuccess, Action <GetSocialError> onFailure) { LogRequest("removeActivities", activityIds.ToDebugString()); WithHadesClient(client => { var response = client.removeActivities(SessionId, activityIds); Ui(() => { LogResponse("removeActivities", response); onSuccess.SafeCall(); }); }, onFailure); }
public void SetFriends(List <string> userIds, Action onSuccess, Action <GetSocialError> onFailure) { LogRequest("setFriends", userIds.ToDebugString()); WithHadesClient(client => { var response = client.setFriends(SessionId, userIds); Ui(() => { LogResponse("setFriends", response); onSuccess.SafeCall(); }); }, onFailure); }
static List <int> TopologicalSort(List <GraphNode> graph) { List <int> topological = new List <int>(); HashSet <int> visited = new HashSet <int>(); foreach (var node in graph) { if (visited.Contains(node.Key) == true) { continue; } Console.WriteLine("Do toplogical sort for {0}", node.Key); DoTopologicalSort(node, graph, ref visited, ref topological); } topological.Reverse(); Console.WriteLine("Topological Order is {0}", topological.ToDebugString()); return(topological); }
public float TestMatch(List<WeightedGroupItem> groups) { var result = 0.0f; var recipeComponents = new List<WeightedValue> (Groups); PSDebug.Log("TestMatch: {1} vs {0}", recipeComponents.ToDebugString(), groups.ToDebugString()); foreach (var testItem in groups) { WeightedValue softMatch = null; foreach (var wv in recipeComponents) { var match = wv.Match (testItem); if (match == 2) { recipeComponents.Remove (wv); result += testItem.Weight * wv.Weight; PSDebug.Log("Adding hard match: {0}, result = {1}, item weight = {2}, recipe weight = {3}", testItem.Name, result, testItem.Weight, wv.Weight); softMatch = null; break; } else if (match == 1) { softMatch = wv; } } if (softMatch != null) { recipeComponents.Remove (softMatch); result += testItem.Weight * softMatch.Weight; } } return recipeComponents.IsEmpty() ? result : 0; }
public override string ToString() { return(String.Format("NetworkLink(T: {0}, I: {1}, P: {2})", Target, Interfaces.ToDebugString(), Port)); }
public static List <Direction8Way> Search8WayNode(Node start, Node end, IMovable grid, out int distance) { Console.Error.WriteLine("Finding from {0} to {1} by A*", start, end); distance = -1; List <Direction8Way> pathWay = new List <Direction8Way>(); if (start.Equals(end)) { distance = 0; return(pathWay); } List <SearchNode> frontier = new List <SearchNode>(); List <SearchNode> explored = new List <SearchNode>(); SearchNode startNode = new SearchNode(start, null, 0, PathFinding.GetManhattanHeuristic(start, end)); frontier.Add(startNode); bool found = false; while (frontier.Count > 0) { SearchNode current = frontier[0]; frontier.RemoveAt(0); explored.Add(current); if (current.Pos.Equals(end)) { distance = current.CostSoFar + current.CostToEnd; SearchNode parent = current; while (parent != null && parent.Pos.Equals(start) == false) { Direction8Way dir = PathFinding.Get8WayDirection(parent.Parent.Pos, parent.Pos); pathWay.Add(dir); parent = parent.Parent; } found = true; break; } List <SearchNode> neighbors = PathFinding.Get8WayNeighbors(current, grid); foreach (SearchNode node in neighbors) { if (explored.Contains(node)) { continue; } node.CostSoFar = current.CostSoFar + 1; node.CostToEnd = PathFinding.GetManhattanHeuristic(node.Pos, end); int index = frontier.IndexOf(node); if (index > 0) { if (node.CostSoFar < frontier[index].CostSoFar) { // if found better way frontier[index].Parent = current; frontier[index].CostSoFar = node.CostSoFar; frontier[index].CostToEnd = node.CostToEnd; } } else { frontier.Add(node); } } frontier.Sort((item1, item2) => (item1.CostSoFar + item1.CostToEnd) - (item2.CostSoFar + item2.CostToEnd)); //Console.Error.WriteLine( "frontier = {0}", frontier.ToDebugString() ); } pathWay.Reverse(); if (found) { Console.Error.WriteLine("Found : {0} to {1} : {2} of distance {3}", start, end, pathWay.ToDebugString(), distance); } else { Console.Error.WriteLine("No Way! : {0} to {1}", start, end); } return(pathWay); }
public static List <Direction4Way> Search4WayNode(Node start, IReachable searchGrid, IMovable moveGrid, out int distance) { Console.Error.WriteLine("Finding from {0} by BFS", start); distance = -1; List <Direction4Way> pathWay = new List <Direction4Way>(); if (searchGrid.IsReachedDestination(start)) { distance = 0; return(pathWay); } List <SearchNode> frontier = new List <SearchNode>(); List <SearchNode> explored = new List <SearchNode>(); SearchNode startNode = new SearchNode(start, null, 0, 0); frontier.Add(startNode); bool found = false; while (frontier.Count > 0) { SearchNode current = ( SearchNode )frontier[0]; frontier.RemoveAt(0); explored.Add(current); if (searchGrid.IsReachedDestination(current.Pos)) { Console.Error.WriteLine("End node found : {0}", current.Pos); distance = current.CostSoFar + current.CostToEnd; SearchNode parent = current; while (parent != null && parent.Pos.Equals(start) == false) { Direction4Way dir = PathFinding.Get4WayDirection(parent.Parent.Pos, parent.Pos); //Console.Error.WriteLine( "iterate back to parent {0}", parent.Pos ); pathWay.Add(dir); parent = parent.Parent; } found = true; break; } List <SearchNode> neighbors = PathFinding.Get4WayNeighbors(current, moveGrid); foreach (SearchNode node in neighbors) { if (explored.Contains(node)) { continue; } node.CostSoFar = current.CostSoFar + 1; int index = frontier.IndexOf(node); if (index == -1) { frontier.Add(node); } } //Console.Error.WriteLine( "frontier = {0}", frontier.ToDebugString() ); } pathWay.Reverse(); if (found) { Console.Error.WriteLine("Found : from {0} through {1} of distance {2}", start, pathWay.ToDebugString(), distance); } else { Console.Error.WriteLine("No Way! Found from {0}", start); } return(pathWay); }
public List <Direction4Way> SearchGraphByDijkstra(Node start, PathGrid grid, out int cost) { cost = -1; List <Direction4Way> pathWay = new List <Direction4Way>(); if (grid.IsReachedDestination(start)) { cost = 0; return(pathWay); } List <SearchNode> frontier = new List <SearchNode>(); List <SearchNode> explored = new List <SearchNode>(); SearchNode startNode = new SearchNode(start, null, 0, 0); frontier.Add(startNode); bool found = false; while (frontier.Count > 0) { SearchNode current = ( SearchNode )frontier[0]; frontier.RemoveAt(0); explored.Add(current); if (grid.IsReachedDestination(current.Pos)) { cost = current.CostSoFar + current.CostToEnd; SearchNode parent = current; while (parent != null && parent.Pos.Equals(start) == false) { Direction4Way dir = PathFinding.Get4WayDirection(parent.Parent.Pos as Node, parent.Pos as Node); pathWay.Add(dir); parent = parent.Parent; } found = true; break; } List <SearchNode> neighbors = PathFinding.Get4WayNeighbors(current, grid); foreach (SearchNode node in neighbors) { if (explored.Contains(node)) { continue; } node.CostSoFar = current.CostSoFar + 1; node.CostToEnd = 0; int index = frontier.IndexOf(node); if (index > 0) { if (node.CostSoFar < frontier[index].CostSoFar) { // if found better way frontier[index].Parent = current; frontier[index].CostSoFar = node.CostSoFar; frontier[index].CostToEnd = node.CostToEnd; } } else { frontier.Add(node); } } frontier.Sort((item1, item2) => (item1.CostSoFar + item1.CostToEnd) - (item2.CostSoFar + item2.CostToEnd)); //Console.Error.WriteLine( "frontier = {0}", frontier.ToDebugString() ); } pathWay.Reverse(); if (found) { Console.Error.WriteLine("Found from {0} : {1} of distance {2}", start, pathWay.ToDebugString(), cost); } else { Console.Error.WriteLine("No Way! from {0}", start); } return(pathWay); }
public void SetFriendsByAuthIdentities(string providerId, List <string> providerUserIds, Action onSuccess, Action <GetSocialError> onFailure) { LogRequest("setFriendsByIdentity", string.Format("providerId:{0}, userIds: {1}", providerId, providerUserIds.ToDebugString())); WithHadesClient(client => { var response = client.setFriendsByIdentity(SessionId, providerId, providerUserIds); Ui(() => { LogResponse("setFriendsByIdentity", response); onSuccess.SafeCall(); }); }, onFailure); }
public void GetUsersByAuthIdentities(string providerId, List <string> providerUserIds, Action <Dictionary <string, PublicUser> > onSuccess, Action <GetSocialError> onFailure) { LogRequest("getPublicUsersByIdentity", "providerId=" + providerId + "; userIds=" + providerUserIds.ToDebugString()); WithHadesClient(client => { var apiUsers = client.getPublicUsersByIdentity(SessionId, providerId, providerUserIds); var publicUsers = apiUsers.ToDictionary(k => k.Key, k => k.Value.ToPublicUser()); Ui(() => { LogResponse("getPublicUsersByIdentity", apiUsers.ToDebugString()); onSuccess.SafeCall(publicUsers); }); }); }
public void SendNotification(List <string> userIds, NotificationContent content, Action <NotificationsSummary> onSuccess, Action <GetSocialError> onError) { var rpcContent = content.ToRpcModel(); LogRequest("sendNotification", string.Format("userIds: {0}, content: {1}", userIds.ToDebugString(), rpcContent)); rpcContent.UserIds = userIds; WithHadesClient(client => { var response = client.sendPushNotification(SessionId, rpcContent); Ui(() => { LogResponse("sendNotification", response); onSuccess.SafeCall(response.FromRpcModel()); }); }, onError); }
public static List <Offset> FindClosedPosByAStar(Offset startNode, int startDirection, Offset endNode, out List <int> rotationPathWay) { Console.Error.WriteLine("Path finding from {0} to {1} at direction of {2}", startNode, endNode, startDirection); rotationPathWay = new List <int>(); List <Offset> pathWay = new List <Offset>(); if (startNode.Equals(endNode)) { return(pathWay); } List <HexSearchNode> frontier = new List <HexSearchNode>(); List <HexSearchNode> explored = new List <HexSearchNode>(); HexSearchNode start = new HexSearchNode(startNode, startDirection, 0, GetHexHeuristic(startNode, endNode)); frontier.Add(start); bool found = false; while (frontier.Count > 0) { HexSearchNode current = frontier[0]; frontier.RemoveAt(0); explored.Add(current); if (current.Pos.Equals(endNode)) { HexSearchNode parent = current; while (parent != null && parent != start) { //Console.Error.WriteLine( "cost to {0} is {1}", parent.Pos, parent.CostSoFar ); int rotation = Offset.GetRotation(parent.Parent.Pos, parent.Pos); rotationPathWay.Add(rotation); pathWay.Add(parent.Pos); parent = parent.Parent; } found = true; break; } // constraints for early exit such as line of sight if (Offset.GetDistance(current.Pos, start.Pos) < 5) { List <HexSearchNode> neighbors = GetHexNeighbors(current, endNode); foreach (HexSearchNode node in neighbors) { if (explored.Contains(node)) { continue; } int costSoFar = current.CostSoFar; int costToEnd = PathFinding.GetHexHeuristic(node.Pos, endNode); int index = frontier.IndexOf(node); if (index > 0) { if (costSoFar < frontier[index].CostSoFar) { // already exist in the container and found better way frontier[index].Parent = current; frontier[index].Rotation = current.Rotation; frontier[index].CostSoFar = costSoFar; frontier[index].CostToEnd = costToEnd; } } else { // Not found node.Parent = current; node.CostSoFar = costSoFar; node.CostToEnd = costToEnd; frontier.Add(node); } } } frontier.Sort((item1, item2) => (item1.CostSoFar + item1.CostToEnd) - (item2.CostSoFar + item2.CostToEnd)); //Console.Error.WriteLine( "Frontier is {0}", frontier.ToDebugString() ); } if (pathWay.Count == 0 && explored.Count > 0) { explored.Sort((item1, item2) => (item1.CostSoFar + item1.CostToEnd) - (item2.CostSoFar + item2.CostToEnd)); HexSearchNode parent = explored[0]; while (parent != null && parent != start) { rotationPathWay.Add(Offset.GetRotation(parent.Parent.Pos, parent.Pos)); pathWay.Add(parent.Pos); parent = parent.Parent; } } pathWay.Reverse(); rotationPathWay.Reverse(); if (found) { Console.Error.WriteLine("Found : Pathway from {0} to target({1}) is {2}, rotation = {3} at distance of {4}", startNode, endNode, pathWay.ToDebugString(), rotationPathWay.ToDebugString(), pathWay.Count); } else { Console.Error.WriteLine("Not Found : Closest Pathway from {0} to target({1}) is {2}, rotation = {3} at distance of {4}", startNode, endNode, pathWay.ToDebugString(), rotationPathWay.ToDebugString(), pathWay.Count); } return(pathWay); }
private QuestionPackData CreateSingleQuestionPackData(HashSet <LetterData> availableLettersWithForms) { QuestionPackData pack = null; var teacher = AppManager.I.Teacher; int SAFE_COUNT = 0; while (true) { var commonLetter = availableLettersWithForms.ToList().RandomSelectOne(); var correctLetters = new List <LetterData>(); correctLetters.Add(commonLetter); availableLettersWithForms.Remove(commonLetter); //Debug.Log("Test " + SAFE_COUNT + ": Trying letter " + commonLetter); // Check if it has enough words List <WordData> wordsWithCommonLetter = null; try { wordsWithCommonLetter = teacher.VocabularyAi.SelectData( () => FindWordsWithCommonLetter(commonLetter), new SelectionParameters(SelectionSeverity.AllRequired, nWords, useJourney: parameters.useJourneyForCorrect, packListHistory: parameters.correctChoicesHistory, filteringIds: previousPacksIDs_words)); } catch (Exception) { SAFE_COUNT++; if (SAFE_COUNT == 100) { throw new Exception("Could not find enough data for CommonLettersInWord"); } continue; } //Debug.Log("Found letter " + commonLetter + " at trial count: " + SAFE_COUNT); var lettersNotInCommon = teacher.VocabularyAi.SelectData( () => FindLettersNotInCommon(wordsWithCommonLetter), new SelectionParameters(parameters.wrongSeverity, nWrong, useJourney: parameters.useJourneyForWrong, journeyFilter: SelectionParameters.JourneyFilter.CurrentJourney, getMaxData: true // needed to skip priority filtering, which will filter out forms! )); lettersNotInCommon = lettersNotInCommon.RandomSelect(nWrong); // needed to skip priority filtering, which will filter out forms! pack = QuestionPackData.Create(wordsWithCommonLetter, correctLetters, lettersNotInCommon); if (ConfigAI.VerboseQuestionPacks) { string debugString = "--------- TEACHER: question pack result ---------"; debugString += "\nQuestion: " + wordsWithCommonLetter.ToDebugString(); debugString += "\nCorrect Answers: " + correctLetters.Count; foreach (var l in correctLetters) { debugString += " " + l; } debugString += "\nWrong Answers: " + lettersNotInCommon.Count; foreach (var l in lettersNotInCommon) { debugString += " " + l; } ConfigAI.AppendToTeacherReport(debugString); } return(pack); } }
private Item[] DoGetNamespacesNamed(string name) { Profile.Start("AutoComplete::DoGetNamespacesNamed"); var items = new List<Item>(m_database.GetNamespaces(name)); string[] names = m_parses.FindNamespaces(name); #if DEBUG Log.WriteLine(TraceLevel.Verbose, "AutoComplete", "db namespaces: {0}", items.ToDebugString()); Log.WriteLine(TraceLevel.Verbose, "AutoComplete", "parsed namespaces: {0}", names.ToDebugString()); #endif foreach (string n in names) { var item = new NameItem(n, name + '.' + n, name + " types"); items.AddIfMissing(item); } Profile.Stop("AutoComplete::DoGetNamespacesNamed"); return items.ToArray(); }