构建可移动路径图
(bdsize: u32)
| 113 | |
| 114 | // 构建可移动路径图 |
| 115 | fn build_knight_graph(bdsize: u32) -> Graph<u32> { |
| 116 | // 闭包函数,计算点值 [0, 63] |
| 117 | let calc_point = |row: u32, col: u32, size: u32| { |
| 118 | (row % size) * size + col |
| 119 | }; |
| 120 | |
| 121 | // 各点间设置边 |
| 122 | let mut knight_graph = Graph::new(); |
| 123 | for row in 0..bdsize { |
| 124 | for col in 0..bdsize { |
| 125 | let dests = legal_moves(row, col, bdsize); |
| 126 | for des in dests { |
| 127 | let src_p = calc_point(row, col, bdsize); |
| 128 | let des_p = calc_point(des.0, des.1, bdsize); |
| 129 | knight_graph.add_edge(&src_p, &des_p); |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | knight_graph |
| 135 | } |
| 136 | |
| 137 | // depth: 走过的路径长度, curr: 当前节点, path: 保存访问过的点 |
| 138 | fn knight_tour<T>( |
no test coverage detected