Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. package uk.ac.aber.dcs.joh50.cs21120.assignment1;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. public class BubbleElimination implements IManager{
  6.  
  7. private String p1,p2;
  8. private String[] toPlay;
  9. private Heap h;
  10. private Match m;
  11. private int teams;
  12. private boolean winstreak;
  13.  
  14. @Override
  15. public void setPlayers(ArrayList<String> players) {
  16. h = new Heap(players.size());
  17. toPlay = new String[players.size()];
  18. for (String s: players) {
  19. toPlay[teams]=s;
  20. teams++;
  21. }
  22. }
  23.  
  24. @Override
  25. public boolean hasNextMatch() {
  26. if (h.getLength()==teams) return false;
  27. else return true;
  28. }
  29.  
  30. @Override
  31. public Match nextMatch() throws NoNextMatchException {
  32. if (h.getLength()==0) {
  33. h.add(toPlay[h.getLength()]);
  34. p2=h.getPlayer(h.getLength()-1);
  35. h.add(toPlay[h.getLength()]);
  36. p1=h.getPlayer(h.getLength()-1);
  37. }
  38. else if (winstreak!=true) {
  39. h.add(toPlay[h.getLength()]);
  40. p1=h.getPlayer(h.getLength()-1);
  41. p2=h.getParent(h.getPosition(p1));
  42. }
  43. else p2=h.getParent(h.getPosition(p1));
  44. return m = new Match (p1,p2);
  45. }
  46.  
  47. @Override
  48. public void setMatchWinner(boolean player1) {
  49. if (player1==true) {
  50. winstreak=true;
  51. h.bubbleUp(h.getPosition(p1));
  52. if (h.getPosition(p1)==0) {
  53. winstreak=false;
  54. }
  55. }
  56. else {
  57. winstreak=false;
  58. }
  59.  
  60. }
  61.  
  62. @Override
  63. public String getPosition(int n) {
  64. return h.getPlayer(n);
  65. }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement