Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. public class StrategyAdviser {
  2.  
  3. private final YahtzeeGame yahtzeeGame;
  4.  
  5. public StrategyAdviser(YahtzeeGame yahtzeeGame) {
  6. this.yahtzeeGame = yahtzeeGame;
  7. }
  8.  
  9. public Strategy getAdvise() {
  10. Roll roll = yahtzeeGame.getRoll();
  11. Board board = yahtzeeGame.getBoard();
  12. YahtzeePlayer currentPlayer = yahtzeeGame.getCurrentPlayer();
  13.  
  14. StrategyFactory factory = new StrategyFactory();
  15. if (!roll.hasRoll()) {
  16. return factory.createStartRollStrategy();
  17. }
  18.  
  19. if (!yahtzeeGame.canRoll()) {
  20. return factory.createWriteToBoardStrategy();
  21. }
  22.  
  23. RollAnalyze rollAnalyze = new RollAnalyze(roll);
  24. BoardAnalyze boardAnalyze = new BoardAnalyze(board, currentPlayer);
  25. int amountOfIdenticals = rollAnalyze.getAmountOfIdenticals();
  26. int highestEyeOfIdenticals = rollAnalyze.getHighestEyeOfIdenticals();
  27. boolean has6 = rollAnalyze.hasSix();
  28. boolean has5 = rollAnalyze.hasFive();
  29. boolean is6Empty = boardAnalyze.isTopRowEmpty(6);
  30. boolean is5Empty = boardAnalyze.isTopRowEmpty(5);
  31. boolean has3InRow = rollAnalyze.hasThreeInRow();
  32. boolean has4InRow = rollAnalyze.hasFourInRow();
  33. boolean hasBottomVariables = boardAnalyze.hasBottomRowsWithVariableCounter();
  34.  
  35. if (amountOfIdenticals == 5) {
  36. return factory.createWriteToBoardStrategy();
  37. }
  38.  
  39. if ((amountOfIdenticals >= 3 && boardAnalyze.isTopRowEmpty(highestEyeOfIdenticals))) {
  40. return factory.createStrategyRollForThreeOrMoreIdentical(highestEyeOfIdenticals, rollAnalyze);
  41. }
  42. if (amountOfIdenticals >= 2 && highestEyeOfIdenticals >= 4) {
  43. return factory.createStrategyRollForThreeOrMoreIdentical(highestEyeOfIdenticals, rollAnalyze);
  44. }
  45.  
  46. if (has4InRow) {
  47. return factory.createStrategyRollForMajorStreet();
  48. }
  49.  
  50. if (has6 && is6Empty) {
  51. return factory.createStrategyRollForSix(rollAnalyze);
  52. }
  53.  
  54. if (((!has6) && (has5 && is5Empty))) {
  55. return factory.createStrategyRollForSix(rollAnalyze);
  56. }
  57.  
  58. if (hasBottomVariables) {
  59. if (has6) {
  60. return factory.createStrategyRollForSix(rollAnalyze);
  61. }
  62. if (has5) {
  63. return factory.createStrategyRollForFive(rollAnalyze);
  64. }
  65. }
  66.  
  67. if (has3InRow) {
  68. if (has5) {
  69. return factory.createStrategyRollForMinorStreet(3, 4, 5);
  70. } else {
  71. return factory.createStrategyRollForMinorStreet(2, 3, 4);
  72. }
  73. }
  74.  
  75. return factory.createStrategyReRollAll();
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement