Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
Not Alone
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
9
Issues
9
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
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
Corentin GUILLEVIC
Not Alone
Commits
a60e88b2
Commit
a60e88b2
authored
Dec 04, 2020
by
Corentin Guillevic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small refactoring
parent
7cd1354f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
200 additions
and
120 deletions
+200
-120
not-alone-server/src/main/java/fr/univnantes/alma/server/game/PowerApplicator.java
.../java/fr/univnantes/alma/server/game/PowerApplicator.java
+71
-108
not-alone-server/src/main/java/fr/univnantes/alma/server/game/item/power/recurrent/PowerRecurrent.java
...alma/server/game/item/power/recurrent/PowerRecurrent.java
+5
-7
not-alone-server/src/test/java/fr/univnantes/alma/server/game/PowerApplicatorTest.java
...a/fr/univnantes/alma/server/game/PowerApplicatorTest.java
+124
-5
No files found.
not-alone-server/src/main/java/fr/univnantes/alma/server/game/PowerApplicator.java
View file @
a60e88b2
...
...
@@ -21,12 +21,9 @@ import fr.univnantes.alma.server.game.item.power.modifier.PowerModifierType;
import
fr.univnantes.alma.server.game.item.power.recurrent.PowerRecurrent
;
import
fr.univnantes.alma.server.game.utilitary.Pair
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.*
;
import
java.util.function.BiConsumer
;
import
java.util.function.Bi
Function
;
import
java.util.function.Bi
Predicate
;
import
java.util.stream.Collectors
;
import
static
fr
.
univnantes
.
alma
.
server
.
game
.
item
.
card
.
CardName
.*;
...
...
@@ -80,7 +77,7 @@ public class PowerApplicator {
Traque
traque
=
(
Traque
)
game
.
getPlayer
(
idPlayer
);
traque
.
addSurvivalCard
(
game
.
getPlanet
().
takeSurvivalCardOnPlace
(
placeCard
));
}
applyPlaceCardPower
(
idPlayer
,
game
,
placeCard
.
getCardName
()
);
applyPlaceCardPower
(
idPlayer
,
placeCard
.
getCardName
(),
game
);
}
}
...
...
@@ -173,10 +170,10 @@ public class PowerApplicator {
/**
* A traque apply the power of one place
* @param idPlayer The id of the traque
* @param game The game
* @param cardName The card name
* @param game The game
*/
public
static
void
applyPlaceCardPower
(
int
idPlayer
,
Game
game
,
CardName
cardN
ame
)
{
public
static
void
applyPlaceCardPower
(
int
idPlayer
,
CardName
cardName
,
Game
g
ame
)
{
switch
(
cardName
)
{
case
ANTRE:
applyPlaceAntre
(
idPlayer
,
game
);
...
...
@@ -246,10 +243,10 @@ public class PowerApplicator {
public
static
void
applyTrackingCardPower
(
int
idPlayer
,
Game
game
,
CardName
cardName
)
{
switch
(
cardName
)
{
case
ACHARNEMENT:
applyTrackingAcharnement
(
idPlayer
,
game
);
applyTrackingAcharnement
(
game
);
break
;
case
ANGOISSE:
applyTrackingAngoisse
(
idPlayer
,
game
);
applyTrackingAngoisse
(
game
);
break
;
case
ANTICIPATION:
applyTrackingAnticipation
(
idPlayer
,
game
);
...
...
@@ -258,15 +255,16 @@ public class PowerApplicator {
applyTrackingCataclysme
(
idPlayer
,
game
);
break
;
case
CHAMP_DE_FORCE:
applyTrackingChampDeForce
(
idPlayer
,
game
);
applyTrackingChampDeForce
(
game
);
break
;
case
CLONE:
applyTrackingClone
(
idPlayer
,
game
);
applyTrackingClone
(
game
);
break
;
case
DEPLOIEMENT:
applyTrackingDeploiement
(
idPlayer
,
game
);
break
;
case
DESESPOIR:
applyTrackingDesespoir
(
idPlayer
,
game
);
applyTrackingDesespoir
(
game
);
break
;
case
DETOUR:
applyTrackingDetour
(
idPlayer
,
game
);
...
...
@@ -308,7 +306,7 @@ public class PowerApplicator {
applyTrackingIntuition
(
idPlayer
,
game
);
break
;
case
MAGNETISME:
applyTrackingMagnetisme
(
idPlayer
,
game
);
applyTrackingMagnetisme
(
game
);
break
;
case
MIRAGE:
applyTrackingMirage
(
game
);
...
...
@@ -366,10 +364,10 @@ public class PowerApplicator {
applySurvivalAlerte
(
idPlayer
,
game
);
break
;
case
AMPLIFICATEUR:
applySurvivalAmplificateur
(
idPlayer
,
game
);
applySurvivalAmplificateur
(
game
);
break
;
case
BROUILLAGE:
applySurvivalBrouillage
(
idPlayer
,
game
);
applySurvivalBrouillage
(
game
);
break
;
case
CAVALE:
applySurvivalCavale
(
idPlayer
,
game
);
...
...
@@ -381,7 +379,7 @@ public class PowerApplicator {
applySurvivalDrone
(
idPlayer
,
game
);
break
;
case
ENTRAVE:
applySurvivalEntrave
(
idPlayer
,
game
);
applySurvivalEntrave
(
game
);
break
;
case
EQUIPEMENT:
applySurvivalEquipement
(
idPlayer
,
game
);
...
...
@@ -402,7 +400,7 @@ public class PowerApplicator {
applySurvivalMimetisme
(
idPlayer
,
game
);
break
;
case
NAVETTE:
applySurvivalNavette
(
idPlayer
,
game
);
applySurvivalNavette
(
game
);
break
;
case
PLANQUES:
applySurvivalPlanques
(
idPlayer
,
game
);
...
...
@@ -411,7 +409,7 @@ public class PowerApplicator {
applySurvivalPortail
(
idPlayer
,
game
);
break
;
case
RALLIEMENT:
applySurvivalRalliement
(
idPlayer
,
game
);
applySurvivalRalliement
(
game
);
break
;
case
REFUGE:
applySurvivalRefuge
(
idPlayer
,
game
);
...
...
@@ -426,7 +424,7 @@ public class PowerApplicator {
applySurvivalRetraite
(
idPlayer
,
game
);
break
;
case
RIPOSTE:
applySurvivalRiposte
(
idPlayer
,
game
);
applySurvivalRiposte
(
game
);
break
;
case
SACRIFICE:
applySurvivalSacrifice
(
idPlayer
,
game
);
...
...
@@ -438,13 +436,13 @@ public class PowerApplicator {
applySurvivalSixiemeSens
(
idPlayer
,
game
);
break
;
case
SYSTEME_D:
applySurvivalSystemeD
(
idPlayer
,
game
);
applySurvivalSystemeD
(
game
);
break
;
case
TENACITE:
applySurvivalTenacite
(
idPlayer
,
game
);
break
;
case
VACCIN:
applySurvivalVaccin
(
idPlayer
,
game
);
applySurvivalVaccin
(
game
);
break
;
case
VOLTE_FACE:
applySurvivalVolteFace
(
idPlayer
,
game
);
...
...
@@ -457,29 +455,6 @@ public class PowerApplicator {
}
}
/**
* Apply the power of jeton placed on the place card on the traque
* @param idPlayer The id of the traque
* @param game The game
* @param placeCard The place card
*/
public
static
void
applyJeton
(
int
idPlayer
,
Game
game
,
PlaceCard
placeCard
)
{
List
<
Jeton
>
jetons
=
game
.
getPlanet
().
findJetonsOnCard
(
placeCard
);
for
(
Jeton
jeton
:
jetons
)
{
switch
(
jeton
.
getType
())
{
case
CIBLE:
applyJetonCible
(
idPlayer
,
game
);
break
;
case
ARTEMIA:
applyJetonArtemia
(
idPlayer
,
game
);
break
;
case
CREATURE:
applyJetonCreature
(
idPlayer
,
game
,
placeCard
);
break
;
}
}
}
/**
* Apply the power of Jeton Artemia on the player
* @param idPlayer The id of the player
...
...
@@ -1011,11 +986,11 @@ public class PowerApplicator {
* Apply tracking card
***********************************/
private
static
void
applyTrackingAcharnement
(
int
idPlayer
,
Game
game
)
{
private
static
void
applyTrackingAcharnement
(
Game
game
)
{
game
.
addNumberWillingnessByJetonCreature
();
}
private
static
void
applyTrackingAngoisse
(
int
idPlayer
,
Game
game
)
{
private
static
void
applyTrackingAngoisse
(
Game
game
)
{
game
.
setTraqueCanResist
(
false
);
}
...
...
@@ -1030,12 +1005,12 @@ public class PowerApplicator {
}
private
static
void
applyTrackingChampDeForce
(
int
idPlayer
,
Game
game
)
{
private
static
void
applyTrackingChampDeForce
(
Game
game
)
{
game
.
getGameRoundVariables
().
setJetonCibleBlockPlace
(
true
);
game
.
getGameRoundVariables
().
setJetonCibleCanBeOnTwoAdjacentPlaces
(
true
);
}
private
static
void
applyTrackingClone
(
int
idPlayer
,
Game
game
)
{
private
static
void
applyTrackingClone
(
Game
game
)
{
BiConsumer
<
Integer
,
Game
>
action
=
(
Integer
id
,
Game
g
)
->
{
Traque
traque
=
(
Traque
)
g
.
getPlayer
(
id
);
List
<
PlaceCard
>
placeCards
=
traque
.
getPlaceCardsPlayed
();
...
...
@@ -1063,7 +1038,7 @@ public class PowerApplicator {
moveJetonOnAdjacentPlace
(
idPlayer
,
game
,
JetonSymbol
.
CREATURE
);
}
private
static
void
applyTrackingDesespoir
(
int
idPlayer
,
Game
game
)
{
private
static
void
applyTrackingDesespoir
(
Game
game
)
{
game
.
setTraqueCanPickSurvivalCards
(
false
);
}
...
...
@@ -1073,11 +1048,9 @@ public class PowerApplicator {
private
static
void
applyTrackingDomination
(
int
idPlayer
,
Game
game
)
{
int
targetPlayer
=
game
.
targetPlayer
(
idPlayer
);
BiConsumer
<
Integer
,
Game
>
action
=
(
Integer
id
,
Game
g
)
->
{
throwAwayPlaceCards
(
id
,
g
,
1
);
};
BiConsumer
<
Integer
,
Game
>
action
=
(
Integer
id
,
Game
g
)
->
throwAwayPlaceCards
(
id
,
g
,
1
);
Bi
Function
<
Integer
,
Game
,
Boolean
>
condition
=
(
Integer
id
,
Game
g
)
->
{
Bi
Predicate
<
Integer
,
Game
>
condition
=
(
Integer
id
,
Game
g
)
->
{
GameRoundVariables
variables
=
game
.
getGameRoundVariables
();
return
!
variables
.
getPlayerWhoHaveLostAllWillingness
().
contains
(
id
);
};
...
...
@@ -1090,7 +1063,7 @@ public class PowerApplicator {
GameRoundVariables
variables
=
game
.
getGameRoundVariables
();
List
<
Integer
>
haveResistPlayers
=
variables
.
getPlayersWhoHaveResist
();
if
(!
haveResistPlayers
.
isEmpty
()){
int
targetPlayer
=
-
1
;
int
targetPlayer
;
do
{
targetPlayer
=
game
.
targetPlayer
(
idPlayer
);
}
...
...
@@ -1187,7 +1160,7 @@ public class PowerApplicator {
creature
.
playTrackingCard
(
trackingCard
);
}
private
static
void
applyTrackingMagnetisme
(
int
idPlayer
,
Game
game
)
{
private
static
void
applyTrackingMagnetisme
(
Game
game
)
{
game
.
getGameRoundVariables
().
setJetonCibleAdjacentPlaceMoveTraque
(
true
);
}
...
...
@@ -1241,9 +1214,7 @@ public class PowerApplicator {
Traque
traque
=
(
Traque
)
g
.
getPlayer
(
id
);
traque
.
addWillingness
(
1
);
};
BiConsumer
<
Integer
,
Game
>
actionAdjacent
=
(
Integer
id
,
Game
g
)
->
{
subWillingness
(
id
,
g
,
1
);
};
BiConsumer
<
Integer
,
Game
>
actionAdjacent
=
(
Integer
id
,
Game
g
)
->
subWillingness
(
id
,
g
,
1
);
game
.
getGameRoundVariables
().
setActionJetonCible
(
action
);
game
.
getGameRoundVariables
().
setActionAdjacentPlaceJetonCible
(
actionAdjacent
);
}
...
...
@@ -1258,10 +1229,10 @@ public class PowerApplicator {
Traque
traque
=
(
Traque
)
game
.
getPlayer
(
targetPlayer
);
if
(
traque
.
placeCardHandSize
()
>
1
)
{
List
<
PlaceCard
>
hand
=
traque
.
getPlaceCards
();
int
indice
=
(
int
)
Math
.
floor
(
Math
.
random
()*(
hand
.
size
()-
1
));
PlaceCard
random
=
hand
.
get
(
indice
);
traque
.
throwAwayPlaceCard
(
random
);
if
(
random
.
equals
(
placeCard
))
{
int
indice
=
new
Random
().
nextInt
(
hand
.
size
(
));
PlaceCard
random
Card
=
hand
.
get
(
indice
);
traque
.
throwAwayPlaceCard
(
random
Card
);
if
(
random
Card
.
equals
(
placeCard
))
{
game
.
getBoard
().
moveForwardCreature
();
}
}
...
...
@@ -1272,9 +1243,7 @@ public class PowerApplicator {
}
private
static
void
applyTrackingToxine
(
Game
game
)
{
BiConsumer
<
Integer
,
Game
>
action
=
(
Integer
id
,
Game
g
)
->
{
throwAwaySurvivalCards
(
id
,
g
,
1
);
};
BiConsumer
<
Integer
,
Game
>
action
=
(
Integer
id
,
Game
g
)
->
throwAwaySurvivalCards
(
id
,
g
,
1
);
GameRoundVariables
variables
=
game
.
getGameRoundVariables
();
variables
.
setActionJetonCible
(
action
);
variables
.
setJetonCibleBlockPlace
(
true
);
...
...
@@ -1311,7 +1280,7 @@ public class PowerApplicator {
game
.
getGameRoundVariables
().
setTargetByAlerte
(
place
);
}
private
static
void
applySurvivalAmplificateur
(
int
idPlayer
,
Game
game
)
{
private
static
void
applySurvivalAmplificateur
(
Game
game
)
{
Planet
planet
=
game
.
getPlanet
();
if
(
planet
.
getPlanetPawnType
().
equals
(
PawnType
.
BEACON
))
{
if
(!
planet
.
planetPawnIsActive
())
{
...
...
@@ -1327,7 +1296,7 @@ public class PowerApplicator {
}
}
private
static
void
applySurvivalBrouillage
(
int
idPlayer
,
Game
game
)
{
private
static
void
applySurvivalBrouillage
(
Game
game
)
{
game
.
getGameRoundVariables
().
setDefaussePlaceCardsAreHidden
(
true
);
}
...
...
@@ -1347,7 +1316,7 @@ public class PowerApplicator {
game
.
getGameRoundVariables
().
addPlayersWhoHavePlayDrone
(
idPlayer
);
}
private
static
void
applySurvivalEntrave
(
int
idPlayer
,
Game
game
)
{
private
static
void
applySurvivalEntrave
(
Game
game
)
{
game
.
getGameRoundVariables
().
setCanPlaceJetonCreatureOnPlaces6To10
(
false
);
}
...
...
@@ -1393,7 +1362,7 @@ public class PowerApplicator {
game
.
getGameRoundVariables
().
addPlayersWhoHavePlayMimetisme
(
idPlayer
);
}
private
static
void
applySurvivalNavette
(
int
idPlayer
,
Game
game
)
{
private
static
void
applySurvivalNavette
(
Game
game
)
{
int
scoreTraque
=
game
.
getBoard
().
getScore
().
getScoreTraque
();
if
(
scoreTraque
==
1
)
{
game
.
getBoard
().
moveForwardTraque
();
...
...
@@ -1412,7 +1381,7 @@ public class PowerApplicator {
game
.
getGameRoundVariables
().
addPlayersWhoHavePlayPortail
(
idPlayer
);
}
private
static
void
applySurvivalRalliement
(
int
idPlayer
,
Game
game
)
{
private
static
void
applySurvivalRalliement
(
Game
game
)
{
game
.
getGameRoundVariables
().
setRalliementIsActive
(
true
);
}
...
...
@@ -1436,7 +1405,7 @@ public class PowerApplicator {
moveTraqueOnAdjacentPlaceAndAddHimToRetraiteList
(
idPlayer
,
game
);
}
private
static
void
applySurvivalRiposte
(
int
idPlayer
,
Game
game
)
{
private
static
void
applySurvivalRiposte
(
Game
game
)
{
List
<
TrackingCard
>
trackingCards
=
game
.
getCreature
().
getTrackingCardHand
();
int
maxToThrowAway
=
Math
.
min
(
2
,
trackingCards
.
size
());
List
<
TrackingCard
>
trashCards
=
new
ArrayList
<>();
...
...
@@ -1470,7 +1439,7 @@ public class PowerApplicator {
takeBackCardsFromDefausse
(
idPlayer
,
game
,
2
);
}
private
static
void
applySurvivalSystemeD
(
int
idPlayer
,
Game
game
)
{
private
static
void
applySurvivalSystemeD
(
Game
game
)
{
Planet
planet
=
game
.
getPlanet
();
if
(!
planet
.
planetPawnIsActive
())
{
planet
.
forceMovePlanetPawn
();
...
...
@@ -1482,7 +1451,7 @@ public class PowerApplicator {
traque
.
getRights
().
setNumberOfAdditionalCardsTakeBackPerPawnWillingnessLostWithResist
(
1
);
}
private
static
void
applySurvivalVaccin
(
int
idPlayer
,
Game
game
)
{
private
static
void
applySurvivalVaccin
(
Game
game
)
{
game
.
getBoard
().
moveBackCreature
();
}
...
...
@@ -1494,9 +1463,6 @@ public class PowerApplicator {
Player
player
=
game
.
getPlayer
(
idPlayer
);
checkPlayerIsNotCreature
(
player
);
Traque
traque
=
(
Traque
)
player
;
if
(
traque
.
getDefausse
().
isEmpty
()){
return
;
}
PlaceCard
placeCard
=
game
.
choosePlaceCardsAction
(
idPlayer
,
1
,
traque
.
getDefausse
()).
get
(
0
);
traque
.
takeBackPlayedPlaceCards
();
traque
.
takeBackPlaceCard
(
placeCard
);
...
...
@@ -1548,14 +1514,14 @@ public class PowerApplicator {
return
;
}
List
<
Place
>
hiddenPlaces
=
planet
.
getHiddenPlaces
();
Place
revealedPlace
=
null
;
Place
revealedPlace
;
do
{
revealedPlace
=
game
.
choosePlace
(
idPlayer
,
1
,
"Choississez un lieu à révéler"
).
get
(
0
);
}
while
(
revealedPlace
==
null
&&
!
hiddenPlaces
.
contains
(
revealedPlace
));
while
(
revealedPlace
==
null
||
!
hiddenPlaces
.
contains
(
revealedPlace
));
planet
.
revealPlace
(
revealedPlace
);
PlaceCard
placeCard
=
planet
.
placeToPlaceCard
(
revealedPlace
);
applyPlaceCardPower
(
idPlayer
,
game
,
placeCard
.
getCardName
()
);
applyPlaceCardPower
(
idPlayer
,
placeCard
.
getCardName
(),
game
);
}
/**
...
...
@@ -1612,16 +1578,14 @@ public class PowerApplicator {
checkPlayerIsNotCreature
(
player
);
Traque
traque
=
(
Traque
)
player
;
List
<
PlaceCard
>
placeCards
=
traque
.
getDefausse
();
if
(
placeCards
.
isEmpty
())
{
return
;
}
else
if
(
placeCards
.
size
()
<=
numberCards
)
{
traque
.
takeBackAllPlaceCardFromDefausse
();
}
else
{
int
maxCardsToTakeBack
=
Math
.
min
(
numberCards
,
placeCards
.
size
());
List
<
PlaceCard
>
cardsTakeBack
=
game
.
choosePlaceCardsAction
(
idPlayer
,
maxCardsToTakeBack
,
placeCards
);
traque
.
takeBackPlaceCard
(
cardsTakeBack
);
if
(!
placeCards
.
isEmpty
())
{
if
(
placeCards
.
size
()
<=
numberCards
)
{
traque
.
takeBackAllPlaceCardFromDefausse
();
}
else
{
List
<
PlaceCard
>
cardsTakeBack
=
game
.
choosePlaceCardsAction
(
idPlayer
,
numberCards
,
placeCards
);
traque
.
takeBackPlaceCard
(
cardsTakeBack
);
}
}
}
...
...
@@ -1685,7 +1649,7 @@ public class PowerApplicator {
}
PlaceCard
card
=
placeCards
.
get
(
0
);
if
(
card
.
getCardName
()
!=
ARTEFACT
)
{
applyPlaceCardPower
(
idPlayer
,
game
,
card
.
getCardName
()
);
applyPlaceCardPower
(
idPlayer
,
card
.
getCardName
(),
game
);
}
}
...
...
@@ -1700,7 +1664,7 @@ public class PowerApplicator {
Traque
traque
=
(
Traque
)
player
;
List
<
PlaceCard
>
placeCards
=
traque
.
getDefausse
();
PlaceCard
placeCard
=
game
.
choosePlaceCardsAction
(
idPlayer
,
1
,
placeCards
).
get
(
0
);
applyPlaceCardPower
(
idPlayer
,
game
,
placeCard
.
getCardName
()
);
applyPlaceCardPower
(
idPlayer
,
placeCard
.
getCardName
(),
game
);
}
/**
...
...
@@ -1711,9 +1675,9 @@ public class PowerApplicator {
* @param b The end of interval
*/
public
static
void
copyPowerOfOneCardInInterval
(
int
idPlayer
,
Game
game
,
int
a
,
int
b
)
{
List
<
PlaceCard
>
choosableCards
=
game
.
getPlanet
().
getPlaceCardsInInterval
(
2
,
5
);
List
<
PlaceCard
>
choosableCards
=
game
.
getPlanet
().
getPlaceCardsInInterval
(
a
,
b
);
PlaceCard
placeCard
=
game
.
choosePlaceCardsAction
(
idPlayer
,
1
,
choosableCards
).
get
(
0
);
applyPlaceCardPower
(
idPlayer
,
game
,
placeCard
.
getCardName
()
);
applyPlaceCardPower
(
idPlayer
,
placeCard
.
getCardName
(),
game
);
}
/**
...
...
@@ -1731,7 +1695,7 @@ public class PowerApplicator {
}
}
PlaceCard
copiedCard
=
game
.
choosePlaceCardsAction
(
idPlayer
,
1
,
choosableCards
).
get
(
0
);
applyPlaceCardPower
(
idPlayer
,
game
,
copiedCard
.
getCardName
()
);
applyPlaceCardPower
(
idPlayer
,
copiedCard
.
getCardName
(),
game
);
}
/**
...
...
@@ -1871,7 +1835,7 @@ public class PowerApplicator {
boolean
isAdjacentPlace
=
false
;
Planet
planet
=
game
.
getPlanet
();
List
<
Place
>
places
=
planet
.
findPlacesWhereJetonIs
(
symbol
);
Place
adjacent
=
null
;
Place
adjacent
;
do
{
adjacent
=
game
.
choosePlace
(
idPlayer
,
1
,
"Choose place adjacent to JetonCreature"
).
get
(
0
);
for
(
Place
place
:
places
)
{
...
...
@@ -1889,14 +1853,13 @@ public class PowerApplicator {
* @param game The game
*/
public
static
Pair
<
Place
,
Place
>
chooseTwoAdjacentPlace
(
int
idPlayer
,
Game
game
)
{
boolean
isAdjacentPlace
=
false
;
Planet
planet
=
game
.
getPlanet
();
boolean
isAdjacentPlace
;
List
<
Place
>
places
;
Pair
<
Place
,
Place
>
pair
;
do
{
places
=
game
.
choosePlace
(
idPlayer
,
2
,
"Choose two adjacent places"
);
pair
=
new
Pair
<>(
places
.
get
(
0
),
places
.
get
(
1
));
isAdjacentPlace
=
p
lanet
.
isAdjacentPlaces
(
pair
.
getKey
(),
pair
.
getValue
());
isAdjacentPlace
=
P
lanet
.
isAdjacentPlaces
(
pair
.
getKey
(),
pair
.
getValue
());
}
while
(!
isAdjacentPlace
);
return
pair
;
...
...
@@ -1964,14 +1927,16 @@ public class PowerApplicator {
GameRoundVariables
variables
=
game
.
getGameRoundVariables
();
Planet
planet
=
game
.
getPlanet
();
if
(
variables
.
inertieTrackingCardIsPlayed
())
{
List
<
Place
>
placesWhereJetonIs
=
planet
.
findPlacesWhereJetonIs
(
JetonSymbol
.
CIBLE
);
boolean
isTraqueOnThePlaces
=
false
;
for
(
Traque
traque
:
game
.
getTraques
())
{
for
(
PlaceCard
playerCard
:
traque
.
getPlaceCardsPlayed
())
{
for
(
Place
jetonPlace
:
placesWhereJetonIs
){
if
(
planet
.
isAdjacentPlaces
(
playerCard
,
jetonPlace
)){
isTraqueOnThePlaces
=
true
;
}
List
<
PlaceCard
>
cardsTargetByJetonCible
=
planet
.
findPlaceCardsWhereJetonIs
(
JetonSymbol
.
CIBLE
);
Iterator
<
Traque
>
iteratorTraque
=
game
.
getTraques
().
iterator
();
while
(!
isTraqueOnThePlaces
&&
iteratorTraque
.
hasNext
())
{
Traque
traque
=
iteratorTraque
.
next
();
List
<
PlaceCard
>
placeCardsPlayed
=
traque
.
getPlaceCardsPlayed
();
Iterator
<
PlaceCard
>
iteratorPlayed
=
placeCardsPlayed
.
iterator
();
while
(!
isTraqueOnThePlaces
&&
iteratorPlayed
.
hasNext
())
{
if
(
cardsTargetByJetonCible
.
contains
(
iteratorPlayed
.
next
()))
{
isTraqueOnThePlaces
=
true
;
}
}
}
...
...
@@ -1993,7 +1958,6 @@ public class PowerApplicator {
}
public
static
boolean
checkIfAdjacentToJetonCible
(
Game
game
,
PlaceCard
placeCard
)
{
GameRoundVariables
variables
=
game
.
getGameRoundVariables
();
Planet
planet
=
game
.
getPlanet
();
List
<
Place
>
placesWhereJetonIs
=
planet
.
findPlacesWhereJetonIs
(
JetonSymbol
.
CIBLE
);
boolean
isAdjacent
=
false
;
...
...
@@ -2006,7 +1970,6 @@ public class PowerApplicator {
}
public
static
PlaceCard
findPlaceCardWhereTheJetonCibleIsAndAdjacent
(
Game
game
,
PlaceCard
placeCard
)
{
GameRoundVariables
variables
=
game
.
getGameRoundVariables
();
Planet
planet
=
game
.
getPlanet
();
List
<
Place
>
placesWhereJetonIs
=
planet
.
findPlacesWhereJetonIs
(
JetonSymbol
.
CIBLE
);
PlaceCard
jetonCiblePlaceCard
=
null
;
...
...
not-alone-server/src/main/java/fr/univnantes/alma/server/game/item/power/recurrent/PowerRecurrent.java
View file @
a60e88b2
package
fr.univnantes.alma.server.game.item.power.recurrent
;
import
fr.univnantes.alma.server.game.Game
;
import
fr.univnantes.alma.server.game.item.Phase
;
import
fr.univnantes.alma.server.game.item.power.Power
;
import
fr.univnantes.alma.server.game.item.power.PowerType
;
import
java.util.function.BiConsumer
;
import
java.util.function.Bi
Function
;
import
java.util.function.Bi
Predicate
;
public
class
PowerRecurrent
extends
Power
{
private
BiConsumer
<
Integer
,
Game
>
action
;
private
BiFunction
<
Integer
,
Game
,
Boolean
>
condition
;
private
Phase
phase
;
private
final
BiConsumer
<
Integer
,
Game
>
action
;
private
final
BiPredicate
<
Integer
,
Game
>
condition
;
public
PowerRecurrent
(
int
inGameIdPlayer
,
BiConsumer
<
Integer
,
Game
>
action
,
Bi
Function
<
Integer
,
Game
,
Boolean
>
condition
)
{
public
PowerRecurrent
(
int
inGameIdPlayer
,
BiConsumer
<
Integer
,
Game
>
action
,
Bi
Predicate
<
Integer
,
Game
>
condition
)
{
super
(
inGameIdPlayer
);
this
.
action
=
action
;
this
.
condition
=
condition
;
...
...
@@ -25,7 +23,7 @@ public class PowerRecurrent extends Power {
}
public
boolean
conditionIsTrue
(
Game
game
)
{
return
condition
.
apply
(
inGameIdPlayer
,
game
);
return
condition
.
test
(
inGameIdPlayer
,
game
);
}
@Override
...
...
not-alone-server/src/test/java/fr/univnantes/alma/server/PowerApplicatorTest.java
→
not-alone-server/src/test/java/fr/univnantes/alma/server/
game/
PowerApplicatorTest.java
View file @
a60e88b2
package
fr.univnantes.alma.server
;
package
fr.univnantes.alma.server
.game
;
import
fr.univnantes.alma.common.NotAloneDatabase
;
import
fr.univnantes.alma.data.DatabaseFactory
;
...
...
@@ -1404,6 +1404,33 @@ class PowerApplicatorTest {
assertEquals
(
Collections
.
singletonList
(
nexus
),
traque
.
getPlaceCards
());
}
@Test
void
testResolvePlace_archipelCantPickSurvivalCard
()
throws
TException
{
Game
game
=
new
Game
(
2
,
1
,
planetExtension
,
board
,
room
,
gameClientHandler
);
game
.
setTraqueCanPickSurvivalCards
(
false
);
TAction
chooseADefausseCard
=
new
TAction
(
CHOOSE_CARD
.
toString
(),
Collections
.
singletonList
(
new
TPair
(
TPairType
.
CARD
.
toString
(),
NEXUS
.
toString
())));
when
(
gameClientHandler
.
askAction
(
any
(
TAskAction
.
class
)))
.
thenReturn
(
chooseSecondPower
)
.
thenReturn
(
chooseADefausseCard
);
Traque
traque
=
(
Traque
)
game
.
getPlayer
(
2
);
List
<
PlaceCard
>
throwAwayCards
=
Arrays
.
asList
(
nexus
,
oasis
,
fjord
,
dome
,
labyrinthe
);
traque
.
throwAwayPlaceCard
(
throwAwayCards
);
traque
.
addPlaceCard
(
archipel
);
traque
.
playPlaceCard
(
archipel
);
PowerApplicator
.
resolvePlace
(
traque
.
getInGameId
(),
archipel
,
game
);
//Verify that traque has only Nexus
assertEquals
(
Collections
.
singletonList
(
nexus
),
traque
.
getPlaceCards
());
}
@Test
void
testResolvePlace_poleFirstPower
()
throws
TException
,
NotFoundException
{
Game
game
=
new
Game
(
2
,
1
,
planetExtension
,
board
,
room
,
gameClientHandler
);
...
...
@@ -1533,6 +1560,64 @@ class PowerApplicatorTest {
assertEquals
(
Collections
.
singletonList
(
nexus
),
traque
.
getPlaceCards
());
}
@Test
void
testResolvePlace_fungiFistPowerCantPickSurvival
()
throws
TException
{
Game
game
=
new
Game
(
2
,
1
,
planetExtension
,
board
,
room
,
gameClientHandler
);
game
.
setTraqueCanPickSurvivalCards
(
false
);
when
(
gameClientHandler
.
askAction
(
any
(
TAskAction
.
class
)))
.
thenReturn
(
chooseFirstPower
);
Traque
traque
=
(
Traque
)
game
.
getPlayer
(
2
);
traque
.
subWillingness
(
2
);
List
<
PlaceCard
>
throwAwayCards
=
Arrays
.
asList
(
nexus
,
oasis
,
fjord
,
dome
,
labyrinthe
);
traque
.
throwAwayPlaceCard
(
throwAwayCards
);
traque
.
addPlaceCard
(
fungi
);
traque
.
playPlaceCard
(
fungi
);
PowerApplicator
.
resolvePlace
(
traque
.
getInGameId
(),
fungi
,
game
);
assertTrue
(
game
.
getGameRoundVariables
().
isPawnWillingnessOnBoard
());
game
.
nextRound
();
assertEquals
(
2
,
traque
.
getNumberWillingness
());
assertTrue
(
game
.
getGameRoundVariables
().
isPawnWillingnessOnBoard
());
game
.
nextRound
();