Skip to content

Conversation

@Shom770
Copy link
Member

@Shom770 Shom770 commented Nov 25, 2023

Uses a starting position and ending position (Pose2d objects) with a grid given (a 2D list of Pose2d objects) to find the most optimal path between the starting position and the ending position.


val newNode = Node(currentNode, grid[newY][newX])
newNode.g = currentNode.g + 1
newNode.h =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

manhattan distance might be a better heuristic to use here

) { // Keep running until all the nodes are visited. In that case, no optimal path is
// found.
currentNode =
openList.minByOrNull { it.f } ?: openList.last() // Find the node with the lowest cost.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your openList should be a priority queue supported by a minheap -- will notice a performance difference for larger open lists

newNode.f = newNode.g + newNode.h

// Discard node if it means going over the charge station.
if ((newNode.position.x - currentNode.position.x).absoluteValue.inMeters >= 10) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old game so understandable but i think you want to construct your graph so that this isn't even a possibility. think about an actual graph, it can only follow edges that exist, an edge that goes over the charge station shouldn't exist


import org.team4099.lib.geometry.Pose2d
import org.team4099.lib.units.base.inMeters
import kotlin.math.pow
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does our value class not have a pow function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants