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
Tang Xinwei
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
Hide 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
System.Linq
;
using
System.Collections.Generic
;
namespace
WindBot.Game.AI
...
...
@@ -174,5 +175,12 @@ namespace WindBot.Game.AI
}
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
public
override
IList
<
ClientCard
>
OnSelectSum
(
IList
<
ClientCard
>
cards
,
int
sum
,
int
min
,
int
max
,
bool
mode
)
{
Logger
.
DebugWriteLine
(
"OnSelectSum "
+
cards
.
Count
+
" "
+
sum
+
" "
+
min
+
" "
+
max
);
if
(
sum
>
12
||
!
mode
)
if
(
sum
!=
8
||
!
mode
)
return
null
;
IList
<
ClientCard
>
avail
=
new
List
<
ClientCard
>();
foreach
(
ClientCard
card
in
cards
)
{
// 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
)
foreach
(
ClientCard
亚白龙
in
使用过的青眼亚白龙
)
{
// try level sub
selected2
.
Remove
(
card
);
trysum
-=
card
.
Level
;
Logger
.
DebugWriteLine
(
"排除"
+
card
.
Name
);
Logger
.
DebugWriteLine
(
trysum
+
" selected2 "
+
sum
);
if
(
trysum
==
sum
)
if
(
cards
.
IndexOf
(
亚白龙
)
>
0
)
{
return
selected2
;
使用过的青眼亚白龙
.
Remove
(
亚白龙
);
Logger
.
DebugWriteLine
(
"选择了使用过的青眼亚白龙"
);
return
new
[]
{
亚白龙
};
}
}
// try all
return
cards
;
return
null
;
}
public
override
bool
OnPreBattleBetween
(
ClientCard
attacker
,
ClientCard
defender
)
...
...
Game/GameAI.cs
View file @
ce84e366
...
...
@@ -157,7 +157,7 @@ namespace WindBot.Game
public
IList
<
ClientCard
>
OnSelectCard
(
IList
<
ClientCard
>
cards
,
int
min
,
int
max
,
bool
cancelable
)
{
// 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
)
return
result
;
...
...
@@ -377,114 +377,101 @@ namespace WindBot.Game
}
if
(
mode
)
{
foreach
(
ClientCard
card
in
cards
)
// equal
if
(
min
<=
1
)
{
//Logger.WriteLine("OpParam1 " + card.OpParam1 + " OpParam2 " + card.OpParam2 + " sum " + sum);
// try special level
if
(
card
.
OpParam2
==
sum
)
foreach
(
ClientCard
card
in
cards
)
{
return
new
[]
{
card
};
}
}
foreach
(
ClientCard
card
in
cards
)
{
// try level equal
if
(
card
.
OpParam1
==
sum
)
{
return
new
[]
{
card
};
}
}
selected
=
new
List
<
ClientCard
>();
int
trysum
=
0
;
foreach
(
ClientCard
card
in
cards
)
{
// try level add
if
(
trysum
+
card
.
OpParam1
>
sum
)
{
continue
;
// try special level
if
(
card
.
OpParam2
==
sum
)
{
return
new
[]
{
card
};
}
}
selected
.
Add
(
card
);
trysum
+=
card
.
OpParam1
;
//Logger.DebugWriteLine(card.Id + "");
//Logger.DebugWriteLine(trysum + " selected " + sum);
if
(
trysum
==
sum
)
foreach
(
ClientCard
card
in
cards
)
{
return
selected
;
// try level equal
if
(
card
.
OpParam1
==
sum
)
{
return
new
[]
{
card
};
}
}
}
IList
<
ClientCard
>
selected2
=
new
List
<
ClientCard
>();
foreach
(
ClientCard
card
in
selected
)
{
// clone
selected2
.
Add
(
card
);
}
foreach
(
ClientCard
card
in
selected
)
int
i
=
(
min
<=
1
)
?
2
:
min
;
while
(
i
<=
max
&&
i
<=
cards
.
Count
)
{
// try level sub
selected2
.
Remove
(
card
);
trysum
-=
card
.
OpParam1
;
//Logger.DebugWriteLine(card.Id + "");
//Logger.DebugWriteLine(trysum + " selected2 " + sum);
if
(
trysum
==
sum
)
IEnumerable
<
IEnumerable
<
ClientCard
>>
combos
=
CardContainer
.
GetCombinations
(
cards
,
i
);
foreach
(
IEnumerable
<
ClientCard
>
combo
in
combos
)
{
return
selected2
;
Logger
.
DebugWriteLine
(
"--"
);
int
s1
=
0
,
s2
=
0
;
selected
=
new
List
<
ClientCard
>();
foreach
(
ClientCard
card
in
combo
)
{
s1
+=
card
.
OpParam1
;
s2
+=
(
card
.
OpParam2
!=
0
)
?
card
.
OpParam2
:
card
.
OpParam1
;
selected
.
Add
(
card
);
}
if
(
s1
==
sum
||
s2
==
sum
)
{
return
selected
;
}
}
i
++;
}
}
else
{
foreach
(
ClientCard
card
in
cards
)
// larger
if
(
min
<=
1
)
{
//Logger.WriteLine("OpParam1 " + card.OpParam1 + " OpParam2 " + card.OpParam2 + " sum " + sum);
// try special level
if
(
card
.
OpParam2
>=
sum
)
foreach
(
ClientCard
card
in
cards
)
{
return
new
[]
{
card
};
}
}
foreach
(
ClientCard
card
in
cards
)
{
// try level equal
if
(
card
.
OpParam1
>=
sum
)
{
return
new
[]
{
card
};
// try special level
if
(
card
.
OpParam2
>=
sum
)
{
return
new
[]
{
card
};
}
}
}
selected
=
new
List
<
ClientCard
>();
int
trysum
=
0
;
foreach
(
ClientCard
card
in
cards
)
{
// try level add
selected
.
Add
(
card
);
trysum
+=
card
.
OpParam1
;
//Logger.DebugWriteLine(card.Id + "");
//Logger.DebugWriteLine(trysum + " selected " + sum);
if
(
trysum
>=
sum
)
foreach
(
ClientCard
card
in
cards
)
{
return
selected
;
// try level equal
if
(
card
.
OpParam1
>=
sum
)
{
return
new
[]
{
card
};
}
}
}
IList
<
ClientCard
>
selected2
=
new
List
<
ClientCard
>();
foreach
(
ClientCard
card
in
selected
)
{
// clone
selected2
.
Add
(
card
);
}
foreach
(
ClientCard
card
in
selected
)
int
i
=
(
min
<=
1
)
?
2
:
min
;
while
(
i
<=
max
&&
i
<=
cards
.
Count
)
{
// try level sub
selected2
.
Remove
(
card
);
trysum
-=
card
.
OpParam1
;
//Logger.DebugWriteLine(card.Id + "");
//Logger.DebugWriteLine(trysum + " selected2 " + sum);
if
(
trysum
>=
sum
)
IEnumerable
<
IEnumerable
<
ClientCard
>>
combos
=
CardContainer
.
GetCombinations
(
cards
,
i
);
foreach
(
IEnumerable
<
ClientCard
>
combo
in
combos
)
{
return
selected2
;
Logger
.
DebugWriteLine
(
"----"
);
int
s1
=
0
,
s2
=
0
;
selected
=
new
List
<
ClientCard
>();
foreach
(
ClientCard
card
in
combo
)
{
s1
+=
card
.
OpParam1
;
s2
+=
(
card
.
OpParam2
!=
0
)
?
card
.
OpParam2
:
card
.
OpParam1
;
selected
.
Add
(
card
);
}
if
(
s1
>=
sum
||
s2
>=
sum
)
{
return
selected
;
}
}
i
++;
}
}
// try all
return
cards
;
Logger
.
WriteErrorLine
(
"Fail to select sum."
);
return
null
;
}
/// <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