Package: DilemmaRoundData
DilemmaRoundData
| name | instruction | branch | complexity | line | method | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| DilemmaRoundData(DilemmaRoundPlayerData, DilemmaRoundPlayerData) | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
| forOpponentOf(IDilemmaPlayer) | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
| forPlayer(IDilemmaPlayer) | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
| fromRaw(IDilemmaPlayer, IDilemmaMove, IDilemmaPlayer, IDilemmaMove) | 
  | 
  | 
  | 
  | 
  | 
||||||||||||||||||||
Coverage
1: package de.fhdw.gaming.ipspiel23.dilemma.strategy.internals;
2: 
3: import de.fhdw.gaming.ipspiel23.dilemma.domain.DilemmaAnswerType;
4: import de.fhdw.gaming.ipspiel23.dilemma.domain.IDilemmaPlayer;
5: import de.fhdw.gaming.ipspiel23.dilemma.moves.IDilemmaMove;
6: 
7: /**
8:  * The record of a single round of a dilemma game.
9:  * @param player1Data The round data of the first player.
10:  * @param player2Data The round data of the second player.
11:  */
12: public record DilemmaRoundData(DilemmaRoundPlayerData player1Data, DilemmaRoundPlayerData player2Data) {
13: 
14:     /**
15:      * Returns the round data for the given player.
16:      * @param player The player to get the data for. 
17:      * If no player in the round data set matches the supplied player 
18:      * object, an {@link IllegalArgumentException} will be thrown.
19:      * @return The round data for the given player.
20:      */
21:     public DilemmaRoundPlayerData forPlayer(final IDilemmaPlayer player) {
22:•        if (player1Data.player().getName().equals(player.getName())) {
23:             return player1Data;
24:         }
25:•        if (player2Data.player().getName().equals(player.getName())) {
26:             return player2Data;
27:         }
28:         throw new IllegalArgumentException("Unknown player: " + player);
29:     }
30: 
31:     /**
32:      * Returns the round data for the opponent of the given player.
33:      * @param player The player to get the data of the opponent for.
34:      * If no player in the round data set matches the supplied player 
35:      * object, an {@link IllegalArgumentException} will be thrown.
36:      * @return The round data for the opponent of the given player.
37:      */
38:     public DilemmaRoundPlayerData forOpponentOf(final IDilemmaPlayer player) {
39:•        if (player1Data.player().getName().equals(player.getName())) {
40:             return player2Data;
41:         }
42:•        if (player2Data.player().getName().equals(player.getName())) {
43:             return player1Data;
44:         }
45:         throw new IllegalArgumentException("Unknown player: " + player);
46:     }
47: 
48:     /**
49:      * Creates a new round data record from the given raw data.
50:      * @param player1 The first player.
51:      * @param player1Move The move of the first player.
52:      * @param player2 The second player.
53:      * @param player2Move The move of the second player.
54:      * @return The new round data record.
55:      */
56:     public static DilemmaRoundData fromRaw(final IDilemmaPlayer player1, final IDilemmaMove player1Move, 
57:             final IDilemmaPlayer player2, final IDilemmaMove player2Move) {
58:         final DilemmaAnswerType player1Answer = 
59:•            player1Move == null
60:                 ? null
61:                 : player1Move.getAnswer();
62:         final DilemmaAnswerType player2Answer = 
63:•            player2Move == null
64:                 ? null
65:                 : player2Move.getAnswer();
66:         final var player1Data = new DilemmaRoundPlayerData(player1, player1Answer, player1Move);
67:         final var player2Data = new DilemmaRoundPlayerData(player2, player2Answer, player2Move);
68:         return new DilemmaRoundData(player1Data, player2Data);
69:     }
70: }