private void SteeringMove(HeuristicType heuristicType) { switch (heuristicType) { case HeuristicType.A1: MovementBehaviour1.SteeringArrive(); break; case HeuristicType.A2: MovementBehaviour1.KinematicArrive(); break; case HeuristicType.B1: MovementBehaviour1.KinematicArrive(); break; case HeuristicType.B2: MovementBehaviour1.SteeringArrive(); break; case HeuristicType.C1: MovementBehaviour1.SteeringFlee(); break; case HeuristicType.C2: MovementBehaviour1.Evade(); break; } }
public void Move(HeuristicType heuristicType) { //set maxspeed to original value MovementBehaviour1.MaxSpeed = originalMaxSpeed; //check if the player's speed is close to zero if (_movementBehaviour.CharacterVelocity.magnitude < 1f) { playerAnimation.Play("idle"); } //check if current speed is half,set animation to walk else if (rigidbody.velocity.magnitude < originalMaxSpeed * 0.5f) { playerAnimation.Play("walk"); } else { playerAnimation.Play("run"); } if (currentState == InputController.MovementTypeState.kinematic) { KinematicMovement(heuristicType); //print(name + " is moving kinematically"); // MovementBehaviour1.KinematicArrive(); } else { SteeringMove(heuristicType); // print(name + " is moving by steering"); //MovementBehaviour1.SteeringArrive(); } }
private void KinematicRotate(HeuristicType heuristicType) { switch (heuristicType) { case HeuristicType.A1: break; case HeuristicType.A2: MovementBehaviour1.InterpolateRotate(); break; case HeuristicType.B1: MovementBehaviour1.InterpolateRotate(); break; case HeuristicType.B2: MovementBehaviour1.InterpolateRotate(); break; case HeuristicType.C1: // MovementBehaviour1.InterpolateRotate(); break; case HeuristicType.C2: MovementBehaviour1.InterpolateRotateWithEnemy(); break; } }
public int GetMove(State state, bool player, MethodType methodType, HeuristicType heuristicType, out int nodesVisited) { int selectedCol = 0; switch (methodType) { case MethodType.AlphaBeta: { int alpha = int.MinValue; int beta = int.MaxValue; AlphaBeta(state, player, this.depth, ref selectedCol, alpha, beta, heuristicType); break; } case MethodType.MinMax: { MinMax(state, player, this.depth, ref selectedCol, heuristicType); break; } } nodesVisited = this.nodesVisited; this.nodesVisited = 0; if (selectedCol == -1) { selectedCol = FixSelectedCol(state); } return(selectedCol); }
private void KinematicMovement(HeuristicType heuristicType) { switch (heuristicType) { case HeuristicType.A1: MovementBehaviour1.KinematicArrive(); break; case HeuristicType.A2: MovementBehaviour1.KinematicArrive(); break; case HeuristicType.B1: MovementBehaviour1.KinematicArrive(); break; case HeuristicType.B2: MovementBehaviour1.KinematicArrive(); break; case HeuristicType.C1: MovementBehaviour1.KinematicFlee(); break; case HeuristicType.C2: MovementBehaviour1.KinematicFlee(); break; } }
// Use this for initialization private void Awake() { all_path_nodes = new List <GameObject>(); all_connector_nodes = new List <GameObject>(); connecters_path_table = new Dictionary <GameObject, Dictionary <GameObject, Node> >(); path = new List <GameObject>(); path_nodes = new Dictionary <string, List <GameObject> >(); heuristic_type = HeuristicType.Dijkstra; }
public void InitializeHeuristics(HeuristicType type) { StopAllCoroutines(); if (breadcrumbs == null) { return; } foreach (Breadcrumb b in breadcrumbs) { if (b == null) { continue; } if (b == goalCrumb) { b.heuristic = 0; b.SetColor(Color.green); continue; } switch (type) { case HeuristicType.None: b.heuristic = 0; b.initialColor = heuristicGradient.Evaluate(0); b.SetColor(heuristicGradient.Evaluate(0)); break; case HeuristicType.DistanceFromGoal: float startGoalDistance = Vector2.Distance(startCrumb.coordinates, goalCrumb.coordinates); float distance = Vector2.Distance(b.coordinates, goalCrumb.coordinates); b.heuristic = distance; b.initialColor = heuristicGradient.Evaluate(distance / startGoalDistance); b.SetColor(heuristicGradient.Evaluate(distance / startGoalDistance)); break; case HeuristicType.ID: b.heuristic = b.ID; b.initialColor = heuristicGradient.Evaluate((float)b.ID / Breadcrumb.numCrumbs); b.SetColor(heuristicGradient.Evaluate((float)b.ID / Breadcrumb.numCrumbs)); break; case HeuristicType.Random: float randomRange = Random.Range(0, Mathf.Max(xSize, ySize)); b.heuristic = randomRange; b.initialColor = heuristicGradient.Evaluate(randomRange / Mathf.Max(xSize, ySize)); b.SetColor(heuristicGradient.Evaluate(randomRange / Mathf.Max(xSize, ySize))); break; } } }
private void Awake() { pathNode = new List <GameObject>(); connectorLsit = new List <GameObject>(); connectorCostTable = new List <List <float> >(); connectorTable = new List <List <List <GameObject> > >(); FindAllNodes(); FindPathForEachNode(); connectorLsit = connectorLsit.OrderBy(x => x.GetComponent <PathNode>().nodeZone).ToList(); CreateClusterTable(); heuristic = HeuristicType.Euclidean; }
public static IHeuristicEstimate СreateHeuristic(HeuristicType heuristicType, TieBreakerType tieBreaker, Vector2Int startPos, float heuristicCoeff) { switch (heuristicType) { case HeuristicType.Euclidean: return(new EuclideanDistanceHeuristic(СreateTieBraker(tieBreaker, startPos), heuristicCoeff)); case HeuristicType.Manhattan: return(new ManhattanDistanceHeuristic(СreateTieBraker(tieBreaker, startPos), heuristicCoeff)); default: return(new NoneHeuristic()); } }
public void SetHeuristicType(int heuristicType) { if (heuristicType == 0) { this.heuristicType = HeuristicType.Simple; } else if (heuristicType == 1) { this.heuristicType = HeuristicType.Defensive; } else if (heuristicType == 2) { this.heuristicType = HeuristicType.Offensive; } }
public int Evaluation(bool player, HeuristicType heuristicType) { int truePoints = Points(true, heuristicType); if (truePoints >= pointsWin) { return(pointsWin); } int falsePoints = Points(false, heuristicType); if (falsePoints >= pointsWin) { return(-pointsWin); } return(truePoints - falsePoints); }
public static float Heuristic(int playerMoves, int opponentMoves) { HeuristicType hT = GameManager.Instance.heuristicType; if (hT == HeuristicType.Simple) { return(Simple(playerMoves)); } else if (hT == HeuristicType.Defensive) { return(Defensive(playerMoves, opponentMoves)); } else { return(Offensive(playerMoves, opponentMoves)); } }
public static Heuristic Create(HeuristicType type, PAD.Planner.IProblem p) { switch (type) { case HeuristicType.FF: return(new FFHeuristic(p)); case HeuristicType.net: case HeuristicType.sum: case HeuristicType.max: case HeuristicType.min: case HeuristicType.weighted10: case HeuristicType.doubleList: case HeuristicType.domainSolver_NN: default: throw new NotImplementedException(); } }
public void Set(List <GameObject> path, float cost, HeuristicType heuristic) { this.path = path; this.cost = cost; switch (heuristic) { case HeuristicType.Dijkstra: break; case HeuristicType.Euclidean: break; case HeuristicType.Cluster: break; default: break; } }
public int expand(Node p, HeuristicType ht) { Playfield afterState = new Playfield(p.state); ParetoMCTSPlayer m_player = new ParetoMCTSPlayer(new ParetoTreePolicy(0.7), GameManager.getRNG(), afterState, ht); m_player.run(afterState, 30000, false); //m_player.m_root.printStats(); //Helpfunctions.Instance.logg("turn: " + p.state.isOwnTurn); int memberSize = m_player.m_root.pa.m_members.size(); // will it always > 0? for (int i = 0; i < memberSize; i++) // this is other's turn { Node afterNode; Playfield pf = m_player.m_root.pa.m_members.get(i).m_state; if (ht == HeuristicType.DrawCard) { if (pf.moveTrigger.newHandcardList.Count == 0) { continue; } afterNode = new ChanceNode(p, pf, null, p.depth, 1); //last param is wrong pf.printActions(); } else if (ht == HeuristicType.LethalCheck) { if (pf.getLethalScore() == 1.0) { afterNode = new Node(p, pf, null, p.depth + 1); } continue; } else { afterNode = new Node(p, pf, null, p.depth + 1); } p.children.Add(afterNode); } return(p.children.Count); }
//public static readonly string[] heuristicTypes = { "euclidian", "octile", "manhattan" }; public static double GetDistance(double[] coords1, double[] coords2, HeuristicType heuristicType) { // Check that the coordinates are both of the same length if (coords1.Length != coords2.Length) { throw new ArgumentException($"Coordinates must of the same length, but instead are of lengths {coords1.Length} and {coords2.Length}."); } double sum = 0.0; if (heuristicType == HeuristicType.Euclidian) { for (int i = 0; i < coords1.Length; i++) { sum += Math.Pow((coords1[i] - coords2[i]), 2); } return(Math.Sqrt(sum)); } else if (heuristicType == HeuristicType.Octile) { double dx = Math.Abs(coords1[0] - coords2[0]); double dy = Math.Abs(coords1[1] - coords2[1]); return(dx - dy + Math.Sqrt(2) * Math.Min(dx, dy)); } else if (heuristicType == HeuristicType.Manhattan) { for (int i = 0; i < coords1.Length; i++) { sum += Math.Abs(coords1[i] - coords2[i]); } return(sum); } else { throw new ArgumentException($"Unknown distance type requested, must be from among: " + $"{string.Join(", ", (string[])Enum.GetNames(typeof(HeuristicType)))}"); } }
public int Points(bool player, HeuristicType heuristicType) { Func <int, int> evalFunc; switch (heuristicType) { case HeuristicType.CornersRaw: { evalFunc = InRowEval; return(PointsHorizontal(player, evalFunc) + PointsVertical(player, evalFunc) + PointsDiagonalForward(player, evalFunc) + PointsDiagonalBack(player, evalFunc)); } case HeuristicType.NoCornersRaw: { evalFunc = InRowEval; return(PointsHorizontal(player, evalFunc) + PointsVertical(player, evalFunc) + PointsDiagonalForwardNoCorner(player, evalFunc) + PointsDiagonalBackNoCorner(player, evalFunc)); } case HeuristicType.CornersSquare: { evalFunc = InRowEvalSquare; return(PointsHorizontal(player, evalFunc) + PointsVertical(player, evalFunc) + PointsDiagonalForward(player, evalFunc) + PointsDiagonalBack(player, evalFunc)); } case HeuristicType.NoCornersSquare: { evalFunc = InRowEvalSquare; return(PointsHorizontal(player, evalFunc) + PointsVertical(player, evalFunc) + PointsDiagonalForwardNoCorner(player, evalFunc) + PointsDiagonalBackNoCorner(player, evalFunc)); } } return(0); }
private int MinMax(State state, bool player, int depth, ref int selectedCol, HeuristicType heuristicType) { nodesVisited++; int colSelection = state.cols - 1; int stateEval = state.Evaluation(player, heuristicType); if (depth == 0 || stateEval == State.pointsWin || stateEval == -State.pointsWin) { return(stateEval); } int eval = player ? int.MinValue : int.MaxValue; for (int c = 0; c < state.cols; c++) { if (state.CanPlace(c)) { int refNum = 1; int childEval = MinMax(state.NextState(player, c), !player, depth - 1, ref refNum, heuristicType); if ((player && childEval > eval) || (!player && childEval < eval)) { eval = childEval; colSelection = c; } } } if (depth == this.depth) { selectedCol = colSelection; if (!state.CanPlace(colSelection)) { selectedCol = -1; } } return(eval); }
public void SetHeuristicType() { heuristicType = (HeuristicType)heuristicTypeDropdown.value; InitializeHeuristics(heuristicType); }
public State AiMove(AiEngine aiEngine, State state, bool player, MethodType methodType, HeuristicType heuristicType) { int nodes; int aiMove = aiEngine.GetMove(state, player, methodType, heuristicType, out nodes); if (player) { ai2Nodes += nodes; } else { ai1Nodes += nodes; } return(state.NextState(player, aiMove)); }
//public ParetoMCTSPlayer(ParetoTreePolicy a_treePolicy, HeuristicMO a_h, Random a_rnd, Game a_game, PlayoutInfo pInfo) //{ // m_playoutInfo = pInfo; // //m_heightMap = new int[a_game.getMap().getMapWidth()][a_game.getMap().getMapHeight()]; // m_heuristic = a_h; // m_heuristic.setPlayoutInfo(m_playoutInfo); // m_treePolicy = a_treePolicy; // this.m_rnd = a_rnd; // this.m_targetWeights = ParetoMCTSParameters.targetWeights; // m_globalPA = new ParetoArchive(); // m_randomRoller = new RandomRoller(RandomRoller.RANDOM_ROLLOUT, this.m_rnd, ParetoMCTSParameters.NUM_ACTIONS); // m_root = new ParetoTreeNode(null, m_randomRoller, m_treePolicy, m_rnd, this, m_playoutInfo); // this.m_numCalls = 0; // this.m_numIters = 0; //} public ParetoMCTSPlayer(ParetoTreePolicy a_treePolicy, Random a_rnd, Playfield a_game, HeuristicType _ht) { //m_playoutInfo = pInfo; ////m_heightMap = new int[a_game.getMap().getMapWidth()][a_game.getMap().getMapHeight()]; //m_heuristic = a_h; //m_heuristic.setPlayoutInfo(m_playoutInfo); m_treePolicy = a_treePolicy; this.m_rnd = a_rnd; this.m_targetWeights = ParetoMCTSParameters.targetWeights; m_globalPA = new ParetoArchive(); m_randomRoller = new RandomRoller(RandomRoller.RANDOM_ROLLOUT, this.m_rnd, ParetoMCTSParameters.NUM_ACTIONS); //m_root = new ParetoTreeNode(null, m_randomRoller, m_treePolicy, m_rnd, this, m_playoutInfo); m_root = new ParetoTreeNode(a_game, null, -1, m_randomRoller, m_treePolicy, m_rnd, this); this.m_numCalls = 0; this.m_numIters = 0; m_runList = new List <ParetoTreeNode>(); heuristicType = _ht; ////bounds[0][0] = -Math.Sqrt(8) * 8 * 8; //bounds[0][0] = 0; //bounds[0][1] = Math.Sqrt(8) * 8 * 8 * 2; ////bounds[1][0] = -Math.Sqrt(8) * 8 * 8; //bounds[1][0] = 0; //bounds[1][1] = Math.Sqrt(8) * 8 * 8; ////bounds[2][0] = -10 * 10; ////bounds[2][1] = 10 * 10; ////bounds[2][0] = -Math.Sqrt(8) * 8 * 10; //bounds[2][0] = 0; //bounds[2][1] = Math.Sqrt(8) * 8 * 10 * 2; switch (this.heuristicType) { case HeuristicType.Boardvalue: bounds = new double[3][]; bounds[0] = new double[2]; bounds[1] = new double[2]; bounds[2] = new double[2]; //bounds[0][0] = -Math.Sqrt(8) * 8 * 8; bounds[0][0] = 0; bounds[0][1] = 1f; //bounds[1][0] = -Math.Sqrt(8) * 8 * 8; bounds[1][0] = 0; bounds[1][1] = 1f; //bounds[2][0] = -10 * 10; //bounds[2][1] = 10 * 10; //bounds[2][0] = -Math.Sqrt(8) * 8 * 10; bounds[2][0] = 0; bounds[2][1] = 1f; break; case HeuristicType.LethalCheck: bounds = new double[1][]; bounds[0] = new double[2]; bounds[0][0] = 0; bounds[0][1] = 1f; break; case HeuristicType.DrawCard: bounds = new double[2][]; bounds[0] = new double[2]; bounds[1] = new double[2]; bounds[0][0] = 0; bounds[0][1] = 1f; bounds[1][0] = 0; bounds[1][1] = 1f; initNewCardCount = m_root.state.moveTrigger.newHandcardList.Count; break; } }
private async void start_button_Click(object sender, EventArgs e) { this.results_button.Visible = false; this.puzzletype_comboBox.Enabled = false; this.heuristics_comboBox.Enabled = false; this.start_button.Enabled = false; this.stop_button.Enabled = true; this.loading_panel.Visible = true; this.error_message.Visible = false; PuzzleType type = puzzletype_comboBox.SelectedItem as PuzzleType; HeuristicType heuristic = heuristics_comboBox.SelectedItem as HeuristicType; int[,] initial = new int[type.N, type.N]; // prepare initial state foreach (Control item in puzzle_panel.Controls.OfType <NumericUpDown>()) { item.Enabled = false; string location = item.Name.Replace("i_", ""); int i = int.Parse(location.Split(',')[0]); int j = int.Parse(location.Split(',')[1]); if (string.IsNullOrEmpty(item.Text)) { initial[i, j] = 0; } else { initial[i, j] = int.Parse(item.Text); } } Puzzle initialState = new Puzzle(initial); int[,] goal = new int[type.N, type.N]; // prepare goal state foreach (Control item in goal_panel.Controls.OfType <NumericUpDown>()) { item.Enabled = false; string location = item.Name.Replace("g_", ""); int i = int.Parse(location.Split(',')[0]); int j = int.Parse(location.Split(',')[1]); if (string.IsNullOrEmpty(item.Text)) { goal[i, j] = 0; } else { goal[i, j] = int.Parse(item.Text); } } Puzzle goalState = new Puzzle(goal); try { AStar aStar = new AStar(initialState, goalState); Result result = await Task.Run(() => aStar.Run(cts.Token, (Heuristic)heuristic.ID)); this.results_button.Visible = true; this.results_panel.Visible = true; this.main_panel.Visible = false; this.aboutSoftware_panel.Visible = false; this.closed_textBox.Text = result.Closed.ToString(); this.open_textbox.Text = result.Open.ToString(); Dictionary <int, List <Branch> > tree = new Dictionary <int, List <Branch> >(); foreach (var item in result.Path) { if (tree.ContainsKey(item.G)) { tree[item.G].Add(item); } else { tree.Add(item.G, new List <Branch> { item }); } } Display(tree, results_textBox); } catch (OperationCanceledException) { cts = new CancellationTokenSource(); } catch (Exception ex) { this.error_message.Text = "Błąd: " + ex.Message; this.error_message.Visible = true; } finally { this.loading_panel.Visible = false; this.puzzletype_comboBox.Enabled = true; this.heuristics_comboBox.Enabled = true; this.start_button.Enabled = true; this.stop_button.Enabled = false; foreach (Control item in puzzle_panel.Controls.OfType <NumericUpDown>()) { item.Enabled = true; } foreach (Control item in goal_panel.Controls.OfType <NumericUpDown>()) { item.Enabled = true; } } }
public AStar(Grid grid, DiagonalMovement diagonalMovement, HeuristicType heuristictType) { this.grid = grid; this.diagonalMovement = diagonalMovement; }
public int expand(Node p, HeuristicType ht, int numberIter) { Playfield afterState = new Playfield(p.state); ParetoMCTSPlayer m_player = new ParetoMCTSPlayer(new ParetoTreePolicy(0.7), GameManager.getRNG(), afterState, ht); m_player.run(afterState, numberIter, false); //m_player.m_root.printStats(); //Helpfunctions.Instance.logg("turn: " + p.state.isOwnTurn); int memberSize = m_player.m_root.pa.m_members.size(); // will it always > 0? //if (ht == HeuristicType.Boardvalue) // m_player.m_root.pa.printArchive(); if (ht == HeuristicType.DrawCard) { Console.WriteLine("chance: " + memberSize); if (memberSize > 1) { chanceCount += memberSize - 1; } m_player.m_root.pa.printArchive(); } for (int i = 0; i < memberSize; i++) // this is other's turn { Node afterNode; Playfield pf = m_player.m_root.pa.m_members.get(i).m_state; if (ht == HeuristicType.DrawCard) { if (pf.moveTrigger.newHandcardList.Count == 0) { continue; } if ((pf.isOwnTurn && pf.homeDeck.Count > 0) || (!pf.isOwnTurn && pf.awayDeck.Count > 0)) { List <Action> actionList = pf.getActions(); Playfield tempPf = new Playfield(afterState); for (int j = tempPf.getActions().Count; j < actionList.Count - 1; j++) { tempPf.doAction(actionList[j]); } afterNode = new ChanceNode(p, tempPf, actionList[actionList.Count - 1], p.depth, pf.moveTrigger.newHandcardList.Count); } else { afterNode = new Node(p, pf, null, p.depth); } if (memberSize > 1) { pf.printActions(); } //pf.printActions(); } else if (ht == HeuristicType.LethalCheck) { if (pf.getLethalScore() == 1.0) { afterNode = new Node(p, pf, null, p.depth + 1); } continue; } else { if ((pf.isOwnTurn && pf.homeDeck.Count > 0) || (!pf.isOwnTurn && pf.awayDeck.Count > 0)) { afterNode = new ChanceNode(p, pf, null, p.depth + 1, 1); } else { pf.drawTurnStartCard(); afterNode = new Node(p, pf, null, p.depth + 1); } } p.children.Add(afterNode); } return(p.children.Count); }
public List <Waypoint> GetShortestPath(Waypoint startPoint, Waypoint endPoint, HeuristicType h) { if (startPoint == null || endPoint == null) { return(null); } if (startPoint.transform.position == endPoint.transform.position) { return(null); } //initialize empty list, to become the path List <Waypoint> path = new List <Waypoint>(); Waypoint currentPoint = startPoint; // <- begin path here allPoints = GameObject.FindObjectsOfType <Waypoint>(); foreach (Waypoint q in allPoints) { q.visited = false; } float[] distances = new float[allPoints.Length]; Waypoint[] previousPoints = new Waypoint[allPoints.Length]; List <Waypoint> unvisitedPoints = new List <Waypoint>(); for (int i = 0; i < allPoints.Length; i++) { if (allPoints[i].walkable && allPoints[i].walkableForCat) //only consider points that cat can traverse! { if (allPoints[i].gameObject.name == startPoint.gameObject.name) { allPoints[i].distance = 0; //distance between start point and itself is 0 } else { allPoints[i].distance = float.MaxValue; //distance unknown at start for everywhere else } allPoints[i].previous = null; unvisitedPoints.Add(allPoints[i]); } } while (unvisitedPoints.Count > 0) //while unvisited points list not empty { Waypoint closest = GetClosestWaypointTo(startPoint, unvisitedPoints); //compute heuristic here, if necessary float heuristic = 0; //default heuristic input to 0 if (heuristicToUse == HeuristicType.EUCLIDEAN) { float dx = Mathf.Abs(closest.transform.position.x - endPoint.transform.position.x); float dz = Mathf.Abs(closest.transform.position.z - endPoint.transform.position.z); heuristic = gridSpacing * Mathf.Sqrt(dx * dx + dz * dz); //distance of 4 between each individual tile } for (int j = 0; j < closest.nearestNeighbors.Count; j++) { float alt = closest.distance + Vector3.Distance (closest.transform.position, closest.nearestNeighbors[j].transform.position) + heuristic; if (alt < closest.nearestNeighbors[j].distance) { closest.nearestNeighbors[j].distance = alt; closest.nearestNeighbors[j].previous = closest; if (showFill) //rest of the fill, outside of final path { closest.nearestNeighbors[j].transform.GetComponent <Waypoint>().Highlight (highlightColor); } } } unvisitedPoints = RemoveWaypointFromList(unvisitedPoints, closest.GetId()); closest.visited = true; } //build path using dijkstra's algorithm information, //walking back from end point to start point //therefore, start at end point path.Add(endPoint); if (showFill) { endPoint.Highlight(pathColor); } Waypoint previousPoint = endPoint.previous; path.Add(previousPoint); if (showFill) { previousPoint.Highlight(pathColor); } while (previousPoint != null && (previousPoint.GetId() != startPoint.GetId())) { previousPoint = previousPoint.previous; path.Add(previousPoint); if (showFill) { previousPoint.Highlight(pathColor); } } //reverse path to have order be from start to end path.Reverse(); return(path); }
public static IRubikHeuristic GetHeuristic(HeuristicType heuristicType) { return(Heuristics[heuristicType]); }
public void OnHeuristicDropdownValueChange(int index) { heuristicType = (HeuristicType)index; }