WIP : add TIE result
All checks were successful
rock-paper-cissors/pipeline/head This commit looks good

This commit is contained in:
2025-11-27 12:33:05 +01:00
parent a9de7a9448
commit 22bf1361ee
6 changed files with 37 additions and 8 deletions

View File

@@ -0,0 +1,7 @@
package fr.iut_fbleau.info.but3.automation.rock_paper_scissors.play.domain;
public enum GameResult {
WIN,
LOOSE,
TIE,
}

View File

@@ -6,12 +6,15 @@ public enum Move {
SCISSORS,
WELL;
public boolean beats(Move other) {
return switch (this) {
public GameResult beats(Move other) {
if (this.equals(other))
return GameResult.TIE;
boolean beats = switch (this) {
case ROCK -> other == SCISSORS;
case PAPER -> other == ROCK || other == WELL;
case SCISSORS -> other == PAPER;
case WELL -> other == ROCK || other == SCISSORS;
};
return beats ? GameResult.WIN : GameResult.LOOSE;
}
}

View File

@@ -11,12 +11,14 @@ public record RockPaperScissorsPlayer(CpuPick cpuPick, StatSave statSave) implem
public static final String WIN = "WIN";
public static final String LOOSE = "LOOSE";
public static final String TIE = "TIE";
@Override
public RoundResult playRound(String name, Move move) {
var cpuPicked = this.cpuPick.pick();
boolean beats = move.beats(cpuPicked);
String result = beats ? WIN : LOOSE;
GameResult beats = move.beats(cpuPicked);
String result = String.valueOf(beats);
if (result.equals(WIN)) {
this.statSave.addWin(name);
}