22 lines
596 B
Java
22 lines
596 B
Java
|
//: enums/RoShamBo6.java
|
|||
|
// <20>2015 MindView LLC: see Copyright.txt
|
|||
|
// Enums using "tables" instead of multiple dispatch.
|
|||
|
package enums;
|
|||
|
import static enums.Outcome.*;
|
|||
|
|
|||
|
enum RoShamBo6 implements Competitor<RoShamBo6> {
|
|||
|
PAPER, SCISSORS, ROCK;
|
|||
|
private static Outcome[][] table = {
|
|||
|
{ DRAW, LOSE, WIN }, // PAPER
|
|||
|
{ WIN, DRAW, LOSE }, // SCISSORS
|
|||
|
{ LOSE, WIN, DRAW }, // ROCK
|
|||
|
};
|
|||
|
@Override
|
|||
|
public Outcome compete(RoShamBo6 other) {
|
|||
|
return table[this.ordinal()][other.ordinal()];
|
|||
|
}
|
|||
|
public static void main(String[] args) {
|
|||
|
RoShamBo.play(RoShamBo6.class, 20);
|
|||
|
}
|
|||
|
} ///:~
|