Advertisement
apcnc

SpecialByApcnc

Sep 4th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. package ExampleStrategies;
  2.  
  3. import java.util.Random;
  4.  
  5. import PrisonersDilemma.Choice;
  6. import PrisonersDilemma.PrisonersStrategy;
  7.  
  8. public class SpecialByApcnc implements PrisonersStrategy{
  9.  
  10. @Override
  11. public Choice turn(Choice[] myChoices, Choice[] otherChoices, Random rand) {
  12.  
  13. int u = 0;
  14. for(int i = 0;i<otherChoices.length;i++){
  15. if(otherChoices[i]==Choice.betray)
  16. u++;
  17. }
  18. if(u>0){
  19. if(otherChoices.length/u>2){
  20. System.out.println("cooperate");
  21. return Choice.cooperate;
  22. }
  23. else{
  24. System.out.println("betray");
  25. return Choice.betray;
  26. }
  27. }
  28. else{
  29. System.out.println("cooperate");
  30. return Choice.cooperate;
  31. }
  32.  
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement