Skip to main content

r/programminghelp


How to convert an A* path (vector of coordinates) into a movement string like "^^>>>>>>>>" in C++?
How to convert an A* path (vector of coordinates) into a movement string like "^^>>>>>>>>" in C++?
Project Related

I'm developing an A* path router in C++ for an academic project. The router reads a netlist from a netlist.cpp file, finds paths on a 2D grid using A* (Manhattan heuristic, 4‑directional moves), and marks the paths on the grid.

What I have so far:

  • RoteadorAstar class with a working A* algorithm.

  • Netlist loading via #include "netlist.cpp".

  • Multi‑net routing with grid updates.

  • Console printing of the final grid.

The next step (second part of the assignment):

I need to generate a textual output file (e.g., .txt) that records all routed paths. The suggested format by my professor is:

start_x,start_y, "movement_string"

where the movement string uses:

  • ^ = up (decrease x)

  • v = down (increase x)

  • < = left (decrease y)

  • > = right (increase y)

For example, a path from (2,2) that goes up twice and then right 8 steps would be written as:

2,2, "^^>>>>>>>>"

I need to compute the direction between consecutive points and then group consecutive identical moves into a count (or just repeat the character). A naïve repetition is fine.

Any code snippets or design suggestions for generating this textual output would be greatly appreciated. Thank you!

My Project Code


Advertisement: Shop top electronics at Amazon! Find the latest tech, trending gadgets, and top rated devices today.
Shop top electronics at Amazon! Find the latest tech, trending gadgets, and top rated devices today.
  • msi Modern AM242TP 23.8" FHD Touchscreen All-in-One Desktop, Intel Core 7-150U, 16GB DDR5, 1TB SSD+1TB HDD, FHD Camera, Wi-Fi 6E, Wireless Keyboard &
  • HP Desktop PC Elite SFF G9| 6-core 5GHz Ryzen-5 Processor(1.3 Times Faster Than Intel i7-1255U) | 16GB DDR5 RAM, 1TB SSD| WiFi| Bluetooth| HDMI, USB,
  • HP OmniDesk M03 Business Next Gen AI PC Desktop, Intel Core Ultra 5-225 Processor (10 Cores, Up to 4.9GHz), 16GB DDR5 RAM, 1TB SSD, USB-C, Wi-Fi 6,
  • Dell Precision 5820 Workstation Tower CTO (Renewed)
  • 128GB 8X16GB DDR5 6400MHZ PC5-51200 CL52 1Rx8 1.1V 288-PIN ECC Registered RDIMM NEMIX RAM Server Memory KIT Compatible with ASRock Rack W890D8-2L2T
  • APC 0M-816336 Compatible Replacement Battery Pack by UPSBatteryCenter