Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
微笑面对bug
ddz
提交
8d9fe39c
ddz
项目概览
微笑面对bug
/
ddz
通知
5
Star
2
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
ddz
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
8d9fe39c
编写于
9月 24, 2020
作者:
C
changjiuxiong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
AI 地主出牌
上级
bfc11153
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
317 addition
and
3 deletion
+317
-3
src/doudizhu/AI.js
src/doudizhu/AI.js
+293
-0
src/doudizhu/Player.js
src/doudizhu/Player.js
+24
-3
未找到文件。
src/doudizhu/AI.js
浏览文件 @
8d9fe39c
...
...
@@ -2,6 +2,8 @@
class
AI
{
constructor
(
param
)
{
param
=
param
||
{};
this
.
player
=
param
.
player
;
this
.
game
=
param
.
game
;
}
classify
(
pokerList
){
...
...
@@ -296,6 +298,297 @@ class AI{
};
}
//接牌
playByObj
(
lastObj
){
}
//出牌1
playByTypys1
(){
let
types
=
[
'
threeWithTwoList
'
,
'
threeWithOneList
'
,
'
threeList
'
,
'
twoList
'
,
'
oneList
'
,
'
threeWithTwo
'
,
'
threeWithOne
'
,
'
three
'
,
'
two
'
,
'
one
'
,
'
four
'
,
'
sx
'
];
for
(
let
i
=
0
;
i
<
types
.
length
;
i
++
){
let
obj
=
this
.
getSmallestObjByType
(
types
[
i
]);
this
.
player
.
deleteFromPokerListAndSendByObj
(
obj
);
}
}
//出牌2
playByTypys2
(){
let
types
=
[
'
threeWithTwoList
'
,
'
threeWithOneList
'
,
'
threeList
'
,
'
twoList
'
,
'
oneList
'
,
'
threeWithTwo
'
,
'
threeWithOne
'
,
'
three
'
,
'
two
'
,
'
four
'
,
'
sx
'
,
'
one
'
];
for
(
let
i
=
0
;
i
<
types
.
length
;
i
++
){
let
obj
=
this
.
getSmallestObjByType
(
types
[
i
],
true
);
this
.
player
.
deleteFromPokerListAndSendByObj
(
obj
);
}
}
//出牌
playByAllType
(){
if
(
this
.
player
.
type
===
'
dizhu
'
){
if
(
this
.
player
.
next
.
pokerList
.
length
===
1
||
this
.
player
.
last
.
pokerList
.
length
===
1
){
this
.
playByTypys2
();
}
else
{
this
.
playByTypys1
();
}
}
}
getSmallestObjByType
(
type
,
oneBigToSmall
){
let
classifyObj
=
this
.
player
.
classifyObj
;
let
obj
=
null
;
if
(
type
===
'
one
'
){
if
(
oneBigToSmall
){
let
poker
;
if
(
classifyObj
.
poker17
.
length
>
0
){
poker
=
classifyObj
.
poker17
;
}
else
if
(
classifyObj
.
poker16
.
length
>
0
){
poker
=
classifyObj
.
poker16
;
}
else
if
(
classifyObj
.
poker15
.
length
>
0
){
poker
=
classifyObj
.
poker15
[
0
];
}
else
{
poker
=
classifyObj
.
one
[
classifyObj
.
one
.
length
-
1
];
}
obj
=
{
type
:
type
,
poker
:
poker
,
one
:
poker
,
};
}
else
{
let
poker
;
if
(
classifyObj
.
one
.
length
>
0
){
poker
=
classifyObj
.
one
[
0
];
}
else
{
if
(
classifyObj
.
poker17
.
length
<
0
||
classifyObj
.
poker16
.
length
<
0
){
if
(
classifyObj
.
poker16
.
length
>
0
){
poker
=
classifyObj
.
poker16
;
}
else
if
(
classifyObj
.
poker17
.
length
>
0
){
poker
=
classifyObj
.
poker17
;
}
}
}
if
(
poker
){
obj
=
{
type
:
type
,
poker
:
poker
,
one
:
poker
,
};
}
}
}
else
if
(
type
===
'
two
'
){
let
poker
;
if
(
oneBigToSmall
){
if
(
classifyObj
.
two
.
length
>
0
){
poker
=
classifyObj
.
two
[
0
];
}
else
{
if
(
classifyObj
.
poker15
.
length
===
2
){
poker
=
classifyObj
.
poker15
;
}
}
}
else
{
if
(
classifyObj
.
two
.
length
>
0
){
poker
=
classifyObj
.
two
[
0
];
}
}
if
(
poker
){
obj
=
{
type
:
type
,
poker
:
poker
,
two
:
poker
,
};
}
}
else
if
(
type
===
'
three
'
){
let
poker
;
if
(
oneBigToSmall
){
if
(
classifyObj
.
three
.
length
>
0
){
poker
=
classifyObj
.
three
[
0
];
}
else
{
if
(
classifyObj
.
poker15
.
length
===
3
){
poker
=
classifyObj
.
poker15
;
}
}
}
else
{
if
(
classifyObj
.
three
.
length
>
0
){
poker
=
classifyObj
.
three
[
0
];
}
}
if
(
poker
){
obj
=
{
type
:
type
,
poker
:
poker
,
three
:
poker
,
};
}
}
else
if
(
type
===
'
threeWithOne
'
){
let
pokerThree
;
let
one
;
if
(
classifyObj
.
three
.
length
>
0
){
pokerThree
=
classifyObj
.
three
[
0
];
}
if
(
classifyObj
.
one
.
length
>
0
){
one
=
classifyObj
.
one
[
0
];
}
if
(
oneBigToSmall
){
if
(
!
pokerThree
&&
classifyObj
.
poker15
.
length
===
3
){
pokerThree
=
classifyObj
.
poker15
;
}
if
(
!
one
&&
classifyObj
.
poker15
.
length
===
1
){
one
=
classifyObj
.
poker15
;
}
}
if
(
pokerThree
&&
one
){
obj
=
{
type
:
type
,
poker
:
pokerThree
.
concat
(
one
),
three
:
pokerThree
,
one
:
one
,
};
}
}
else
if
(
type
===
'
four
'
){
let
poker
;
if
(
oneBigToSmall
){
if
(
classifyObj
.
four
.
length
>
0
){
poker
=
classifyObj
.
four
[
0
];
}
else
{
if
(
classifyObj
.
poker15
.
length
===
4
){
poker
=
classifyObj
.
poker15
;
}
}
}
else
{
if
(
classifyObj
.
four
.
length
>
0
){
poker
=
classifyObj
.
four
[
0
];
}
}
if
(
poker
){
obj
=
{
type
:
type
,
poker
:
poker
,
four
:
poker
,
};
}
}
else
if
(
type
===
'
threeWithTwo
'
){
let
pokerThree
;
let
two
;
if
(
classifyObj
.
three
.
length
>
0
){
pokerThree
=
classifyObj
.
three
[
0
];
}
if
(
classifyObj
.
two
.
length
>
0
){
two
=
classifyObj
.
two
[
0
];
}
if
(
oneBigToSmall
){
if
(
!
pokerThree
&&
classifyObj
.
poker15
.
length
===
3
){
pokerThree
=
classifyObj
.
poker15
;
}
if
(
!
two
&&
classifyObj
.
poker15
.
length
===
2
){
two
=
classifyObj
.
poker15
;
}
}
if
(
pokerThree
&&
two
){
obj
=
{
type
:
type
,
poker
:
pokerThree
.
concat
(
two
),
three
:
pokerThree
,
two
:
two
,
};
}
}
else
if
(
type
===
'
threeWithOneList
'
){
if
(
classifyObj
.
threeList
.
length
>
0
){
if
(
classifyObj
.
one
.
length
>=
classifyObj
.
threeList
[
0
].
length
){
let
pokerThree
=
classifyObj
.
threeList
[
0
].
flat
(
1
);
let
pokerOne
=
classifyObj
.
one
.
slice
(
0
,
classifyObj
.
threeList
[
0
].
length
).
flat
(
1
);
obj
=
{
type
:
type
,
poker
:
pokerThree
.
concat
(
pokerOne
),
list
:
classifyObj
.
threeList
[
0
].
map
(
function
(
item
)
{
return
{
three
:
item
};
}),
};
}
}
}
else
if
(
type
===
'
threeWithTwoList
'
){
if
(
classifyObj
.
threeList
.
length
>
0
){
if
(
classifyObj
.
two
.
length
>=
classifyObj
.
threeList
[
0
].
length
){
let
pokerThree
=
classifyObj
.
threeList
[
0
].
flat
(
1
);
let
pokerTwo
=
classifyObj
.
two
.
slice
(
0
,
classifyObj
.
threeList
[
0
].
length
).
flat
(
1
);
obj
=
{
type
:
type
,
poker
:
pokerThree
.
concat
(
pokerTwo
),
list
:
classifyObj
.
threeList
[
0
].
map
(
function
(
item
)
{
return
{
three
:
item
};
}),
};
}
}
}
else
if
(
type
===
'
oneList
'
){
if
(
classifyObj
.
oneList
.
length
>
0
){
obj
=
{
type
:
type
,
poker
:
classifyObj
.
oneList
[
0
].
flat
(
1
),
list
:
classifyObj
.
oneList
[
0
].
map
(
function
(
item
)
{
return
{
one
:
item
,
}
}),
};
}
}
else
if
(
type
===
'
twoList
'
){
if
(
classifyObj
.
twoList
.
length
>
0
){
obj
=
{
type
:
type
,
poker
:
classifyObj
.
twoList
[
0
].
flat
(
1
),
list
:
classifyObj
.
twoList
[
0
].
map
(
function
(
item
)
{
return
{
two
:
item
,
}
}),
};
}
}
else
if
(
type
===
'
threeList
'
){
if
(
classifyObj
.
threeList
.
length
>
0
){
obj
=
{
type
:
type
,
poker
:
classifyObj
.
threeList
[
0
].
flat
(
1
),
list
:
classifyObj
.
threeList
[
0
].
map
(
function
(
item
)
{
return
{
three
:
item
,
}
}),
};
}
}
else
if
(
type
===
'
sx
'
){
if
(
classifyObj
.
poker16
.
length
>
0
&&
classifyObj
.
poker17
.
length
>
0
){
return
{
type
:
type
,
poker
:
classifyObj
.
poker16
.
concat
(
classifyObj
.
poker17
),
sx
:
classifyObj
.
poker16
.
concat
(
classifyObj
.
poker17
),
}
}
}
return
obj
;
}
sortFunction
(
a
,
b
){
return
a
.
number
-
b
.
number
;
}
...
...
src/doudizhu/Player.js
浏览文件 @
8d9fe39c
...
...
@@ -11,15 +11,18 @@ class Player{
this
.
next
=
null
;
this
.
isRobot
=
param
.
isRobot
;
this
.
game
=
param
.
game
;
this
.
ai
=
new
AI
();
this
.
classifyObj
=
new
AI
();
this
.
ai
=
new
AI
({
player
:
this
,
game
:
param
.
game
,
});
this
.
classifyObj
=
null
;
this
.
lastSendObj
=
null
;
}
//组牌
getClassifyObj
(){
this
.
classifyObj
=
this
.
ai
.
getClassifyObj
(
this
.
pokerList
);
console
.
log
(
this
.
pokerListToString
());
console
.
log
(
this
.
classifyObj
);
}
...
...
@@ -60,7 +63,25 @@ class Player{
}
playByAI2
(){
let
that
=
this
;
that
.
getClassifyObj
();
setTimeout
(
function
()
{
let
lastObj
=
that
.
getLastObj
();
if
(
lastObj
){
that
.
ai
.
playByObj
(
lastObj
);
}
else
{
that
.
ai
.
playByAllType
();
}
},
1000
);
}
sendPoker
(
obj
){
obj
.
player
=
this
;
this
.
game
.
clearDesk
();
this
.
lastSendObj
=
obj
;
this
.
game
.
deskPokerObj
=
obj
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录