public Entry <TK> Search(TK key) { Searched.Add(key); if (Inserted.ContainsKey(key) && !Deleted.Contains(key)) { return(new Entry <TK> { Key = key, Pointer = Inserted[key] }); } return(null); }
public override Direction[] Solve(Maze aMaze) { //ensure variable cost mode is on SearchMethod.VariableCost = true; AddToFrontier(aMaze.StartState); while (!Frontier.Empty()) { //Pop frontier state into curState MazeState curState = Frontier.Pop(); Searched.Add(curState); //check if curState is a goalState //using a loop for each of the varient goal states listed for (int i = 0; i < aMaze.GoalStates.Length; i++) { if (Maze.AreEqual(curState.State, aMaze.GoalStates[i].State)) { Maze.OutputState(curState.State); aMaze.FinalPathCost = curState.Cost; Console.WriteLine($"Path cost: {aMaze.FinalPathCost}"); iterationCount++; return(curState.GetPathFromParent()); } } //get all possible new states from curState List <MazeState> newStates = curState.CreatePossibleMoves(); foreach (MazeState s in newStates) { AddToFrontier(s); } iterationCount++; Frontier.SortByCost(); } return(null); }
private void SearchButton_Click(object sender, RoutedEventArgs e) { if (CustNameTextBox.Text == "" && CustSurnameTextBox.Text == "") { displayList = DB.GetListOfCustomers(); UpdateCustomersView(); } else { List <Customer> ToSearch = DB.GetListOfCustomers(); List <Customer> Searched = new List <Customer>(); if (CustNameTextBox.Text != "") { foreach (Customer customer in ToSearch) { if (customer.getFirstName().ToLower() == CustNameTextBox.Text.ToLower()) { Searched.Add(customer); } } ToSearch = Searched; Searched = new List <Customer>(); } if (CustSurnameTextBox.Text != "") { foreach (Customer customer in ToSearch) { if (customer.getSurname().ToLower() == CustSurnameTextBox.Text.ToLower()) { Searched.Add(customer); } } } displayList = Searched; UpdateCustomersView(); } }
public override Direction[] Solve(Maze aMaze) { //push the StartState to the frontier AddToFrontier(aMaze.StartState); while (!Frontier.Empty()) { //Pop frontier state into curState MazeState curState = Frontier.Dequeue(); Searched.Add(curState); //check if curState is a goalState //using a loop for each of the varient goal states listed for (int i = 0; i < aMaze.GoalStates.Length; i++) { if (Maze.AreEqual(curState.State, aMaze.GoalStates[i].State)) { Maze.OutputState(curState.State); aMaze.FinalPathCost = curState.Cost; Console.WriteLine($"Path cost: {aMaze.FinalPathCost}"); iterationCount++; return(curState.GetPathFromParent()); } } //get all possible new states from curState List <MazeState> newStates = curState.CreatePossibleMoves(); newStates.Reverse(); //Reverse elements to ensure priority is U > L > D > R foreach (MazeState s in newStates) { AddToFrontier(s); } iterationCount++; } return(null); }