├── DouDiZhu ├── data ├── cards.h ├── game.h ├── scene.h ├── cards.cpp ├── game.cpp ├── player.h ├── res │ ├── 1.png │ ├── hint.bmp │ ├── no.bmp │ ├── pass.bmp │ ├── cards.bmp │ ├── cards0.bmp │ ├── score1.bmp │ ├── score2.bmp │ ├── score3.bmp │ ├── cardback.bmp │ ├── discard.bmp │ ├── nodiscard.bmp │ └── background.bmp ├── scene.cpp ├── winmain.h ├── DouDiZhu.rc ├── cardgroup.h ├── player.cpp ├── resource.h ├── winmain.cpp ├── cardgroup.cpp ├── DouDiZhu.vcxproj.filters └── DouDiZhu.vcxproj ├── DouDiZhu.sln ├── LICENSE ├── README.md ├── .gitattributes └── .gitignore /DouDiZhu/data: -------------------------------------------------------------------------------- 1 | 994 2 | 1003 3 | 1003 4 | -------------------------------------------------------------------------------- /DouDiZhu/cards.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/cards.h -------------------------------------------------------------------------------- /DouDiZhu/game.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/game.h -------------------------------------------------------------------------------- /DouDiZhu/scene.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/scene.h -------------------------------------------------------------------------------- /DouDiZhu/cards.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/cards.cpp -------------------------------------------------------------------------------- /DouDiZhu/game.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/game.cpp -------------------------------------------------------------------------------- /DouDiZhu/player.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/player.h -------------------------------------------------------------------------------- /DouDiZhu/res/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/res/1.png -------------------------------------------------------------------------------- /DouDiZhu/scene.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/scene.cpp -------------------------------------------------------------------------------- /DouDiZhu/winmain.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/winmain.h -------------------------------------------------------------------------------- /DouDiZhu/DouDiZhu.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/DouDiZhu.rc -------------------------------------------------------------------------------- /DouDiZhu/cardgroup.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/cardgroup.h -------------------------------------------------------------------------------- /DouDiZhu/player.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/player.cpp -------------------------------------------------------------------------------- /DouDiZhu/res/hint.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/res/hint.bmp -------------------------------------------------------------------------------- /DouDiZhu/res/no.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/res/no.bmp -------------------------------------------------------------------------------- /DouDiZhu/res/pass.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/res/pass.bmp -------------------------------------------------------------------------------- /DouDiZhu/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/resource.h -------------------------------------------------------------------------------- /DouDiZhu/winmain.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/winmain.cpp -------------------------------------------------------------------------------- /DouDiZhu/cardgroup.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/cardgroup.cpp -------------------------------------------------------------------------------- /DouDiZhu/res/cards.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/res/cards.bmp -------------------------------------------------------------------------------- /DouDiZhu/res/cards0.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/res/cards0.bmp -------------------------------------------------------------------------------- /DouDiZhu/res/score1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/res/score1.bmp -------------------------------------------------------------------------------- /DouDiZhu/res/score2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/res/score2.bmp -------------------------------------------------------------------------------- /DouDiZhu/res/score3.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/res/score3.bmp -------------------------------------------------------------------------------- /DouDiZhu/res/cardback.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/res/cardback.bmp -------------------------------------------------------------------------------- /DouDiZhu/res/discard.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/res/discard.bmp -------------------------------------------------------------------------------- /DouDiZhu/res/nodiscard.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/res/nodiscard.bmp -------------------------------------------------------------------------------- /DouDiZhu/res/background.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songbaoming/DouDiZhu/HEAD/DouDiZhu/res/background.bmp -------------------------------------------------------------------------------- /DouDiZhu.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DouDiZhu", "DouDiZhu\DouDiZhu.vcxproj", "{3C8DE031-E139-4E90-829B-4B1E86B80701}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {3C8DE031-E139-4E90-829B-4B1E86B80701}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {3C8DE031-E139-4E90-829B-4B1E86B80701}.Debug|Win32.Build.0 = Debug|Win32 16 | {3C8DE031-E139-4E90-829B-4B1E86B80701}.Release|Win32.ActiveCfg = Release|Win32 17 | {3C8DE031-E139-4E90-829B-4B1E86B80701}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Song Baoming 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 程序简介 2 | 3 | 这是一个简单的人工智能单机斗地主游戏 4 | 5 | # 程序的实现 6 | 7 | ## 程序中使用到的类 8 | 9 | #### Card:一副扑克牌。 10 | 11 | 接口:洗牌、抹牌及剩余牌数。 12 | 13 | #### CardGroup:一组牌型,如:单张、对子、顺子、炸弹等等。 14 | 15 | 属性:包含牌序号集合、对应牌的权值集合、该组牌的类型、权值、牌的数量; 16 | 接口:添加/删除序号牌、重置结构内属性、静态序号到权值转换。 17 | 18 | #### Player:玩家 19 | 20 | 属性:手牌集合、手牌牌型集合、选牌集合、出牌集合、是否不出牌、玩家总分数; 21 | 接口:包括分析叫地主分数、分析手牌、选牌、分析是否出牌(或跟牌)等。 22 | 23 | #### Game:游戏主程序 24 | 25 | 属性:玩家、地主方、当前出牌方、本局基本分、倍率、地主专属牌集合等; 26 | 接口:相关控制游戏进行函数,及没个步骤通知界面更新。 27 | 28 | #### Scene:游戏界面 29 | 30 | 包含游戏界面元素及游戏主界面缓冲去生成及窗口绘制等功能。 31 | 32 | ## 人工智能部分实现 33 | 34 | #### 分析选牌牌型 35 | 36 | 1. 先分析选牌是否为王炸,如不是则进行第二步; 37 | 2. 找出选牌中相同权值的最大数量; 38 | 3. 根据最大数量判断是否为相应的有效牌型。 39 | 40 | #### 分析手牌并拆分成有效牌型 41 | 42 | 1. 判断牌型集合是否为空,不为空就不需要分析直接返回,否则进行第二步; 43 | 2. 由当前玩家手牌(0-53格式)生成权值牌集合(3-17格式); 44 | 3. 先拆分出权值牌集合中的基本牌型,分析的顺序为:王炸 → 炸弹 → 单顺 → 双顺 → 三顺、三条 → 一对 → 单张; 45 | 4. 然后又基本牌型尝试组合成更复杂的牌型:三带一、四带二、飞机等。 46 | 47 | #### 出牌/跟牌分析 48 | 49 | 1. 是否需要重新分析手牌,分析完成后进行第2步; 50 | 2. 直接出牌(最后出牌方为自己); 51 | 52 | * 如手牌数为2,则先出王炸、炸弹、数量最多、权值最大的牌; 53 | * 如下家为我方,其手牌数为一,则出最小单牌;如下家为敌方,其手牌数为一,尽量不出单牌,或出最大单牌; 54 | * 其他正常出牌顺序为:单牌(A以上的牌尽量不直接出)→对子→双顺→单顺→三条、三带一、飞机 55 | 56 | 3. 跟友方牌(最后出牌方为我方) 57 | 58 | * 手牌把数≤2,应出对应牌或炸弹,否则过牌 59 | * 上家为地主且未跟牌,过牌 60 | * 有对应牌,且权值小于14,则跟,炸弹不跟; 61 | 62 | 4. 跟敌方牌(最后出牌方为敌方) 63 | * 有对应牌就跟, 64 | * 没有就拆, 65 | * 再着用炸弹,否则就过牌 66 | 67 | ##### 拆牌原则: 68 | ``` 69 | 单牌时: 70 | 71 | 1.拆单顺数量大于5的 72 | 2.拆三条 73 | 3.拆对 74 | 75 | 对子时: 76 | 77 | 1.拆三条 78 | 2.拆三顺数量大于3的 79 | 80 | 单顺: 81 | 82 | 1.拆更长单顺 83 | 84 | 三条或三带一: 85 | 86 | 1.拆三顺(先判断数量大于3的) 87 | 88 | 飞机: 89 | 90 | 1.拆三顺数量大、权值更大的 91 | ``` 92 | `拆牌后一定要清空牌型集合` 93 | 94 | # License 95 | [MIT](https://github.com/songbaoming/DouDiZhu/blob/master/LICENSE) 96 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | 11 | [Dd]ebug/ 12 | [Rr]elease/ 13 | x64/ 14 | build/ 15 | [Bb]in/ 16 | [Oo]bj/ 17 | 18 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets 19 | !packages/*/build/ 20 | 21 | # MSTest test Results 22 | [Tt]est[Rr]esult*/ 23 | [Bb]uild[Ll]og.* 24 | 25 | *_i.c 26 | *_p.c 27 | *.ilk 28 | *.meta 29 | *.obj 30 | *.pch 31 | *.pdb 32 | *.pgc 33 | *.pgd 34 | *.rsp 35 | *.sbr 36 | *.tlb 37 | *.tli 38 | *.tlh 39 | *.tmp 40 | *.tmp_proj 41 | *.log 42 | *.vspscc 43 | *.vssscc 44 | .builds 45 | *.pidb 46 | *.log 47 | *.scc 48 | 49 | # Visual C++ cache files 50 | ipch/ 51 | *.aps 52 | *.ncb 53 | *.opensdf 54 | *.sdf 55 | *.cachefile 56 | 57 | # Visual Studio profiler 58 | *.psess 59 | *.vsp 60 | *.vspx 61 | 62 | # Guidance Automation Toolkit 63 | *.gpState 64 | 65 | # ReSharper is a .NET coding add-in 66 | _ReSharper*/ 67 | *.[Rr]e[Ss]harper 68 | 69 | # TeamCity is a build add-in 70 | _TeamCity* 71 | 72 | # DotCover is a Code Coverage Tool 73 | *.dotCover 74 | 75 | # NCrunch 76 | *.ncrunch* 77 | .*crunch*.local.xml 78 | 79 | # Installshield output folder 80 | [Ee]xpress/ 81 | 82 | # DocProject is a documentation generator add-in 83 | DocProject/buildhelp/ 84 | DocProject/Help/*.HxT 85 | DocProject/Help/*.HxC 86 | DocProject/Help/*.hhc 87 | DocProject/Help/*.hhk 88 | DocProject/Help/*.hhp 89 | DocProject/Help/Html2 90 | DocProject/Help/html 91 | 92 | # Click-Once directory 93 | publish/ 94 | 95 | # Publish Web Output 96 | *.Publish.xml 97 | 98 | # NuGet Packages Directory 99 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 100 | #packages/ 101 | 102 | # Windows Azure Build Output 103 | csx 104 | *.build.csdef 105 | 106 | # Windows Store app package directory 107 | AppPackages/ 108 | 109 | # Others 110 | sql/ 111 | *.Cache 112 | ClientBin/ 113 | [Ss]tyle[Cc]op.* 114 | ~$* 115 | *~ 116 | *.dbmdl 117 | *.[Pp]ublish.xml 118 | *.pfx 119 | *.publishsettings 120 | 121 | # RIA/Silverlight projects 122 | Generated_Code/ 123 | 124 | # Backup & report files from converting an old project file to a newer 125 | # Visual Studio version. Backup files are not needed, because we have git ;-) 126 | _UpgradeReport_Files/ 127 | Backup*/ 128 | UpgradeLog*.XML 129 | UpgradeLog*.htm 130 | 131 | # SQL Server files 132 | App_Data/*.mdf 133 | App_Data/*.ldf 134 | 135 | 136 | #LightSwitch generated files 137 | GeneratedArtifacts/ 138 | _Pvt_Extensions/ 139 | ModelManifest.xml 140 | 141 | # ========================= 142 | # Windows detritus 143 | # ========================= 144 | 145 | # Windows image file caches 146 | Thumbs.db 147 | ehthumbs.db 148 | 149 | # Folder config file 150 | Desktop.ini 151 | 152 | # Recycle Bin used on file shares 153 | $RECYCLE.BIN/ 154 | 155 | # Mac desktop service store files 156 | .DS_Store 157 | -------------------------------------------------------------------------------- /DouDiZhu/DouDiZhu.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 源文件 26 | 27 | 28 | 源文件 29 | 30 | 31 | 源文件 32 | 33 | 34 | 源文件 35 | 36 | 37 | 38 | 39 | 头文件 40 | 41 | 42 | 头文件 43 | 44 | 45 | 头文件 46 | 47 | 48 | 头文件 49 | 50 | 51 | 头文件 52 | 53 | 54 | 头文件 55 | 56 | 57 | 头文件 58 | 59 | 60 | 61 | 62 | 资源文件 63 | 64 | 65 | 资源文件 66 | 67 | 68 | 资源文件 69 | 70 | 71 | 资源文件 72 | 73 | 74 | 资源文件 75 | 76 | 77 | 资源文件 78 | 79 | 80 | 资源文件 81 | 82 | 83 | 资源文件 84 | 85 | 86 | 资源文件 87 | 88 | 89 | 资源文件 90 | 91 | 92 | 资源文件 93 | 94 | 95 | 96 | 97 | 资源文件 98 | 99 | 100 | -------------------------------------------------------------------------------- /DouDiZhu/DouDiZhu.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {3C8DE031-E139-4E90-829B-4B1E86B80701} 15 | Win32Proj 16 | DouDiZhu 17 | 18 | 19 | 20 | Application 21 | true 22 | v140 23 | Unicode 24 | 25 | 26 | Application 27 | false 28 | v140 29 | true 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | true 44 | 45 | 46 | false 47 | 48 | 49 | 50 | 51 | 52 | Level3 53 | Disabled 54 | WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) 55 | true 56 | 57 | 58 | Windows 59 | true 60 | 61 | 62 | 63 | 64 | Level3 65 | 66 | 67 | MaxSpeed 68 | true 69 | true 70 | WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) 71 | true 72 | 73 | 74 | Windows 75 | true 76 | true 77 | true 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | --------------------------------------------------------------------------------