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
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
MyCard
windbot
Commits
98f7c3e1
Commit
98f7c3e1
authored
Apr 06, 2018
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update OnBattle
parent
5870c2d9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
92 additions
and
41 deletions
+92
-41
Game/AI/DefaultExecutor.cs
Game/AI/DefaultExecutor.cs
+28
-1
Game/AI/Executor.cs
Game/AI/Executor.cs
+18
-39
Game/ClientCard.cs
Game/ClientCard.cs
+1
-0
Game/GameAI.cs
Game/GameAI.cs
+45
-1
No files found.
Game/AI/DefaultExecutor.cs
View file @
98f7c3e1
...
@@ -45,13 +45,40 @@ namespace WindBot.Game.AI
...
@@ -45,13 +45,40 @@ namespace WindBot.Game.AI
AddExecutor
(
ExecutorType
.
Activate
,
_CardId
.
ChickenGame
,
DefaultChickenGame
);
AddExecutor
(
ExecutorType
.
Activate
,
_CardId
.
ChickenGame
,
DefaultChickenGame
);
}
}
/// <summary>
/// Decide which card should the attacker attack.
/// </summary>
/// <param name="attacker">Card that attack.</param>
/// <param name="defenders">Cards that defend.</param>
/// <returns>BattlePhaseAction including the target, or null (in this situation, GameAI will check the next attacker)</returns>
public
override
BattlePhaseAction
OnSelectAttackTarget
(
ClientCard
attacker
,
IList
<
ClientCard
>
defenders
)
{
for
(
int
i
=
0
;
i
<
defenders
.
Count
;
++
i
)
{
ClientCard
defender
=
defenders
[
i
];
attacker
.
RealPower
=
attacker
.
Attack
;
defender
.
RealPower
=
defender
.
GetDefensePower
();
if
(!
OnPreBattleBetween
(
attacker
,
defender
))
continue
;
if
(
attacker
.
RealPower
>
defender
.
RealPower
||
(
attacker
.
RealPower
>=
defender
.
RealPower
&&
attacker
.
IsLastAttacker
))
return
AI
.
Attack
(
attacker
,
defender
);
}
if
(
attacker
.
CanDirectAttack
)
return
AI
.
Attack
(
attacker
,
null
);
return
null
;
}
/// <summary>
/// <summary>
/// Decide whether to declare attack between attacker and defender.
/// Decide whether to declare attack between attacker and defender.
/// Can be overrided to update the RealPower of attacker for cards like Honest.
/// Can be overrided to update the RealPower of attacker for cards like Honest.
/// </summary>
/// </summary>
/// <param name="attacker">Card that attack.</param>
/// <param name="attacker">Card that attack.</param>
/// <param name="defender">Card that defend.</param>
/// <param name="defender">Card that defend.</param>
/// <returns>false if the attack
ca
n't be done.</returns>
/// <returns>false if the attack
should
n't be done.</returns>
public
override
bool
OnPreBattleBetween
(
ClientCard
attacker
,
ClientCard
defender
)
public
override
bool
OnPreBattleBetween
(
ClientCard
attacker
,
ClientCard
defender
)
{
{
if
(
attacker
.
RealPower
<=
0
)
if
(
attacker
.
RealPower
<=
0
)
...
...
Game/AI/Executor.cs
View file @
98f7c3e1
...
@@ -52,47 +52,26 @@ namespace WindBot.Game.AI
...
@@ -52,47 +52,26 @@ namespace WindBot.Game.AI
/// <returns>A new BattlePhaseAction containing the action to do.</returns>
/// <returns>A new BattlePhaseAction containing the action to do.</returns>
public
virtual
BattlePhaseAction
OnBattle
(
IList
<
ClientCard
>
attackers
,
IList
<
ClientCard
>
defenders
)
public
virtual
BattlePhaseAction
OnBattle
(
IList
<
ClientCard
>
attackers
,
IList
<
ClientCard
>
defenders
)
{
{
if
(
attackers
.
Count
==
0
)
// For overriding
return
AI
.
ToMainPhase2
();
return
null
;
}
if
(
defenders
.
Count
==
0
)
{
for
(
int
i
=
attackers
.
Count
-
1
;
i
>=
0
;
--
i
)
{
ClientCard
attacker
=
attackers
[
i
];
if
(
attacker
.
Attack
>
0
)
return
AI
.
Attack
(
attacker
,
null
);
}
}
else
{
for
(
int
i
=
defenders
.
Count
-
1
;
i
>=
0
;
--
i
)
{
ClientCard
defender
=
defenders
[
i
];
for
(
int
j
=
0
;
j
<
attackers
.
Count
;
++
j
)
{
ClientCard
attacker
=
attackers
[
j
];
attacker
.
RealPower
=
attacker
.
Attack
;
defender
.
RealPower
=
defender
.
GetDefensePower
();
if
(!
OnPreBattleBetween
(
attacker
,
defender
))
continue
;
if
(
attacker
.
RealPower
>
defender
.
RealPower
||
(
attacker
.
RealPower
>=
defender
.
RealPower
&&
j
==
attackers
.
Count
-
1
))
return
AI
.
Attack
(
attacker
,
defender
);
}
}
for
(
int
i
=
attackers
.
Count
-
1
;
i
>=
0
;
--
i
)
{
ClientCard
attacker
=
attackers
[
i
];
if
(
attacker
.
CanDirectAttack
)
return
AI
.
Attack
(
attacker
,
null
);
}
}
if
(!
Battle
.
CanMainPhaseTwo
)
/// <summary>
return
AI
.
Attack
(
attackers
[
0
],
(
defenders
.
Count
==
0
)
?
null
:
defenders
[
0
]);
/// Called when the AI has to decide which card to attack first
/// </summary>
/// <param name="attackers">List of monsters that can attcack.</param>
/// <param name="defenders">List of monsters of enemy.</param>
/// <returns>The card to attack first.</returns>
public
virtual
ClientCard
OnSelectAttacker
(
IList
<
ClientCard
>
attackers
,
IList
<
ClientCard
>
defenders
)
{
// For overriding
return
null
;
}
return
AI
.
ToMainPhase2
();
public
virtual
BattlePhaseAction
OnSelectAttackTarget
(
ClientCard
attacker
,
IList
<
ClientCard
>
defenders
)
{
// Overrided in DefalultExecutor
return
null
;
}
}
public
virtual
bool
OnPreBattleBetween
(
ClientCard
attacker
,
ClientCard
defender
)
public
virtual
bool
OnPreBattleBetween
(
ClientCard
attacker
,
ClientCard
defender
)
...
...
Game/ClientCard.cs
View file @
98f7c3e1
...
@@ -36,6 +36,7 @@ namespace WindBot.Game
...
@@ -36,6 +36,7 @@ namespace WindBot.Game
public
bool
CanDirectAttack
{
get
;
set
;
}
public
bool
CanDirectAttack
{
get
;
set
;
}
public
bool
ShouldDirectAttack
{
get
;
set
;
}
public
bool
ShouldDirectAttack
{
get
;
set
;
}
public
bool
Attacked
{
get
;
set
;
}
public
bool
Attacked
{
get
;
set
;
}
public
bool
IsLastAttacker
{
get
;
set
;
}
public
int
[]
ActionIndex
{
get
;
set
;
}
public
int
[]
ActionIndex
{
get
;
set
;
}
public
IDictionary
<
int
,
int
>
ActionActivateIndex
{
get
;
private
set
;
}
public
IDictionary
<
int
,
int
>
ActionActivateIndex
{
get
;
private
set
;
}
...
...
Game/GameAI.cs
View file @
98f7c3e1
...
@@ -143,13 +143,57 @@ namespace WindBot.Game
...
@@ -143,13 +143,57 @@ namespace WindBot.Game
}
}
}
}
// Sort the attackers and defenders, make monster with higher attack go first.
List
<
ClientCard
>
attackers
=
new
List
<
ClientCard
>(
battle
.
AttackableCards
);
List
<
ClientCard
>
attackers
=
new
List
<
ClientCard
>(
battle
.
AttackableCards
);
attackers
.
Sort
(
AIFunctions
.
CompareCardAttack
);
attackers
.
Sort
(
AIFunctions
.
CompareCardAttack
);
attackers
.
Reverse
();
List
<
ClientCard
>
defenders
=
new
List
<
ClientCard
>(
Duel
.
Fields
[
1
].
GetMonsters
());
List
<
ClientCard
>
defenders
=
new
List
<
ClientCard
>(
Duel
.
Fields
[
1
].
GetMonsters
());
defenders
.
Sort
(
AIFunctions
.
CompareDefensePower
);
defenders
.
Sort
(
AIFunctions
.
CompareDefensePower
);
defenders
.
Reverse
();
return
Executor
.
OnBattle
(
attackers
,
defenders
);
// Let executor decide which card should attack first.
ClientCard
selected
=
Executor
.
OnSelectAttacker
(
attackers
,
defenders
);
if
(
selected
!=
null
&&
attackers
.
Contains
(
selected
))
{
attackers
.
Remove
(
selected
);
attackers
.
Insert
(
0
,
selected
);
}
// Check for the executor.
BattlePhaseAction
result
=
Executor
.
OnBattle
(
attackers
,
defenders
);
if
(
result
!=
null
)
return
result
;
if
(
attackers
.
Count
==
0
)
return
ToMainPhase2
();
if
(
defenders
.
Count
==
0
)
{
// Attack with the monster with the lowest attack first
for
(
int
i
=
attackers
.
Count
-
1
;
i
>=
0
;
--
i
)
{
ClientCard
attacker
=
attackers
[
i
];
if
(
attacker
.
Attack
>
0
)
return
Attack
(
attacker
,
null
);
}
}
else
{
for
(
int
k
=
0
;
k
<
attackers
.
Count
;
++
k
)
{
ClientCard
attacker
=
attackers
[
k
];
attacker
.
IsLastAttacker
=
(
k
==
attackers
.
Count
-
1
);
result
=
Executor
.
OnSelectAttackTarget
(
attacker
,
defenders
);
if
(
result
!=
null
)
return
result
;
}
}
if
(!
battle
.
CanMainPhaseTwo
)
return
Attack
(
attackers
[
0
],
(
defenders
.
Count
==
0
)
?
null
:
defenders
[
0
]);
return
ToMainPhase2
();
}
}
/// <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