当前位置: 代码迷 >> C# >> x01.Weiqi.10: 死活有关问题
  详细解决方案

x01.Weiqi.10: 死活有关问题

热度:49   发布时间:2016-05-05 03:41:08.0
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