OnJava8-Examples/enums/RoShamBo6.java

22 lines
596 B
Java
Raw Normal View History

2015-05-31 10:58:40 -07:00
//: 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);
}
} ///:~