Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
W
windbot
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
神之吹息
windbot
Commits
ce84e366
Commit
ce84e366
authored
Aug 19, 2017
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update OnSelectSum
parent
5bbaebde
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
148 deletions
+89
-148
Game/AI/CardContainer.cs
Game/AI/CardContainer.cs
+8
-0
Game/AI/Decks/BlueEyesExecutor.cs
Game/AI/Decks/BlueEyesExecutor.cs
+9
-63
Game/GameAI.cs
Game/GameAI.cs
+72
-85
No files found.
Game/AI/CardContainer.cs
View file @
ce84e366
using
YGOSharp.OCGWrapper.Enums
;
using
YGOSharp.OCGWrapper.Enums
;
using
System.Linq
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
namespace
WindBot.Game.AI
namespace
WindBot.Game.AI
...
@@ -174,5 +175,12 @@ namespace WindBot.Game.AI
...
@@ -174,5 +175,12 @@ namespace WindBot.Game.AI
}
}
return
null
;
return
null
;
}
}
public
static
IEnumerable
<
IEnumerable
<
T
>>
GetCombinations
<
T
>(
this
IEnumerable
<
T
>
elements
,
int
k
)
{
return
k
==
0
?
new
[]
{
new
T
[
0
]
}
:
elements
.
SelectMany
((
e
,
i
)
=>
elements
.
Skip
(
i
+
1
).
GetCombinations
(
k
-
1
).
Select
(
c
=>
(
new
[]
{
e
}).
Concat
(
c
)));
}
}
}
}
}
\ No newline at end of file
Game/AI/Decks/BlueEyesExecutor.cs
View file @
ce84e366
...
@@ -221,74 +221,20 @@ namespace WindBot.Game.AI.Decks
...
@@ -221,74 +221,20 @@ namespace WindBot.Game.AI.Decks
public
override
IList
<
ClientCard
>
OnSelectSum
(
IList
<
ClientCard
>
cards
,
int
sum
,
int
min
,
int
max
,
bool
mode
)
public
override
IList
<
ClientCard
>
OnSelectSum
(
IList
<
ClientCard
>
cards
,
int
sum
,
int
min
,
int
max
,
bool
mode
)
{
{
Logger
.
DebugWriteLine
(
"OnSelectSum "
+
cards
.
Count
+
" "
+
sum
+
" "
+
min
+
" "
+
max
);
Logger
.
DebugWriteLine
(
"OnSelectSum "
+
cards
.
Count
+
" "
+
sum
+
" "
+
min
+
" "
+
max
);
if
(
sum
>
12
||
!
mode
)
if
(
sum
!=
8
||
!
mode
)
return
null
;
return
null
;
IList
<
ClientCard
>
avail
=
new
List
<
ClientCard
>();
foreach
(
ClientCard
card
in
cards
)
foreach
(
ClientCard
亚白龙
in
使用过的青眼亚白龙
)
{
// clone
avail
.
Add
(
card
);
}
IList
<
ClientCard
>
selected
=
new
List
<
ClientCard
>();
int
trysum
=
0
;
if
(
使用过的青眼亚白龙
.
Count
>
0
&&
avail
.
IndexOf
(
使用过的青眼亚白龙
[
0
])
>
0
)
{
Logger
.
DebugWriteLine
(
"优先用使用过的亚白龙同调."
);
ClientCard
card
=
使用过的青眼亚白龙
[
0
];
使用过的青眼亚白龙
.
Remove
(
card
);
avail
.
Remove
(
card
);
selected
.
Add
(
card
);
trysum
=
card
.
Level
;
if
(
trysum
==
sum
)
{
Logger
.
DebugWriteLine
(
"直接选择了使用过的青眼亚白龙"
);
return
selected
;
}
}
foreach
(
ClientCard
card
in
cards
)
{
// try level equal
Logger
.
DebugWriteLine
(
"同调素材可以选择: "
+
card
.
Name
);
if
(
card
.
Level
==
sum
)
{
Logger
.
DebugWriteLine
(
"直接选择了"
+
card
.
Name
);
return
new
[]
{
card
};
}
// try level add
if
(
trysum
+
card
.
Level
>
sum
)
{
Logger
.
DebugWriteLine
(
"跳过了"
+
card
.
Name
);
continue
;
}
selected
.
Add
(
card
);
trysum
+=
card
.
Level
;
Logger
.
DebugWriteLine
(
"添加"
+
card
.
Name
);
Logger
.
DebugWriteLine
(
trysum
+
" selected "
+
sum
);
if
(
trysum
==
sum
)
{
return
selected
;
}
}
IList
<
ClientCard
>
selected2
=
new
List
<
ClientCard
>();
foreach
(
ClientCard
card
in
selected
)
{
// clone
selected2
.
Add
(
card
);
}
foreach
(
ClientCard
card
in
selected
)
{
{
// try level sub
if
(
cards
.
IndexOf
(
亚白龙
)
>
0
)
selected2
.
Remove
(
card
);
trysum
-=
card
.
Level
;
Logger
.
DebugWriteLine
(
"排除"
+
card
.
Name
);
Logger
.
DebugWriteLine
(
trysum
+
" selected2 "
+
sum
);
if
(
trysum
==
sum
)
{
{
return
selected2
;
使用过的青眼亚白龙
.
Remove
(
亚白龙
);
Logger
.
DebugWriteLine
(
"选择了使用过的青眼亚白龙"
);
return
new
[]
{
亚白龙
};
}
}
}
}
// try all
return
cards
;
return
null
;
}
}
public
override
bool
OnPreBattleBetween
(
ClientCard
attacker
,
ClientCard
defender
)
public
override
bool
OnPreBattleBetween
(
ClientCard
attacker
,
ClientCard
defender
)
...
...
Game/GameAI.cs
View file @
ce84e366
...
@@ -157,7 +157,7 @@ namespace WindBot.Game
...
@@ -157,7 +157,7 @@ namespace WindBot.Game
public
IList
<
ClientCard
>
OnSelectCard
(
IList
<
ClientCard
>
cards
,
int
min
,
int
max
,
bool
cancelable
)
public
IList
<
ClientCard
>
OnSelectCard
(
IList
<
ClientCard
>
cards
,
int
min
,
int
max
,
bool
cancelable
)
{
{
// Check for the executor.
// Check for the executor.
IList
<
ClientCard
>
result
=
Executor
.
OnSelectCard
(
cards
,
min
,
max
,
cancelable
);
IList
<
ClientCard
>
result
=
Executor
.
OnSelectCard
(
cards
,
min
,
max
,
cancelable
);
if
(
result
!=
null
)
if
(
result
!=
null
)
return
result
;
return
result
;
...
@@ -376,10 +376,12 @@ namespace WindBot.Game
...
@@ -376,10 +376,12 @@ namespace WindBot.Game
return
selected
;
return
selected
;
}
}
if
(
mode
)
if
(
mode
)
{
// equal
if
(
min
<=
1
)
{
{
foreach
(
ClientCard
card
in
cards
)
foreach
(
ClientCard
card
in
cards
)
{
{
//Logger.WriteLine("OpParam1 " + card.OpParam1 + " OpParam2 " + card.OpParam2 + " sum " + sum);
// try special level
// try special level
if
(
card
.
OpParam2
==
sum
)
if
(
card
.
OpParam2
==
sum
)
{
{
...
@@ -394,48 +396,39 @@ namespace WindBot.Game
...
@@ -394,48 +396,39 @@ namespace WindBot.Game
return
new
[]
{
card
};
return
new
[]
{
card
};
}
}
}
}
selected
=
new
List
<
ClientCard
>();
}
int
trysum
=
0
;
foreach
(
ClientCard
card
in
cards
)
int
i
=
(
min
<=
1
)
?
2
:
min
;
while
(
i
<=
max
&&
i
<=
cards
.
Count
)
{
{
// try level add
IEnumerable
<
IEnumerable
<
ClientCard
>>
combos
=
CardContainer
.
GetCombinations
(
cards
,
i
);
if
(
trysum
+
card
.
OpParam1
>
sum
)
foreach
(
IEnumerable
<
ClientCard
>
combo
in
combos
)
{
{
continue
;
Logger
.
DebugWriteLine
(
"--"
);
}
int
s1
=
0
,
s2
=
0
;
selected
.
Add
(
card
);
selected
=
new
List
<
ClientCard
>();
trysum
+=
card
.
OpParam1
;
foreach
(
ClientCard
card
in
combo
)
//Logger.DebugWriteLine(card.Id + "");
//Logger.DebugWriteLine(trysum + " selected " + sum);
if
(
trysum
==
sum
)
{
{
return
selected
;
s1
+=
card
.
OpParam1
;
}
s2
+=
(
card
.
OpParam2
!=
0
)
?
card
.
OpParam2
:
card
.
OpParam1
;
selected
.
Add
(
card
);
}
}
IList
<
ClientCard
>
selected2
=
new
List
<
ClientCard
>();
if
(
s1
==
sum
||
s2
==
sum
)
foreach
(
ClientCard
card
in
selected
)
{
{
// clone
return
selected
;
selected2
.
Add
(
card
);
}
}
foreach
(
ClientCard
card
in
selected
)
{
// try level sub
selected2
.
Remove
(
card
);
trysum
-=
card
.
OpParam1
;
//Logger.DebugWriteLine(card.Id + "");
//Logger.DebugWriteLine(trysum + " selected2 " + sum);
if
(
trysum
==
sum
)
{
return
selected2
;
}
}
i
++;
}
}
}
}
else
else
{
// larger
if
(
min
<=
1
)
{
{
foreach
(
ClientCard
card
in
cards
)
foreach
(
ClientCard
card
in
cards
)
{
{
//Logger.WriteLine("OpParam1 " + card.OpParam1 + " OpParam2 " + card.OpParam2 + " sum " + sum);
// try special level
// try special level
if
(
card
.
OpParam2
>=
sum
)
if
(
card
.
OpParam2
>=
sum
)
{
{
...
@@ -450,41 +443,35 @@ namespace WindBot.Game
...
@@ -450,41 +443,35 @@ namespace WindBot.Game
return
new
[]
{
card
};
return
new
[]
{
card
};
}
}
}
}
}
int
i
=
(
min
<=
1
)
?
2
:
min
;
while
(
i
<=
max
&&
i
<=
cards
.
Count
)
{
IEnumerable
<
IEnumerable
<
ClientCard
>>
combos
=
CardContainer
.
GetCombinations
(
cards
,
i
);
foreach
(
IEnumerable
<
ClientCard
>
combo
in
combos
)
{
Logger
.
DebugWriteLine
(
"----"
);
int
s1
=
0
,
s2
=
0
;
selected
=
new
List
<
ClientCard
>();
selected
=
new
List
<
ClientCard
>();
int
trysum
=
0
;
foreach
(
ClientCard
card
in
combo
)
foreach
(
ClientCard
card
in
cards
)
{
{
// try level add
s1
+=
card
.
OpParam1
;
s2
+=
(
card
.
OpParam2
!=
0
)
?
card
.
OpParam2
:
card
.
OpParam1
;
selected
.
Add
(
card
);
selected
.
Add
(
card
);
trysum
+=
card
.
OpParam1
;
//Logger.DebugWriteLine(card.Id + "");
//Logger.DebugWriteLine(trysum + " selected " + sum);
if
(
trysum
>=
sum
)
{
return
selected
;
}
}
}
IList
<
ClientCard
>
selected2
=
new
List
<
ClientCard
>();
if
(
s1
>=
sum
||
s2
>=
sum
)
foreach
(
ClientCard
card
in
selected
)
{
{
// clone
return
selected
;
selected2
.
Add
(
card
);
}
}
foreach
(
ClientCard
card
in
selected
)
{
// try level sub
selected2
.
Remove
(
card
);
trysum
-=
card
.
OpParam1
;
//Logger.DebugWriteLine(card.Id + "");
//Logger.DebugWriteLine(trysum + " selected2 " + sum);
if
(
trysum
>=
sum
)
{
return
selected2
;
}
}
i
++;
}
}
}
}
// try all
return
cards
;
Logger
.
WriteErrorLine
(
"Fail to select sum."
);
return
null
;
}
}
/// <summary>
/// <summary>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment