{"id":21690523,"url":"https://github.com/oli51467/go-datastructure","last_synced_at":"2025-04-12T09:40:57.036Z","repository":{"id":65304955,"uuid":"525020731","full_name":"Oli51467/go-datastructure","owner":"Oli51467","description":"围棋数据结构及其规则与状态判断逻辑实现","archived":false,"fork":false,"pushed_at":"2023-09-21T02:40:32.000Z","size":77,"stargazers_count":15,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-26T04:35:20.971Z","etag":null,"topics":["go","goban","gogame","java"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Oli51467.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-08-15T14:34:11.000Z","updated_at":"2025-03-16T06:05:18.000Z","dependencies_parsed_at":"2023-09-21T15:27:44.591Z","dependency_job_id":null,"html_url":"https://github.com/Oli51467/go-datastructure","commit_stats":null,"previous_names":["oli51467/go-datastructure"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oli51467%2Fgo-datastructure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oli51467%2Fgo-datastructure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oli51467%2Fgo-datastructure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oli51467%2Fgo-datastructure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Oli51467","download_url":"https://codeload.github.com/Oli51467/go-datastructure/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248549003,"owners_count":21122810,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","goban","gogame","java"],"created_at":"2024-11-25T17:31:40.506Z","updated_at":"2025-04-12T09:40:57.012Z","avatar_url":"https://github.com/Oli51467.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"### 基本规则\n\n下棋时，对弈双方各执一种颜色的棋子，黑先白后，轮流将一枚棋子放置于交叉点上。与棋子直线相连的空白交叉点叫做气。当这些气都被对方棋子占据后，该棋子就没有了“气”，要被从棋盘上提掉。\n\n如果棋子的相邻（仅上下左右）直线交叉点上有了同色的棋子，则这两个棋子被叫做相连的。任意多个棋子可以以此方式联成一体，连成一体的棋子的气的数目是所有组成这块棋的单个棋子气数之和。如果这些气都被异色棋子占领，这块棋子就要被一起提掉。\n\n劫是围棋中较特殊的一种情况。举例来说，当黑方某一手提掉对方一子，而这一个黑子恰好处于白方虎口之内，这时白方不能立即提掉这一黑子，而必须在棋盘其他地方着一手（称为“找劫材”），使黑方不得不应一手（称为“应劫”），然后白才能够提掉这个黑子。\n\n### 禁止自杀规则\n\n下子时，除非能令对方某些子失去所有的气，否则不得下子令自己某些子失去所有气，这亦被称为“禁止自杀规则”\n\n##### 核心方法\n```getAllGroupsLengthAndLiberty```：\n\n使用**Flood Fill**遍历棋盘上的所有位置，如果这个位置没有棋子，则\n跳过。如果有棋子，从该棋子开始遍历所有连接该棋子的同色棋子(组)，(即使组内只有一颗棋子)。\n\n遍历完成后， 获取该组的长度和它的所有的气。根据围棋规则，当一步落下时，除了该子所属的组，不可能杀死自己的其它组，所以\n这里只需要判断对方的某个或某些组是否被杀死。\n\n一个局部形成打劫，当且仅当：**该子落下后，该子所在的组失去了所有的气并且该子所在的组只有一个棋子(即它本身)\u0026\u0026\n该子落下后对方仅有一个组失去了所有的气且该组只有一颗棋子。** 如果该局部形成打劫，更新对方的禁入点，禁入点即为\n该子落下后，对方被提吃的仅有的一颗子的位置。\n\n```play```：判断一步棋是否可以走在棋盘上，如果可以，则更新棋盘，如果不可能，则什么都不会更新。\n\n1. 如果该点在棋盘外或者该点的位置已经有子，则不可以落子，返回**false**\n2. 如果该点在本方记录的打劫禁入点内，则不可以落子，返回**false**\n3. 排除以上两种情况后，则一定可以落子(没有反例)\n\n判断可以落子后：\n1. 清空辅助数组\n2. 将该子真正地更新在棋盘上(很重要)\n3. 遍历该子所属的整个组，并记录该组的长度\n4. 遍历棋盘，检查对方是否有一个或一串棋子被吃\n5. 如果没有对方没有棋子被吃，并且自己该子落下后失去了所有的气，那么**该行为属于自杀，落子无效**，恢复该位置的棋盘落子，并返回**false**\n6. 否则该位置可以落子，并清空自己的所有禁入点，因为该落子的有效意味着这是一枚劫财，之后的所有打劫处都可以落子。\n\n欢迎提出问题！🌟🌟🌟\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foli51467%2Fgo-datastructure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foli51467%2Fgo-datastructure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foli51467%2Fgo-datastructure/lists"}