test: ajout de l'égalité

This commit is contained in:
2025-11-27 12:24:17 +01:00
parent bba8fd25e4
commit d908378ad9
3 changed files with 19 additions and 8 deletions

View File

@@ -6,8 +6,11 @@ public enum Move {
SCISSORS,
WELL;
public boolean beats(Move other) {
return switch (this) {
public Result beats(Move other) {
if(this.equals(other)){
return Result.EQUAL;
}
boolean result = switch (this) {
case ROCK -> other == SCISSORS;
case PAPER -> other == ROCK || other == WELL;
case SCISSORS -> other == PAPER;
@@ -15,5 +18,6 @@ public enum Move {
};
return result ? Result.WIN : Result.LOOSE;
}
}

View File

@@ -0,0 +1,8 @@
package fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain;
public enum Result {
WIN,
LOOSE,
EQUAL;
}

View File

@@ -9,17 +9,16 @@ import fr.iut_fbleau.info.but3.automation.rock_paper_scissors.stat.domain.StatSa
@DomainService
public record RockPaperScissorsPlayer(CpuPick cpuPick, StatSave statSave) implements RockPaperScissorsPlay {
public static final String WIN = "WIN";
public static final String LOOSE = "LOOSE";
@Override
public RoundResult playRound(String name, Move move) {
var cpuPicked = this.cpuPick.pick();
boolean beats = move.beats(cpuPicked);
String result = beats ? WIN : LOOSE;
if (result.equals(WIN)) {
Result beats = move.beats(cpuPicked);
if (beats.equals(Result.WIN)) {
this.statSave.addWin(name);
}
return new RoundResult(result, name, cpuPicked);
return new RoundResult(beats.toString(), name, cpuPicked);
}
}