Created
February 12, 2014 16:09
-
-
Save mike-neck/8958560 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IntRange.metaClass.define { | |
random = { | |
return new Random().nextInt(delegate.size()) + delegate.min() | |
} | |
} | |
class Dices { | |
protected List dices = [(1..6), (1..6), (1..6)] | |
public def play = { | |
return dices.collect { | |
return it.random() | |
} | |
} | |
} | |
class ShigoroSai extends Dices { | |
protected List dices = [(4..6), (4..6), (4..6)] | |
} | |
enum Result { | |
Zorome, Shigoro, Six, Five, Four, Three, Two, One, None, Hifumi | |
public static Result whatDeme(int deme) { | |
if (deme == 1) return One | |
if (deme == 2) return Two | |
if (deme == 3) return Three | |
if (deme == 4) return Four | |
if (deme == 5) return Five | |
if (deme == 6) return Six | |
return None | |
} | |
} | |
class Chinchirorin { | |
public static Result getResult(final List<Integer> dices) { | |
if (dices.size() != 3) throw new IllegalArgumentException() | |
def res = dices.sort() | |
if (dices.sort() == [1,2,3]) return Result.Hifumi | |
if (dices.sort() == [4,5,6]) return Result.Shigoro | |
def one = res[0] | |
def two = res[1] | |
def three = res[2] | |
if (one == two && two == three) return Result.Zorome | |
if (one != two && two != three) return Result.None | |
def deme = one == two? three : one | |
return Result.whatDeme(deme) | |
} | |
} | |
assert Chinchirorin.getResult([1,1,1]) == Result.Zorome | |
assert Chinchirorin.getResult([2,2,2]) == Result.Zorome | |
assert Chinchirorin.getResult([2,1,3]) == Result.Hifumi | |
assert Chinchirorin.getResult([6,4,5]) == Result.Shigoro | |
assert Chinchirorin.getResult([2,5,4]) == Result.None | |
assert Chinchirorin.getResult([3,3,2]) == Result.Two | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment