Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.util.ArrayList;
- import java.util.Arrays;
- /**
- * Assignment 6 -- Prisoner's Dilemma -- 2ip90
- * part Patch
- *
- * @author Stefan Adrian Robu, 1449044
- * @author Silvia Garcia Cabaces 1446304
- * assignment group FILL IN
- *
- * assignment copyright Kees Huizing
- */
- class Patch {
- private ArrayList<Patch> neighboursList;
- boolean strategy;
- private double score;
- // returns true if and only if patch is cooperating
- boolean isCooperating() {
- return strategy;
- }
- // set strategy to C if isC is true and to D if false
- void setCooperating(boolean isC) {
- strategy = isC;
- }
- // change strategy from C to D and vice versa
- public void toggleStrategy() {
- strategy=!strategy;
- }
- public ArrayList<Patch> getNeighbours(){
- return neighboursList;
- }
- public int cooperators() {
- int cooperators = 0;
- for (Patch i : this.getNeighbours()) {
- if (i.isCooperating()) {
- cooperators++;
- }
- }
- return cooperators;
- }
- public void setNeighbour(ArrayList<Patch> neighboursList) {
- this.neighboursList = neighboursList;
- }
- // return score of this patch in current round
- public double getScore(){return this.score;}
- public double setScore(double alpha)
- {
- return (isCooperating() ? 1 : alpha) * cooperators();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement