| 1 | package de.aikiit.game.kaiser; | |
| 2 | ||
| 3 | import java.util.Objects; | |
| 4 | import java.util.Scanner; | |
| 5 | ||
| 6 | /** | |
| 7 | * This class encapsulates the actual game flow. | |
| 8 | * A player | |
| 9 | * <ul> | |
| 10 | * <li>is shown current statistics and</li> | |
| 11 | * <li>can start to act</li> | |
| 12 | * <li>until the maximum number of rounds is reached and the game ends.</li> | |
| 13 | * </ul> | |
| 14 | */ | |
| 15 | public class KaiserGame { | |
| 16 | ||
| 17 | /** | |
| 18 | * The player can play at most this number of rounds. | |
| 19 | */ | |
| 20 | public static final int MAX_ROUNDS = 10; | |
| 21 | ||
| 22 | private final KaiserEngine engine; | |
| 23 | private final KaiserEnginePrinter printer; | |
| 24 | private final Scanner input; | |
| 25 | ||
| 26 | /** | |
| 27 | * Initializes a game with default parameters. | |
| 28 | */ | |
| 29 | public KaiserGame() { | |
| 30 | this(new KaiserEngine(), new Scanner(System.in)); | |
| 31 | } | |
| 32 | ||
| 33 | /** | |
| 34 | * Allows setting an explicit engine for testing purposes. | |
| 35 | * @param engine initialize with the given engine. | |
| 36 | */ | |
| 37 | KaiserGame(KaiserEngine engine, Scanner input) { | |
| 38 | this.engine = Objects.requireNonNull(engine); | |
| 39 | this.input = Objects.requireNonNull(input); | |
| 40 | this.printer = new KaiserEnginePrinter(this.engine); | |
| 41 | } | |
| 42 | ||
| 43 | /** | |
| 44 | * Shows the introduction and start confirmation without the original BASIC code | |
| 45 | * gate, then runs the reign until completion, dismissal or an abort. A replay | |
| 46 | * starts again with the introduction and start confirmation. | |
| 47 | */ | |
| 48 | public void run() { | |
| 49 | boolean playAgain; | |
| 50 | do { | |
| 51 | playAgain = false; | |
| 52 |
1
1. run : removed call to de/aikiit/game/kaiser/KaiserGame::intro → SURVIVED |
intro(); |
| 53 |
1
1. run : removed call to java/io/PrintStream::println → KILLED |
System.out.println("Start (J/N)?"); |
| 54 |
1
1. run : negated conditional → KILLED |
if ("n".equalsIgnoreCase(nextAnswer())) { |
| 55 |
1
1. run : removed call to de/aikiit/game/kaiser/KaiserEngine::abort → KILLED |
engine.abort(); |
| 56 | break; | |
| 57 | } | |
| 58 |
1
1. run : negated conditional → KILLED |
while (!engine.isGameOver()) { |
| 59 |
1
1. run : removed call to de/aikiit/game/kaiser/KaiserEngine::startNewRound → KILLED |
engine.startNewRound(); |
| 60 |
1
1. run : removed call to de/aikiit/game/kaiser/KaiserGame::status → KILLED |
status(); |
| 61 |
1
1. run : negated conditional → KILLED |
if (engine.isGameOver()) { |
| 62 | break; // BASIC line 270: final report, but no eleventh action phase. | |
| 63 | } | |
| 64 |
1
1. run : removed call to de/aikiit/game/kaiser/KaiserEngine::prepareLandTrading → KILLED |
engine.prepareLandTrading(); |
| 65 |
1
1. run : removed call to java/io/PrintStream::println → KILLED |
System.out.println("Ein Hektar Land kostet " + engine.getLandPrice() + " dt Getreide."); |
| 66 |
1
1. run : removed call to de/aikiit/game/kaiser/KaiserGame::actions → KILLED |
actions(); |
| 67 |
1
1. run : negated conditional → KILLED |
if (!engine.isGameOver()) { |
| 68 |
1
1. run : removed call to de/aikiit/game/kaiser/KaiserEngine::finishRoundAfterActions → KILLED |
engine.finishRoundAfterActions(); |
| 69 | } | |
| 70 | } | |
| 71 | switch (engine.getState()) { | |
| 72 |
1
1. run : removed call to java/io/PrintStream::println → KILLED |
case DISMISSED -> System.out.println(printer.getDismissal()); |
| 73 |
1
1. run : removed call to java/io/PrintStream::println → KILLED |
case ABORTED -> System.out.println("Das kann man nicht mit mir machen! Suchen Sie sich einen anderen zum Mitspielen!"); |
| 74 | case COMPLETED -> { | |
| 75 |
1
1. run : removed call to de/aikiit/game/kaiser/KaiserGame::finish → KILLED |
finish(); |
| 76 | // Only the mediocre branch reaches the replay prompt in lines 959–966. | |
| 77 |
1
1. run : negated conditional → KILLED |
if (engine.getRegency() == KaiserEngine.Regency.MEDIOCRE) { |
| 78 |
1
1. run : removed call to java/io/PrintStream::println → KILLED |
System.out.println("Nochmal (J/N)?"); |
| 79 | playAgain = "j".equalsIgnoreCase(nextAnswer()); | |
| 80 |
1
1. run : negated conditional → KILLED |
if (playAgain) { |
| 81 |
1
1. run : removed call to de/aikiit/game/kaiser/KaiserEngine::reset → KILLED |
engine.reset(); |
| 82 | } | |
| 83 | } | |
| 84 | } | |
| 85 | default -> throw new IllegalStateException("Game ended without a final state."); | |
| 86 | } | |
| 87 |
1
1. run : negated conditional → KILLED |
} while (playAgain); |
| 88 |
1
1. run : removed call to de/aikiit/game/kaiser/KaiserGame::byeByeBanner → SURVIVED |
byeByeBanner(); |
| 89 | } | |
| 90 | ||
| 91 | /** | |
| 92 | * Shows information about the game flow and welcomes the player. | |
| 93 | */ | |
| 94 | public void intro() { | |
| 95 |
1
1. intro : removed call to de/aikiit/game/kaiser/KaiserGame::banner → SURVIVED |
banner(); |
| 96 |
1
1. intro : removed call to java/io/PrintStream::println → SURVIVED |
System.out.println("Versuchen Sie die antike Stadt " + KaiserEnginePrinter.ANSI_YELLOW + ">SUMERIA<" + KaiserEnginePrinter.ANSI_RESET + " zu regieren!"); |
| 97 |
1
1. intro : removed call to java/io/PrintStream::println → SURVIVED |
System.out.println("Ihre Regierungszeit beträgt " + MAX_ROUNDS + " Jahre."); |
| 98 |
1
1. intro : removed call to java/io/PrintStream::println → SURVIVED |
System.out.println("Nach jeweils einem Jahr erhalten Sie einen Bericht über die Entwicklung in der Stadt."); |
| 99 |
1
1. intro : removed call to java/io/PrintStream::println → SURVIVED |
System.out.println("Dann werden wir weitersehen ......."); |
| 100 |
1
1. intro : removed call to java/io/PrintStream::println → SURVIVED |
System.out.println(); |
| 101 | } | |
| 102 | ||
| 103 | /** | |
| 104 | * Shows the game's banner. | |
| 105 | */ | |
| 106 | public void banner() { | |
| 107 | // generated with the help of https://manytools.org/hacker-tools/ascii-banner/ | |
| 108 | // font: banner | |
| 109 |
1
1. banner : removed call to java/io/PrintStream::println → SURVIVED |
System.out.println(KaiserEnginePrinter.ANSI_RED); |
| 110 |
1
1. banner : removed call to java/io/PrintStream::println → SURVIVED |
System.out.println(""" |
| 111 | # # \s | |
| 112 | # # ## # #### ###### ##### \s | |
| 113 | # # # # # # # # #\s | |
| 114 | ### # # # #### ##### # #\s | |
| 115 | # # ###### # # # ##### \s | |
| 116 | # # # # # # # # # # \s | |
| 117 | # # # # # #### ###### # #\s | |
| 118 | \s | |
| 119 | """); | |
| 120 |
1
1. banner : removed call to java/io/PrintStream::println → SURVIVED |
System.out.println(KaiserEnginePrinter.ANSI_RESET); |
| 121 | } | |
| 122 | ||
| 123 | /** | |
| 124 | * Shows console banner after the game is over. | |
| 125 | */ | |
| 126 | public void byeByeBanner() { | |
| 127 | // generated with the help of https://manytools.org/hacker-tools/ascii-banner/ | |
| 128 | // font: banner | |
| 129 |
1
1. byeByeBanner : removed call to java/io/PrintStream::println → SURVIVED |
System.out.println(KaiserEnginePrinter.ANSI_RED); |
| 130 |
1
1. byeByeBanner : removed call to java/io/PrintStream::println → SURVIVED |
System.out.println(""" |
| 131 | ###### ###### # # \s | |
| 132 | # # # # ###### # # # # ###### # # ## # #### ###### ##### \s | |
| 133 | # # # # # # # # # # # # # # # # # # #\s | |
| 134 | ###### # ##### ###### # ##### ### # # # #### ##### # #\s | |
| 135 | # # # # # # # # # # ###### # # # ##### \s | |
| 136 | # # # # # # # # # # # # # # # # # # \s | |
| 137 | ###### # ###### ###### # ###### # # # # # #### ###### # #\s | |
| 138 | \n | |
| 139 | """); | |
| 140 |
1
1. byeByeBanner : removed call to java/io/PrintStream::println → SURVIVED |
System.out.println(KaiserEnginePrinter.ANSI_RESET); |
| 141 | } | |
| 142 | ||
| 143 | /** | |
| 144 | * Shows the underlying status of the current round the player is in. | |
| 145 | */ | |
| 146 | public void status() { | |
| 147 |
1
1. status : removed call to java/io/PrintStream::println → KILLED |
System.out.println(printer.getYearResult(engine.getYear())); |
| 148 |
1
1. status : negated conditional → SURVIVED |
if (engine.isPlagueOccurred()) { |
| 149 |
1
1. status : removed call to java/io/PrintStream::println → KILLED |
System.out.println(KaiserEnginePrinter.ORANGE |
| 150 | + "Eine fürchterliche Seuche hat die halbe Stadt dahingerafft!" | |
| 151 | + KaiserEnginePrinter.ANSI_RESET); | |
| 152 | } | |
| 153 |
1
1. status : removed call to java/io/PrintStream::println → SURVIVED |
System.out.println(printer.getStatus(engine.getYear())); |
| 154 | } | |
| 155 | ||
| 156 | /** | |
| 157 | * Performs user interactions. | |
| 158 | * The player can either | |
| 159 | * <ul> | |
| 160 | * <li>buy or sell land</li> | |
| 161 | * <li>feed the population</li> | |
| 162 | * <li>perform agricultural operations per round.</li> | |
| 163 | * </ul> | |
| 164 | */ | |
| 165 | public void actions() { | |
| 166 |
1
1. actions : removed call to java/io/PrintStream::println → SURVIVED |
System.out.println(); |
| 167 |
1
1. actions : removed call to java/io/PrintStream::println → SURVIVED |
System.out.println(KaiserEnginePrinter.ANSI_PURPLE + "#+#+#+#+ Was möchten Sie tun?" + KaiserEnginePrinter.ANSI_RESET); |
| 168 | ||
| 169 | // only buy or sell is allowed | |
| 170 |
2
1. actions : negated conditional → KILLED 2. actions : negated conditional → KILLED |
if (!KaiserActions.buy(engine, input) && !engine.isGameOver()) { |
| 171 |
1
1. actions : removed call to de/aikiit/game/kaiser/KaiserActions::sell → KILLED |
KaiserActions.sell(engine, input); |
| 172 | } | |
| 173 |
1
1. actions : negated conditional → KILLED |
if (!engine.isGameOver()) { |
| 174 |
1
1. actions : removed call to de/aikiit/game/kaiser/KaiserActions::feed → KILLED |
KaiserActions.feed(engine, input); |
| 175 | } | |
| 176 |
1
1. actions : negated conditional → KILLED |
if (!engine.isGameOver()) { |
| 177 |
1
1. actions : removed call to de/aikiit/game/kaiser/KaiserActions::cultivate → KILLED |
KaiserActions.cultivate(engine, input); |
| 178 | } | |
| 179 | ||
| 180 |
1
1. actions : removed call to java/io/PrintStream::println → SURVIVED |
System.out.println(); |
| 181 | } | |
| 182 | ||
| 183 | /** | |
| 184 | * Shows results after the game is over. | |
| 185 | */ | |
| 186 | public void finish() { | |
| 187 |
1
1. finish : removed call to java/io/PrintStream::println → SURVIVED |
System.out.println(printer.getResults()); |
| 188 |
1
1. finish : removed call to java/io/PrintStream::println → KILLED |
System.out.println(printer.evaluateRegency()); |
| 189 | } | |
| 190 | ||
| 191 | private String nextAnswer() { | |
| 192 |
2
1. nextAnswer : negated conditional → KILLED 2. nextAnswer : replaced return value with "" for de/aikiit/game/kaiser/KaiserGame::nextAnswer → KILLED |
return input.hasNext() ? input.next() : "n"; |
| 193 | } | |
| 194 | } | |
Mutations | ||
| 52 |
1.1 |
|
| 53 |
1.1 |
|
| 54 |
1.1 |
|
| 55 |
1.1 |
|
| 58 |
1.1 |
|
| 59 |
1.1 |
|
| 60 |
1.1 |
|
| 61 |
1.1 |
|
| 64 |
1.1 |
|
| 65 |
1.1 |
|
| 66 |
1.1 |
|
| 67 |
1.1 |
|
| 68 |
1.1 |
|
| 72 |
1.1 |
|
| 73 |
1.1 |
|
| 75 |
1.1 |
|
| 77 |
1.1 |
|
| 78 |
1.1 |
|
| 80 |
1.1 |
|
| 81 |
1.1 |
|
| 87 |
1.1 |
|
| 88 |
1.1 |
|
| 95 |
1.1 |
|
| 96 |
1.1 |
|
| 97 |
1.1 |
|
| 98 |
1.1 |
|
| 99 |
1.1 |
|
| 100 |
1.1 |
|
| 109 |
1.1 |
|
| 110 |
1.1 |
|
| 120 |
1.1 |
|
| 129 |
1.1 |
|
| 130 |
1.1 |
|
| 140 |
1.1 |
|
| 147 |
1.1 |
|
| 148 |
1.1 |
|
| 149 |
1.1 |
|
| 153 |
1.1 |
|
| 166 |
1.1 |
|
| 167 |
1.1 |
|
| 170 |
1.1 2.2 |
|
| 171 |
1.1 |
|
| 173 |
1.1 |
|
| 174 |
1.1 |
|
| 176 |
1.1 |
|
| 177 |
1.1 |
|
| 180 |
1.1 |
|
| 187 |
1.1 |
|
| 188 |
1.1 |
|
| 192 |
1.1 2.2 |