x01.Weiqi.9: 點目功能,x01.weiqi.9功能
添加點目功能,雖不中,不遠也。還是先看看截圖吧。

確保其可行,再看一張:

其點目結果,還是比較令人滿意的。這主要得益於多遍掃描,如編譯器的詞法分析階段,下面的代碼可以證明:

![]()
1 private void InitMeshes()
2 {
3 UpdateMeshes1();
4
5 if (StepCount < 120) return;
6
7 UpdateMeshes2();
8 UpdateMeshes3();
9 UpdateMeshes4(5);
10 UpdateMeshes4(8); // 二次掃描有必要
11 UpdateMeshes5();
12 UpdateMeshes6();
13 }
InitMeshes()
主要思路,也不過如此,實現的關鍵點,在於 UpdateMeshBlocks() 方法:

![]()
1 void UpdateMeshBlocks(List<Pos> poses, List<PosBlock> blocks)
2 {
3 List<Pos> copyPoses = poses.ToList();
4 if (copyPoses.Count == 0) return;
5
6 List<Pos> tmp = new List<Pos>();
7 foreach (var pos in copyPoses) {
8 if (tmp.Count == 0) tmp.Add(pos);
9 var links = LinkPoses(pos);
10 if (tmp.Intersect(links).Count() > 0) {
11 links.ForEach(l => {
12 if (copyPoses.Contains(l) && !tmp.Contains(l))
13 tmp.Add(l);
14 });
15 }
16 }
17 for (int i = 0; i < 4; i++) { // 確保不遺漏到瘋狂程度
18 foreach (var pos in copyPoses) {
19 var links = LinkPoses(pos);
20 if (tmp.Intersect(links).Count() > 0) {
21 links.ForEach(l => {
22 if (copyPoses.Contains(l) && !tmp.Contains(l))
23 tmp.Add(l);
24 });
25 }
26 }
27 }
28
29 PosBlock block = new PosBlock();
30 block.Poses = tmp;
31 blocks.Add(block);
32
33 copyPoses.RemoveAll(p => tmp.Contains(p));
34 UpdateMeshBlocks(copyPoses, blocks);
35 }
UpdaeMeshBlocks()
這同 UpdateStepBlocks() 相同,只是為確保不遺漏,多了幾遍而已。
整個程序都是建立在集合的基礎上的,更新塊成為關鍵,也就不足為奇了。
完整代碼下載鏈接:https://github.com/chinax01/x01.Weiqi