KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > innig > macker > example > modularity > game > impl > PrisonersDilemmaMove


1 package net.innig.macker.example.modularity.game.impl;
2
3 import net.innig.macker.example.modularity.game.*;
4 import net.innig.util.EnumeratedType;
5 import java.util.*;
6
7 public final class PrisonersDilemmaMove
8     extends EnumeratedType
9     implements Move
10     {
11     static final Move
12         COOPERATE = new PrisonersDilemmaMove("cooperate"),
13         DEFECT = new PrisonersDilemmaMove("defect");
14     
15     static final Set ALL = Collections.unmodifiableSet(new HashSet(Arrays.asList(
16         new Move[] { COOPERATE, DEFECT } )));
17     
18     private PrisonersDilemmaMove(String JavaDoc name)
19         { super(name); }
20
21     public int getScoreFor(Move other)
22         {
23         if(this == COOPERATE && other == COOPERATE)
24             return 5;
25         if(this == DEFECT && other == COOPERATE)
26             return 10;
27         if(this == COOPERATE && other == DEFECT)
28             return 0;
29         if(this == DEFECT && other == DEFECT)
30             return 2;
31         throw new Error JavaDoc("unknown move");
32         }
33
34     private int num;
35     }
36
Popular Tags