Last active
March 24, 2016 05:18
-
-
Save kntmr/14f1048733782111bb45 to your computer and use it in GitHub Desktop.
ZunDoko.java
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
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Random; | |
public class ZunDoko { | |
enum Type { | |
ZUN("ズン"), DOKO("ドコ"); | |
final String value; | |
Type(String v) { | |
this.value = v; | |
} | |
} | |
void run() { | |
List<Type> buf = new ArrayList<>(); | |
while (true) { | |
buf.add(getZunDoko()); | |
out(buf); | |
if (checkZunDoko(buf)) | |
break; | |
if (buf.size() > 5) | |
buf.clear(); | |
} | |
System.out.println("キ・ヨ・シ!"); | |
} | |
Type getZunDoko() { | |
Random r = new Random(); | |
return r.nextBoolean() ? Type.ZUN : Type.DOKO; | |
} | |
boolean checkZunDoko(List<Type> list) { | |
if (list.size() < 5) | |
return false; | |
return list.get(0) == Type.ZUN | |
&& list.get(1) == Type.ZUN | |
&& list.get(2) == Type.ZUN | |
&& list.get(3) == Type.ZUN | |
&& list.get(4) == Type.DOKO; | |
} | |
static void out(List<Type> list) { | |
if (list.size() < 5) | |
return; | |
System.out.println(String.format("%s %s %s %s %s", | |
list.get(0).value, list.get(1).value, list.get(2).value, list.get(3).value, list.get(4).value)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment