2015-09-07 11:44:36 -06:00
|
|
|
|
// enums/RoShamBo6.java
|
2015-11-14 16:18:05 -08:00
|
|
|
|
// <20>2016 MindView LLC: see Copyright.txt
|
2015-06-15 17:47:35 -07:00
|
|
|
|
// 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);
|
|
|
|
|
}
|
2015-09-07 11:44:36 -06:00
|
|
|
|
}
|
|
|
|
|
/* Output:
|
2015-06-15 17:47:35 -07:00
|
|
|
|
ROCK vs. ROCK: DRAW
|
|
|
|
|
SCISSORS vs. ROCK: LOSE
|
|
|
|
|
SCISSORS vs. ROCK: LOSE
|
|
|
|
|
SCISSORS vs. ROCK: LOSE
|
|
|
|
|
PAPER vs. SCISSORS: LOSE
|
|
|
|
|
PAPER vs. PAPER: DRAW
|
|
|
|
|
PAPER vs. SCISSORS: LOSE
|
|
|
|
|
ROCK vs. SCISSORS: WIN
|
|
|
|
|
SCISSORS vs. SCISSORS: DRAW
|
|
|
|
|
ROCK vs. SCISSORS: WIN
|
|
|
|
|
SCISSORS vs. PAPER: WIN
|
|
|
|
|
SCISSORS vs. PAPER: WIN
|
|
|
|
|
ROCK vs. PAPER: LOSE
|
|
|
|
|
ROCK vs. SCISSORS: WIN
|
|
|
|
|
SCISSORS vs. ROCK: LOSE
|
|
|
|
|
PAPER vs. SCISSORS: LOSE
|
|
|
|
|
SCISSORS vs. PAPER: WIN
|
|
|
|
|
SCISSORS vs. PAPER: WIN
|
|
|
|
|
SCISSORS vs. PAPER: WIN
|
|
|
|
|
SCISSORS vs. PAPER: WIN
|
2015-09-07 11:44:36 -06:00
|
|
|
|
*/
|