MCPcopy Create free account
hub / github.com/QMHTMY/RustBook / main

Function main

code/chapter08/kinght_tour.rs:182–204  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

180}
181
182fn main() {
183 // 构建骑士旅游图
184 let mut kg: Graph<u32> = build_knight_graph(BDSIZE);
185
186 // 选择起始点并更新图中点颜色
187 let point = 0;
188 kg.vertices.get_mut(&point).unwrap().color = Color::Gray;
189 let start = kg.vertices.get(&point).unwrap().clone();
190
191 // 开始骑士之旅,path 保存所有访问过的点
192 let mut path = Vec::new();
193 let successed = knight_tour(&mut kg, start, &mut path, 0);
194
195 // 将结果格式化输出
196 if successed {
197 for row in 0..BDSIZE {
198 let row_s = ((row % BDSIZE) * BDSIZE) as usize;
199 let row_e = row_s + BDSIZE as usize;
200 let row_str = path[row_s..row_e].join("\t");
201 println!("{row_str}");
202 }
203 }
204}

Callers

nothing calls this directly

Calls 4

build_knight_graphFunction · 0.70
knight_tourFunction · 0.70
get_mutMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected