SHARE
TWEET

Untitled

a guest Oct 18th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.awt.*;
  2. import java.util.ArrayList;
  3. import java.util.Arrays;
  4.  
  5. /**
  6.  * Assignment 6 -- Prisoner's Dilemma -- 2ip90
  7.  * part Patch
  8.  *
  9.  * @author Stefan Adrian Robu, 1449044
  10.  * @author Silvia Garcia Cabaces 1446304
  11.  * assignment group FILL IN
  12.  *
  13.  * assignment copyright Kees Huizing
  14.  */
  15.  
  16. class Patch  {
  17.     private ArrayList<Patch> neighboursList;
  18. boolean strategy;
  19.     private double score;
  20.     // returns true if and only if patch is cooperating
  21.     boolean isCooperating() {
  22.         return strategy;
  23.     }
  24.  
  25.  
  26.     // set strategy to C if isC is true and to D if false
  27.     void setCooperating(boolean isC) {
  28.         strategy = isC;
  29.     }
  30.  
  31.     // change strategy from C to D and vice versa
  32.     public void toggleStrategy() {
  33.         strategy=!strategy;
  34.  
  35.     }
  36.  
  37.     public ArrayList<Patch> getNeighbours(){
  38.         return neighboursList;
  39.     }
  40.     public int cooperators() {
  41.         int cooperators = 0;
  42.         for (Patch i : this.getNeighbours()) {
  43.             if (i.isCooperating()) {
  44.                 cooperators++;
  45.             }
  46.         }
  47.         return cooperators;
  48.     }
  49.  
  50.     public void setNeighbour(ArrayList<Patch> neighboursList) {
  51.         this.neighboursList = neighboursList;
  52.     }
  53.     // return score of this patch in current round
  54.         public double getScore(){return this.score;}
  55.     public double setScore(double alpha)
  56.     {
  57.         return (isCooperating() ? 1 : alpha) * cooperators();
  58.     }
  59.  
  60.  
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top