程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> x01.Weiqi.10: 死活問題,x01.Weiqi.10:問題

x01.Weiqi.10: 死活問題,x01.Weiqi.10:問題

編輯:C#入門知識

x01.Weiqi.10: 死活問題,x01.Weiqi.10:問題


估計得不錯,點目後,僅一個方法:UpdateMeshes5() 就完美解決了梅花六、刀把五、斗笠四、盤角曲四等死活問題。先來看看效果圖:

            

其代碼如下:

1 void UpdateMeshes5(bool isFirst = true) 2 { 3 UpdateAllMeshBlocks(); 4 5 m_BlackMeshBlocks.ForEach(block => { 6 var poses = block.Poses.ToList(); 7 block.Poses.ForEach(p => { 8 if (BlackPoses.Contains(p)) 9 poses.Remove(p); 10 LinkPoses(p).ForEach(l => { 11 if (m_WhiteMeshes.Contains(l)) 12 poses.Remove(p); 13 }); 14 }); 15 16 if (poses.Count == 6) { 17 poses.ForEach(p => { 18 var links = LinkPoses(p); 19 if (links.Intersect(poses).Count() == 5) { // 梅花六 20 var tmp = poses.Except(links).ToList(); 21 if (IsCusp(tmp[0], p)) { 22 block.IsDead = true; 23 block.KeyPos = p; 24 } 25 } 26 }); 27 } else if (poses.Count == 5) { 28 poses.ForEach(p => { 29 var links = LinkPoses(p); 30 if (links.Intersect(poses).Count() == 4) { // 刀把五 31 var tmp = poses.Except(links).ToList(); 32 if (IsCusp(tmp[0], p)) { 33 block.IsDead = true; 34 block.KeyPos = p; 35 } 36 } 37 }); 38 } else if (poses.Count == 4) { 39 poses.ForEach(p => { 40 var links = LinkPoses(p); 41 if (links.Intersect(poses).Count() == 4) { // 斗笠四 42 block.IsDead = true; 43 block.KeyPos = p; 44 } else if (links.Intersect(poses).Count() == 3 // 盤角曲四 45 && (p == new Pos(0, 0) || p == new Pos(0, 18) || p == new Pos(18, 0) || p == new Pos(18, 18))) { 46 block.IsDead = true; 47 } 48 }); 49 } else if (poses.Count == 3) { 50 poses.ForEach(p => { 51 var links = LinkPoses(p); 52 if (links.Intersect(poses).Count() == 3) { // 直三、曲三 53 block.IsDead = true; 54 block.KeyPos = p; 55 } 56 }); 57 } else if (poses.Count == 2) { 58 poses.ForEach(p => { 59 var links = LinkPoses(p); 60 if (links.Intersect(poses).Count() == 2) { 61 block.IsDead = true; 62 } 63 }); 64 } else if (poses.Count < 2) { 65 block.IsDead = true; 66 } 67 68 if (!isFirst && block.IsDead) { 69 m_BlackMeshes.RemoveAll(b => block.Poses.Contains(b)); 70 m_WhiteMeshes.AddRange(block.Poses); 71 } 72 }); 73 74 m_WhiteMeshBlocks.ForEach(block => { 75 var poses = block.Poses.ToList(); 76 block.Poses.ForEach(p => { 77 if (WhitePoses.Contains(p)) 78 poses.Remove(p); 79 LinkPoses(p).ForEach(l => { 80 if (m_BlackMeshes.Contains(l)) 81 poses.Remove(p); 82 }); 83 }); 84 if (poses.Count == 6) { 85 poses.ForEach(p => { 86 var links = LinkPoses(p); 87 if (links.Intersect(poses).Count() == 5) { // 梅花六 88 var tmp = poses.Except(links).ToList(); 89 if (IsCusp(tmp[0], p)) { 90 block.IsDead = true; 91 block.KeyPos = p; 92 } 93 } 94 }); 95 } else if (poses.Count == 5) { 96 poses.ForEach(p => { 97 var links = LinkPoses(p); 98 if (links.Intersect(poses).Count() == 4) { // 刀把五 99 var tmp = poses.Except(links).ToList(); 100 if (IsCusp(tmp[0], p)) { 101 block.IsDead = true; 102 block.KeyPos = p; 103 } 104 } 105 }); 106 } else if (poses.Count == 4) { 107 poses.ForEach(p => { 108 var links = LinkPoses(p); 109 if (links.Intersect(poses).Count() == 4) { // 斗笠四 110 block.IsDead = true; 111 block.KeyPos = p; 112 } else if (links.Intersect(poses).Count() == 3 // 盤角曲四 113 && (p == new Pos(0, 0) || p == new Pos(0, 18) || p == new Pos(18, 0) || p == new Pos(18, 18))) { 114 block.IsDead = true; 115 } 116 }); 117 } else if (poses.Count == 3) { 118 poses.ForEach(p => { 119 var links = LinkPoses(p); 120 if (links.Intersect(poses).Count() == 3) { // 直三、曲三 121 block.IsDead = true; 122 block.KeyPos = p; 123 } 124 }); 125 } else if (poses.Count == 2) { 126 poses.ForEach(p => { 127 var links = LinkPoses(p); 128 if (links.Intersect(poses).Count() == 2) { 129 block.IsDead = true; 130 } 131 }); 132 } else if (poses.Count < 2) { 133 block.IsDead = true; 134 } 135 136 if (!isFirst && block.IsDead) { 137 m_WhiteMeshes.RemoveAll(b => block.Poses.Contains(b)); 138 m_BlackMeshes.AddRange(block.Poses); 139 } 140 }); 141 142 if (isFirst) { 143 m_BlackMeshBlocks.ForEach(block => { 144 if (block.IsDead) { 145 foreach (var pos in block.Poses) { 146 var links = LinkPoses(pos); 147 m_WhiteMeshBlocks.ForEach(w_block => { 148 if (links.Intersect(w_block.Poses).Count() > 0) { 149 if (w_block.IsDead) { 150 BlackPosBlocks.ForEach(bp_block => { 151 if (bp_block.Poses.Contains(pos)) { 152 block.EmptyCount = bp_block.EmptyCount; 153 } 154 WhitePosBlocks.ForEach(wp_block => { 155 if (wp_block.Poses.Intersect(w_block.Poses).Count() > 0) { 156 w_block.EmptyCount = wp_block.EmptyCount; 157 } 158 }); 159 }); 160 if (block.EmptyCount > w_block.EmptyCount) { 161 m_WhiteMeshes.RemoveAll(w => w_block.Poses.Contains(w)); 162 m_BlackMeshes.AddRange(w_block.Poses); 163 } else if (block.EmptyCount < w_block.EmptyCount) { 164 m_BlackMeshes.RemoveAll(b => block.Poses.Contains(b)); 165 m_WhiteMeshes.AddRange(block.Poses); 166 } 167 } 168 } 169 }); 170 } 171 } 172 }); 173 } 174 175 UpdateMeshColors(); 176 } UpdateMeshes5()

因為涉及到比氣問題,所以要調用兩次。這又是多遍掃描的應有之意,相信已經見怪不怪了。

最新代碼下載鏈接:https://github.com/chinax01/x01.Weiqi

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved