Looking for just the winner

So my code is ready for the first round robin, (I hope) any idea how I can output only the winner in x amount of runs into a file to see if my bot is running better than the reference bot?

You would have to change the core game code or do something like write your own analyser…

This code will go through the log directory for all the matches, get the last folder and increment the victor for that game’s wins.

Path logsDirectory = p.resolve("logs");
                    try {
                        Files.list(logsDirectory).forEach(matchDirectory -> {
                            try {
                                Path lastRoundDirectory = Files.list(matchDirectory).max(Comparator.comparingInt(roundDirectory -> {
                                    Matcher matcher = roundPattern.matcher(roundDirectory.toString());
                                    if (matcher.find()) {
                                        return Integer.parseInt(matcher.group(1));
                                    }
                                    return -1;
                                })).orElseThrow(UnsupportedOperationException::new);
                                Path endGameStateFile = lastRoundDirectory.resolve("endGameState.txt");
                                List<String> endGameStateLines = Files.readAllLines(endGameStateFile);
                                endGameStateLines.stream().filter(l -> l.startsWith("The winner is:")).forEach(l -> {
                                    Matcher matcher = winnerPattern.matcher(l);
                                    if (matcher.find()) {
                                        switch (matcher.group(1)) {
                                            case "A":
                                                competitorMap.computeIfPresent(bots.get(0), (k, v) -> v + 1);
                                                break;
                                            case "B":
                                                competitorMap.computeIfPresent(bots.get(1), (k, v) -> v + 1);
                                                break;
                                            default:
                                                System.out.println(matcher.group(1));
                                        }
                                    }
                                });
                            } catch (IOException e) {
                                Logger.error(e);
                            }
                        });
                    } catch (IOException e) {
                        Logger.error(e);
                    }
2 Likes

Thanks, I take it this is java?

Correct, this is java. :+1: