The provided C++ program implements a strategy controller for a grid-based logistics simulation (the Huawei CodeCraft 2024 competition). It reads a 200x200 map, tracks robots, berths, boats, and goods, and issues movement/operation commands each frame ("zhen"). The logic focuses on path precomputation, greedy goods collection, and berth/boat dispatching to maximize transported value within a time limit. The program runs for 15,000 frames and outputs commands for robots/boats each frame. 【F:original_code.cpp†L1-L870】
- Global configuration and state: Defines map size, robot/berth counts, map grid, robot occupancy, berth availability, and data structures for pathfinding and assignments. 【F:original_code.cpp†L1-L87】
- Robots and boats:
Robothandles movement and pickup/drop commands;Boathandles docking/transport state. 【F:original_code.cpp†L45-L137】 - Berths:
Berthhandles dock edge calculation, boat registration, and loading goods onto boats. 【F:original_code.cpp†L139-L198】 - Goods tracking:
Goodsstores value/time-to-live, and a lock system to prevent multiple robots from targeting the same goods. 【F:original_code.cpp†L200-L262】 - Pathfinding helpers: BFS-style search for goods; precomputed shortest paths from each cell to each berth to speed navigation. The A* implementation is present but commented out. 【F:original_code.cpp†L271-L534】
- Dispatch logic:
- Robots select nearby high-value goods, then carry them to the nearest berth (precomputed). 【F:original_code.cpp†L537-L654】
- Boats decide whether to stay, move to another berth, or return to base based on capacity, time remaining, and berth stock. 【F:original_code.cpp†L656-L772】
- Initialization and I/O: Parses the map, initializes berth edges and routing tables, then loops through frames, reading inputs and outputting commands. 【F:original_code.cpp†L775-L870】
original_code.cpp: The exact original source provided by the user. 【F:original_code.cpp†L1-L870】updated_code.cpp: A lightly updated version that fixes a logical bug (assignment used instead of comparison when building berth connectivity) and adds clarifying comments without changing overall behavior. 【F:updated_code.cpp†L1-L880】
- 寻找算法:以 BFS 扩散出货物候选,筛掉将过期货物,再从候选中选“价值最高”的。
- 船只逻辑:船满或时间不足就走;港口没货就转港,否则留港装货。
- 机器人逻辑:空手找高价值货物,拿到后送最近港口;交货后继续找货。