private void ExecuteCommand() { if (Battery.Status - Battery.Consumption(CurrentRobotAction) < 0) { return; } Battery.Status = Battery.Status - Battery.Consumption(CurrentRobotAction); if (CurrentRobotAction == RobotAction.A || CurrentRobotAction == RobotAction.B) { PreviousCoordinate = CurrentCoordinate; CurrentCoordinate = GetResultCoordinate(CurrentFacing, CurrentRobotAction, CurrentCoordinate); } else if (CurrentRobotAction == RobotAction.TL || CurrentRobotAction == RobotAction.TR) { CurrentFacing = (Facing)Enum.Parse(typeof(Facing), FacingActionResult[(int)CurrentFacing][(int)CurrentRobotAction]); } if (!IsObstacle()) { if ((CurrentRobotAction == RobotAction.A || CurrentRobotAction == RobotAction.B) && (!Visited.Any(m => m.X == CurrentCoordinate.X && m.Y == CurrentCoordinate.Y))) { Visited.Add(CurrentCoordinate); } else if ((CurrentRobotAction == RobotAction.C) && (!Cleaned.Any(m => m.X == CurrentCoordinate.X && m.Y == CurrentCoordinate.Y))) { Cleaned.Add(CurrentCoordinate); } } }
private static bool Output(long status) { var previousPosition = droidPosition; var attemptedPosition = Compass.PositionAfterMovement(droidPosition, Attempt); if (status == 0) { // The repair droid hit a wall. Its position has not changed. area.Set(attemptedPosition, Day15Cell.Wall); Day15Debug.Set(attemptedPosition, Day15Cell.Wall); Day15Debug.WriteLine("BLOCKED"); } else { // The repair droid has moved one step in the requested direction. Day15Debug.WriteLine("OK"); droidPosition = attemptedPosition; if (!Backtracking) { area.Set(attemptedPosition, Day15Cell.Open); Day15Debug.Set(attemptedPosition, Day15Cell.Open); if (status == 2) { oxygenSystemPosition = attemptedPosition; } EnteredFrom[attemptedPosition] = Attempt; Visited.Add(attemptedPosition); Attempts.Push(Compass.AllDirections); } } return((Attempts.Count() > 1) || (Attempts.Peek().Count > 0)); }
public bool IsGraphConnected() { if (Graph.GraphParts is null) { } else { var foundedDirectedEdge = Graph.GraphParts.FirstOrDefault(x => x.IsDirected); if (foundedDirectedEdge is null) { } else { throw new ArgumentException( "It won't find out if the graph is connected or not when directed Graph Parts exists."); } } DeclareArrays(); Queue <int> queue = new Queue <int>(); int startVertex = 0; MainLoopForSeparatedConnectedGraph(queue, Visited, PreviousArray, startVertex); return(!Visited.Contains(false)); }
private void Search(int root) { var queue = new Queue <int>(); ChangeColor(root, Colors.Red); queue.Enqueue(root); Visited.Add(root); while (queue.Count > 0) { if (queue.ToList().Exists(d => d == TargetId)) { ChangeColor(TargetId.Value, Colors.Red); BuildPath(); return; } var v1 = queue.Dequeue(); foreach (var v2 in _model.GetAdjacentVerticies(v1)) { if (!Visited.Contains(v2)) { ChangeColor(HashCode.GetHashCode(v1, v2), Colors.CornflowerBlue); ChangeColor(v2, Colors.CornflowerBlue); queue.Enqueue(v2); Visited.Add(v2); _path[v2] = v1; if (v2 == TargetId) { break; } } } } }
public string CreateVisit(VisitedCreate model) { var entity = new Visited() { Profile_ID = _userId, BusinessID = model.BusinessID, EventID = model.EventID, Rating = model.Rating, Review = model.Review, AddToFavorites = model.AddToFavorites, AddToCalendar = model.AddToCalendar, }; using (var ctx = new ApplicationDbContext()) { try { ctx.Visits.Add(entity); ctx.SaveChanges(); return("Okay"); } catch { } return("Error"); } }
public string CreateVisit(VisitedCreate model) { var entity = new Visited() { UserID = _userId, TrailID = model.TrailID, Rating = model.Rating, Review = model.Review, AddToFavorites = model.AddToFavorites }; using (var ctx = new ApplicationDbContext()) { try { var trail = ctx.Trails.Single(e => e.ID == model.TrailID); } catch { return("Invalid Trail ID"); } try { var user = ctx.Users.Single(e => e.ID == _userId); } catch { return("Invalid User ID"); } try { var visited = ctx.Visits.Single(e => e.TrailID == model.TrailID && e.UserID == _userId); } catch { ctx.Visits.Add(entity); ctx.SaveChanges(); return("Okay"); } return("User Revisit"); } }
public async Task <IActionResult> SubmitAnswer(int qId, string answer) { Question question = await _context.Questions.Include(q => q.QuestionCategory).FirstOrDefaultAsync(q => q.QuestionId == qId); string stored = question.Answer.ToLower(); string input = answer.ToLower().Trim(); //Check for number vs word digit representation match by converting number to word. if (int.TryParse(stored, out int numStored)) { stored = numStored.ToWords(); } if (int.TryParse(input, out int inputStored)) { input = inputStored.ToWords(); } //Perform fuzzy matching using Levenshtein distance and consider 90% match a success int ratio = Fuzz.Ratio(stored, input); bool success = ratio >= 90; if (success) { CurrentScore += question.QuestionCategory.ScoreWeight; _currentUser.Money += question.QuestionCategory.ScoreWeight; _context.Entry(_currentUser).State = EntityState.Modified; await _context.SaveChangesAsync(); Visited.Add(qId); } return(Json(new { success, currentScore = CurrentScore })); }
public Visited Clone() { Visited c = new Visited(); c.Mask = Mask.ToArray(); return(c); }
public override void VisitDefault(IntermediateNode node) { Visited.Add(node); OnVisiting?.Invoke(node); base.VisitDefault(node); }
string Solve(int K, int N, List <int> keys, List <Chest> chests) { VisitedList = new List <Visited> [1 << VisitedHashLen]; for (int i = 0; i < VisitedList.Length; i++) { VisitedList[i] = new List <Visited>(); } List <List <int> > keyToChest = new List <List <int> >(); for (int i = 0; i < chests.Count; i++) { int k = chests[i].ToOpen; while (k >= keyToChest.Count) { keyToChest.Add(new List <int>()); } keyToChest[k].Add(i); } Visited v = new Visited(); v.Init(); List <int> order = Search(keys, chests, keyToChest, v, 0); if (order != null) { return(string.Join(" ", order)); } return("IMPOSSIBLE"); }
List <int> Search(List <int> keys, List <Chest> chests, List <List <int> > keyToChest, Visited v, int depth) { int hash = v.GetHashCode() & ((1 << VisitedHashLen) - 1); foreach (var h in VisitedList[hash]) { if (h == v) { return(null); } } VisitedList[hash].Add(v); VisitedListCount++; if (VisitedListCount > VisitedListCapacity) { for (int i = 0; i < VisitedList.Length; i++) { VisitedList[i] = new List <Visited>(); } } List <int> nexts = new List <int>(); foreach (var k in keys.Distinct()) { if (k < keyToChest.Count) { nexts.AddRange(keyToChest[k]); } } nexts.Sort(); foreach (var n in nexts) { if (v[n] == false) { List <int> nkeys = keys.ToList(); nkeys.Remove(chests[n].ToOpen); nkeys.AddRange(chests[n].Keys); nkeys.Sort(); Visited nv = v.Clone(); nv[n] = true; if (depth < chests.Count - 1) { List <int> r = Search(nkeys, chests, keyToChest, nv, depth + 1); if (r != null) { r.Insert(0, n + 1); return(r); } } else { return(new List <int> { n + 1 }); } } } return(null); }
private bool Search(int root) { if (root == TargetId) { ChangeColor(root, Colors.Red); return(true); } Visited.Add(root); if (root != SourceId) { ChangeColor(root, Colors.Gold); } foreach (var v in _model.GetAdjacentVerticies(root)) { if (!Visited.Contains(v)) { ChangeColor(HashCode.GetHashCode(root, v), Colors.Gold); if (Search(v)) { return(true); } ChangeColor(HashCode.GetHashCode(root, v), Colors.DarkSlateGray); } } ChangeColor(root, Colors.DarkSlateGray); return(false); }
public void AddVisited(string url) { Visited.Add(new VisitedEntity { Value = GetMd5Hash(url) }); SaveChanges(); }
public override bool VisitDeclaration(Declaration decl) { if (!IsRenameableDecl(decl)) { return(true); } if (AlreadyVisited(decl)) { return(true); } Visited.Add(decl); if (decl.Name == null) { return(true); } string newName; if (Rename(decl.Name, out newName)) { decl.Name = newName; return(true); } return(true); }
public virtual IEnumerable <LevelItem <TItem> > ExpandWalk(TItem start, int level, Func <LevelItem <TItem>, bool> predicate) { var queue = new Queue <LevelItem <TItem> > (); Action <TItem, TItem, int> enqueue = (node, path, l) => { if (!Visited.Contains(node)) { var item = new LevelItem <TItem> (node, path, l); if (predicate == null || predicate(item)) { queue.Enqueue(item); } Visited.Add(node); } }; enqueue(start, default(TItem), level); while (queue.Count > 0) { var item = queue.Dequeue(); yield return(item); level = item.Level; if (item.Node is TEdge) { var edge = (TEdge)item.Node; var adjacent = graph.Adjacent(edge, start); if (adjacent != null || (edge.Equals(start)) || (graph.RootIsEdge(edge) && graph.LeafIsEdge(edge))) { // follow link of links foreach (var edge_edge in graph.Edges(edge)) { enqueue(edge_edge, edge, level + 1); } } if (adjacent != null) // follow adjacent of start: { enqueue(adjacent, edge, level); } else { enqueue(edge.Root, edge, level); enqueue(edge.Leaf, edge, level); } } else if (item.Node.Equals(start)) { foreach (var edge in graph.Edges(item.Node)) { enqueue(edge, item.Node, level + 1); } } } }
public void VisitChildren() { int length = Visited.Count; for (int i = 0; i < length; i++) { var expr = Visited.Dequeue(); BaseVisit(expr); } }
public virtual IEnumerable <LevelItem <TItem> > CollapseWalk(TItem start, int level) { var queue = new Queue <TItem> (); foreach (var edge in graph.Edges(start)) { foreach (var subedge in graph.Edges(edge)) { if (!Visited.Contains(subedge)) { if (subedge.Leaf.Equals(edge)) { continue; } queue.Enqueue(subedge); Visited.Add(subedge); if (!Visited.Contains(subedge.Leaf)) { queue.Enqueue(subedge.Leaf); Visited.Add(subedge.Leaf); } } } if (!Visited.Contains(edge)) { if (edge.Leaf.Equals(start)) { continue; } queue.Enqueue(edge); Visited.Add(edge); if (!Visited.Contains(edge.Leaf)) { queue.Enqueue(edge.Leaf); Visited.Add(edge.Leaf); } } } while (queue.Count > 0) { var item = queue.Dequeue(); yield return(new LevelItem <TItem> (item, default(TItem), 0)); foreach (var edge in graph.Twig(item)) { if (!Visited.Contains(edge)) { Visited.Add(edge); yield return(new LevelItem <TItem> (edge, default(TItem), 0)); } } } }
public override void Calc() { var inp1 = input.Split('\n'); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { if (input[i * 7 + j] == '#') { grid[i, j] = true; } } } /* * var g = gridToInt(); * Console.WriteLine(Convert.ToString(g, 2)); */ while (true) { iterate(); int g = gridToInt(); if (Visited.Contains(g)) { //Console.WriteLine(g); /* for (int i = 0; i < 5; i++) * { * for (int j = 0; j < 5; j++) * { * if (grid[i, j]) * { * Console.Write('#'); * } * else * { * Console.Write('.'); * } * * } * Console.WriteLine(); * }*/ // Console.ReadLine(); output = g + ""; break; } Visited.Add(g); } }
// everywhere public int GetVisitsCount(string name) { if (Visited.TryGetValue(name, out var he)) { return(he.Visits); } else { return(0); } }
// override object.GetHashCode public override int GetHashCode() { unchecked { int hash = 13; hash = (hash * 7) + Row.GetHashCode(); hash = (hash * 7) + Column.GetHashCode(); hash = (hash * 7) + Visited.GetHashCode(); return(hash); } }
private int GetRandomQuestionId() { int currentId; do { currentId = Rand.Next(MinQuestionId, MaxQuestionId + 1); } while (Visited.Contains(currentId)); return(currentId); }
public List <IDiagramAnalysisNodeMessage> Evaluate() { var firewalls = network.Nodes.Values.Where(x => x.IsFirewall).ToList(); foreach (var firewall in firewalls) { Visited.Clear(); CheckRule2(firewall); } return(this.Messages); }
/** * This method will take a candidate list and identify is there is redundant * individual in it. If yes, it will get rid of the redundant individuals. * After that, it will check if all the samples from this generation have * been visited in previous generation. If yes, it will retrieve the samples * from previous generations. */ public IList <Individual> UniqueSamples(IEvolutionState state, IList <Individual> candidates) { // first filter out the redundant sample with in the set of candidates HashSet <Individual> set = new HashSet <Individual>(); foreach (Individual i in candidates) { if (!set.Contains(i)) { set.Add(i); } } // now all the individual in candidates are unique with in the set candidates = new List <Individual>(set); // Sk will be the new population IList <Individual> sk = new List <Individual>(); // see if we have these individual in visted array before for (int i = 0; i < candidates.Count; ++i) { IntegerVectorIndividual individual = (IntegerVectorIndividual)candidates[i]; if (VisitedIndexMap.ContainsKey(individual)) { // we have this individual before, retrieve that int index = VisitedIndexMap[individual]; // get the original individual individual = (IntegerVectorIndividual)Visited[index]; } else { Visited.Add(individual); VisitedIndexMap[individual] = Visited.Count - 1; // We add the new individual into the CornerMap // NOTE: if the individual already, we still need to do this? // original code says yes, but it seems to be wrong // so we do this only the new individual is new for (int j = 0; j < GenomeSize; ++j) { // The individual is the content. The key is its // coordinate position Corners[j].Insert(individual.genome[j], individual); } } sk.Add(individual); } return(sk); }
public void UpdateHistory(Site site) { Visited visit = new Visited(); Date current = FindObjectOfType <SetDate>().currentDate; visit.url = site.url; visit.displayedText = site.historyText; visit.dateVisited = current; InsertKeepSorted(visit); RemoveChildren(); CreateLinks(); }
public static void Run() { Console.WriteLine("Test data:"); Run("data/testdata19.txt"); Visited.Clear(); VisitedList.Clear(); Console.WriteLine("Answer data:"); Run("data/data19.txt"); Visited.Clear(); VisitedList.Clear(); Console.WriteLine("Answer data B:"); Run("data/data19b.txt"); }
public override int GetHashCode() { int hash = 1; if (Visited != false) { hash ^= Visited.GetHashCode(); } if (TimeNow != 0L) { hash ^= TimeNow.GetHashCode(); } return(hash); }
public bool Equals(Visited rhs) { if (rhs == null) { return(false); } for (int i = 0; i < MaskLen; i++) { if (Mask[i] != rhs.Mask[i]) { return(false); } } return(true); }
private void InsertKeepSorted(Visited visit) { Date date = visit.dateVisited; for (int i = 0; i < pastSites.Count; i++) { if (CompareDates(date, pastSites[i].dateVisited) == -1) { pastSites.Insert(i, visit); return; } } pastSites.Add(visit); //Oldest date, so add it to the end. }
public override List<Article> MakeList(params string[] searchCriteria) { List<Article> list = new List<Article>(); lock (Visited) { Visited.Clear(); foreach (string page in PrepareCategories(searchCriteria)) { list.AddRange(RecurseCategory(page, list.Count, Depth)); } Visited.Clear(); } return list; }
public override bool VisitTranslationUnit(TranslationUnit unit) { if (!unit.IsValid) { return(false); } if (ClearVisitedDeclarations) { Visited.Clear(); } VisitDeclarationContext(unit); return(true); }
private static void Solve(string header, string[] unparsedBoard) { string[] sHeader = header.Split(' '); int xpos = 0; int ypos = 0; char[,] board = new char[int.Parse(sHeader[1]), int.Parse(sHeader[0])]; Visited[,] visited = new Visited[int.Parse(sHeader[1]), int.Parse(sHeader[0])]; for (int i = 0; i < board.GetLength(0); i++) { for (int j = 0; j < board.GetLength(1); j++) { board[i, j] = unparsedBoard[i][j]; if (board[i, j] == 'X') { xpos = i; ypos = j; } } } int totalTime = 0; float speed = 1 / float.Parse(sHeader[2]); int reactionTime = int.Parse(sHeader[3]); Console.WriteLine(Math.Round(FindResult(board, xpos, ypos, visited, 0, 0, totalTime, speed, reactionTime))); }
private static float FindResult(char[,] board, int x, int y, Visited[,] visited, int xSlide, int ySlide, int time, float speed, int reactionTime) { if (x >= board.GetLength(0) || x < 0) return float.MaxValue; if (y >= board.GetLength(1) || y < 0) return float.MaxValue; Visited v = GetFromCoordinates(xSlide, ySlide); if ((visited[x, y] & v) == v) { #if DEBUG for (int i = 0; i < time; i++) { Console.Write(" "); } Console.WriteLine("(V) - {2} {0},{1} . - {3} {4} [{5}]", x, y, time, xSlide, ySlide, board[x, y]); #endif return float.MaxValue; } if (board[x, y] == '#') return float.MaxValue; if (board[x, y] == 'O') { #if DEBUG Console.WriteLine("Found it! 0 "); #endif return speed; } visited = (Visited[,])visited.Clone(); visited[x, y] = visited[x, y] | v; float result = 0; #if DEBUG for (int i = 0; i < time; i++) { Console.Write(" "); } Console.WriteLine("(B) - {2} {0},{1} . - {3} {4} [{5}]", x, y, time, xSlide, ySlide, board[x, y]); #endif int mul = 1; int newX = 0; int newY = 0; bool stopped = true; if (xSlide != 0 || ySlide != 0) { result = speed; stopped = false; while (!stopped) { newX = x + mul * xSlide; newY = y + mul * ySlide; visited[newX, newY] = visited[newX, newY] | GetFromCoordinates(xSlide, ySlide); #if DEBUG for (int i = 0; i < time; i++) { Console.Write(" "); } Console.WriteLine("(S) - {2} {0},{1} . - {3} {4} ({5}) [{6}]", newX, newY, time, xSlide, ySlide, result, board[newX, newY]); #endif if (board[newX, newY] == 'O') { #if DEBUG Console.WriteLine("Found it! {0} ", result); #endif return result + speed; } if (board[newX, newY] == '#') stopped = true; else { result += speed; mul++; } } } mul--; //Debug! float sum = result; #if DEBUG Console.WriteLine(sum); #endif x = x + mul * xSlide; y = y + mul * ySlide; if (stopped) { sum += reactionTime; } float[] results = { FindResult(board, x + 1, y, visited, 1, 0, time + 1, speed, reactionTime), FindResult(board, x - 1, y, visited, -1, 0, time + 1, speed, reactionTime), FindResult(board, x, y - 1, visited, 0, -1, time + 1, speed, reactionTime), FindResult(board, x, y + 1, visited, 0, 1, time + 1, speed, reactionTime), }; float min = results.Min(); #if DEBUG if (min < float.MaxValue) { for (int i = 0; i < time; i++) { Console.Write(" "); } Console.WriteLine("(E) - {2} {0},{1} . - {3} {4} [{5}]", x, y, time, xSlide, ySlide, sum + min); } #endif return sum + min; }