Title: On names and parameter orders of coodinates · Issue #50 · brean/python-pathfinding · GitHub
Open Graph Title: On names and parameter orders of coodinates · Issue #50 · brean/python-pathfinding
X Title: On names and parameter orders of coodinates · Issue #50 · brean/python-pathfinding
Description: Hi, It is my first time to use python-pathfinding, it's nice but sth make me confused... To be brief, I am writing a bot to play a game, this is what I try to do tonight: def ParseMap(map:List[Map]) -> (List[List[Map]], List[List[List[tu...
Open Graph Description: Hi, It is my first time to use python-pathfinding, it's nice but sth make me confused... To be brief, I am writing a bot to play a game, this is what I try to do tonight: def ParseMap(map:List[Map]...
X Description: Hi, It is my first time to use python-pathfinding, it's nice but sth make me confused... To be brief, I am writing a bot to play a game, this is what I try to do tonight: def ParseMap(map:List[...
Opengraph URL: https://github.com/brean/python-pathfinding/issues/50
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"On names and parameter orders of coodinates","articleBody":"Hi,\r\nIt is my first time to use python-pathfinding, it's nice but sth make me confused...\r\nTo be brief, I am writing a bot to play a game, this is what I try to do tonight:\r\n```python\r\n def ParseMap(map:List[Map]) -\u003e (List[List[Map]], List[List[List[tuple]]], tuple):\r\n parsedMap = [[Map() for i in range(MapEdgeLength)] for j in range(MapEdgeLength)]\r\n paths = [[[] for i in range(MapEdgeLength)] for j in range(MapEdgeLength)]\r\n accessableNow = [[1 for i in range(MapEdgeLength)] for j in range(MapEdgeLength)]\r\n playerPosition = None\r\n for grid in map:\r\n parsedMap[grid.x][grid.y] = grid\r\n for obj in grid.objs:\r\n if obj.type == ObjType.Player and obj.property.player_id != gContext[\"playerID\"] and playerPosition is None:\r\n playerPosition = (grid.x, grid.y)\r\n if obj.type == ObjType.Block or obj.type == ObjType.Bomb:\r\n accessableNow[grid.x][grid.y] = 0 # (a)\r\n # pfGrid: an abbreviation of pathfinding grid\r\n pfGrid = Grid(matrix=accessableNow)\r\n for grid in map:\r\n pfGrid.cleanup()\r\n finder = AStarFinder(diagonal_movement=DiagonalMovement.never)\r\n newPath, _ = finder.find_path(pfGrid.node(playerPosition[0], playerPosition[1]),\r\n pfGrid.node(grid.x, grid.y, pfGrid) #(b)\r\n myNewPath = [(newPath[i].x, newPath[i].y) for i in range(len(newPath))]\r\n paths[grid.x][grid.y] = myNewPath\r\n return parsedMap, paths, playerPosition\r\n```\r\nSome names of variables in the code above are provided by the organizer of the contest I am taking part in. \r\nMy code above failed to get correct answer until I rewite `(a)` as:\r\n```python\r\n accessableNow[grid.y][grid.x] = 0\r\n```\r\nor rewrite `(b)` as:\r\n```python\r\n newPath, _ = finder.find_path(pfGrid.node(playerPosition[1], playerPosition[0]),\r\n pfGrid.node(grid.y, grid.x, pfGrid) #(b)\r\n```\r\nLater, I refer to the `docs` but find nothing about parameter order.\r\nAs I look into the grid.py i found:\r\n```python\r\n def node(self, x, y) -\u003e GridNode:\r\n \"\"\"\r\n get node at position\r\n :param x: x pos\r\n :param y: y pos\r\n :return:\r\n \"\"\"\r\n return self.nodes[y][x]\r\n```\r\nBelow is what I suggest: Rearrangeing parameters `x` and `y` as the order they appear in the List indexes:\r\n```python\r\n def node(self, y, x) -\u003e GridNode:\r\n return self.nodes[y][x]\r\n```\r\nor rename them to the form `xi` where `i` is the order they appear in the indexes:\r\n```python\r\n def node(self, x1, x2) -\u003e GridNode:\r\n return self.nodes[x1][x2]\r\n```\r\nso that People who use the `pathfinding` can access a `node` not according to a specific name convention, but the order they pass parameters to these functions before. ","author":{"url":"https://github.com/XinyiLiu577086410","@type":"Person","name":"XinyiLiu577086410"},"datePublished":"2023-11-17T15:47:25.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/50/python-pathfinding/issues/50"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:48bb05bd-a705-7e60-1138-58feb443c66e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8E2E:245634:45036:5796A:698D2421 |
| html-safe-nonce | b76a6a2341347e5ea5bdcbe3b7178067bce0b80e48ed96b4453e84197451b39b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RTJFOjI0NTYzNDo0NTAzNjo1Nzk2QTo2OThEMjQyMSIsInZpc2l0b3JfaWQiOiI0MjAzNzMwMzgxMjQzNzUzNTA1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d51fe7773b7e156c816f20f88d89c20dc6dcaa3e3cfa50956d79b927d4d22c38 |
| hovercard-subject-tag | issue:1999423382 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/brean/python-pathfinding/50/issue_layout |
| twitter:image | https://opengraph.githubassets.com/796ae1cf2aad05876ea574e1e2dcfd84679d71b1552b5f732eb423d84e6db049/brean/python-pathfinding/issues/50 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/796ae1cf2aad05876ea574e1e2dcfd84679d71b1552b5f732eb423d84e6db049/brean/python-pathfinding/issues/50 |
| og:image:alt | Hi, It is my first time to use python-pathfinding, it's nice but sth make me confused... To be brief, I am writing a bot to play a game, this is what I try to do tonight: def ParseMap(map:List[Map]... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | XinyiLiu577086410 |
| hostname | github.com |
| expected-hostname | github.com |
| None | c25395580e1e3bf82d705e0982a1b24255366088720fef945f1493d5e3e67954 |
| turbo-cache-control | no-preview |
| go-import | github.com/brean/python-pathfinding git https://github.com/brean/python-pathfinding.git |
| octolytics-dimension-user_id | 229768 |
| octolytics-dimension-user_login | brean |
| octolytics-dimension-repository_id | 32716626 |
| octolytics-dimension-repository_nwo | brean/python-pathfinding |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 32716626 |
| octolytics-dimension-repository_network_root_nwo | brean/python-pathfinding |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 1fa2bc33fc715bfb2cb9dd8a9cad4f811c16c371 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width