Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package uk.ac.aber.dcs.joh50.cs21120.assignment1;
- import java.util.ArrayList;
- public class BubbleElimination implements IManager{
- private String p1,p2;
- private String[] toPlay;
- private Heap h;
- private Match m;
- private int teams;
- private boolean winstreak;
- @Override
- public void setPlayers(ArrayList<String> players) {
- h = new Heap(players.size());
- toPlay = new String[players.size()];
- for (String s: players) {
- toPlay[teams]=s;
- teams++;
- }
- }
- @Override
- public boolean hasNextMatch() {
- if (h.getLength()==teams) return false;
- else return true;
- }
- @Override
- public Match nextMatch() throws NoNextMatchException {
- if (h.getLength()==0) {
- h.add(toPlay[h.getLength()]);
- p2=h.getPlayer(h.getLength()-1);
- h.add(toPlay[h.getLength()]);
- p1=h.getPlayer(h.getLength()-1);
- }
- else if (winstreak!=true) {
- h.add(toPlay[h.getLength()]);
- p1=h.getPlayer(h.getLength()-1);
- p2=h.getParent(h.getPosition(p1));
- }
- else p2=h.getParent(h.getPosition(p1));
- return m = new Match (p1,p2);
- }
- @Override
- public void setMatchWinner(boolean player1) {
- if (player1==true) {
- winstreak=true;
- h.bubbleUp(h.getPosition(p1));
- if (h.getPosition(p1)==0) {
- winstreak=false;
- }
- }
- else {
- winstreak=false;
- }
- }
- @Override
- public String getPosition(int n) {
- return h.getPlayer(n);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement