Skip to content

Commit

Permalink
Kan 43 drabinka na 16 os b (#42)
Browse files Browse the repository at this point in the history
* init TreeBracketFor 16

* system for 16 player or less implemented
  • Loading branch information
c-i-a-s-t-e-k authored Jun 11, 2024
1 parent 319a825 commit 6633515
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public ReportController(ReportService reportService) {
this.reportService = reportService;
}

@GetMapping("/report")
public void getReport(@RequestParam String saveTo) throws DocumentException, FileNotFoundException {
reportService.generate(saveTo);
}
// @GetMapping("/report")
// public void getReport(@RequestParam String saveTo) throws DocumentException, FileNotFoundException {
// reportService.generate(saveTo);
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ public static MatchingSystem_II pickSystem(int numberOfPlayers) {
throw new IllegalArgumentException("Number of players must be greater than 0");
} else if (numberOfPlayers <= 5) {
throw new IllegalArgumentException("System Missing");
} else if (numberOfPlayers <= 8) {
return new TreeBracket();
} else if (numberOfPlayers <= 16) {
throw new IllegalArgumentException("System Missing");
return new TreeBracket();
}
throw new IllegalArgumentException("Too many players");
throw new IllegalArgumentException(numberOfPlayers + " is too many players");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@
import com.rikishi.rikishi.model.Fight;
import com.rikishi.rikishi.model.User;
import com.rikishi.rikishi.model.WeightClass;
import com.rikishi.rikishi.model.entity.Duel;

import java.util.*;

public class TreeBracket implements MatchingSystem, MatchingSystem_II {
private final List<User> arrayTree = new ArrayList<>(15);
private int actualMatch;
private OctetRoundName currentRound;
private TreeRoundName currentRound;
private WeightClass weightCategory;

@Override
public void nextMatch() {
if (arrayTree.get(actualMatch) == null) {
throw new RuntimeException("No winner of the round");
}
if (currentRound == OctetRoundName.FINAL) throw new RuntimeException("There is nothing afet finals");
if (currentRound == TreeRoundName.FINAL) throw new RuntimeException("There is nothing afet finals");
if (actualMatch + 1 < currentRound.getIndexBound()) actualMatch++;
else {
currentRound = currentRound.goUp();
Expand Down Expand Up @@ -59,14 +58,14 @@ private Set<User> getPlayersByFromDuelID(int duelId) {
public void loadPlayers(Collection<User> players) {
List<User> playersArray = new ArrayList<>(players);
Collections.shuffle(playersArray);
currentRound = OctetRoundName.FIRST_FIGHT;
actualMatch = OctetRoundName.FIRST_FIGHT.getIndexStart();
if (players.size() == 8) {
currentRound = TreeRoundName.FIRST_FIGHT;
actualMatch = TreeRoundName.FIRST_FIGHT.getIndexStart();
if (players.size() == 8 || players.size() == 16) {
for (int i = 0; i < players.size() * 2 - 1; i++) {
arrayTree.add(null);
}
Iterator<User> it = playersArray.iterator();
for (int i = 7; i < 15 && it.hasNext(); i++) {
for (int i = 7; i < 7 + players.size() && it.hasNext(); i++) {
arrayTree.set(i, it.next()); // Assign the next player
}
} else if (5 < players.size() && players.size() < 8) {
Expand All @@ -76,8 +75,16 @@ public void loadPlayers(Collection<User> players) {
for (int i = 0, k = 0; k < players.size(); i = ((i + 4) % 7), k++) {
arrayTree.set(7 + i, playersArray.get(k));
}
} else if (8 < players.size() && players.size() < 16) {
for (int i = 0; i < 31; i++) {
arrayTree.add(null);
}
for (int i = 0, k = 0; k < players.size(); i = ((i + 4) % 15), k++) {
// System.out.println("k="+k+"size="+players.size()+" new index=" + (15 + i));
arrayTree.set(15 + i, playersArray.get(k));
}
} else {
throw new RuntimeException("implement only for 6 to 8 players");
throw new RuntimeException("implement only for 6 to 16 players");
}

Map<WeightClass, Integer> weightCategoryFrequency = new HashMap<>();
Expand Down Expand Up @@ -179,9 +186,14 @@ private List<Fight> getDuelsFromRange(int a, int b) {
}

public List<Fight> getAllFights() {
return getDuelsFromRange(0, 7);
return switch (arrayTree.size()) {
case 15 -> getDuelsFromRange(0, 7);
case 31 -> getDuelsFromRange(0, 15);
default -> throw new IllegalStateException("Unexpected value: " + arrayTree.size());
};
}


public List<Fight> getCurrentFights() {
return getDuelsFromRange(currentRound.getIndexStart(), currentRound.getIndexBound());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.rikishi.rikishi.system.matching;

public enum OctetRoundName {
FINAL, SEMI_FINAL, FIRST_FIGHT;
public enum TreeRoundName {
FINAL, SEMI_FINAL, QUARTER_FINAL, FIRST_FIGHT;

public int getIndexBound() {
return switch (this) {
case FIRST_FIGHT -> 7;
case FIRST_FIGHT -> 15;
case QUARTER_FINAL -> 7;
case SEMI_FINAL -> 3;
case FINAL -> 1;
default -> throw new IllegalStateException("Unexpected value: " + this);
Expand All @@ -14,18 +15,20 @@ public int getIndexBound() {

public int getIndexStart() {
return switch (this) {
case FIRST_FIGHT -> 3;
case FIRST_FIGHT -> 7;
case QUARTER_FINAL -> 3;
case SEMI_FINAL -> 1;
case FINAL -> 0;
default -> throw new IllegalStateException("Unexpected value: " + this);
};
}

public OctetRoundName goUp() {
public TreeRoundName goUp() {
return switch (this) {
case FIRST_FIGHT -> QUARTER_FINAL;
case SEMI_FINAL -> FINAL;
case FINAL -> throw new IllegalArgumentException("Finals are at the top");
case FIRST_FIGHT -> SEMI_FINAL;
case QUARTER_FINAL -> SEMI_FINAL;
default -> throw new IllegalStateException("Unexpected value: " + this);
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.rikishi.rikishi.system;

import org.junit.jupiter.api.Test;


public class TreeBracketTest {
@Test
void genrateDuelsFor8Test() {

}
}

0 comments on commit 6633515

Please sign in to comment.