Skip to content

Instantly share code, notes, and snippets.

@kntmr
Last active March 24, 2016 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kntmr/14f1048733782111bb45 to your computer and use it in GitHub Desktop.
Save kntmr/14f1048733782111bb45 to your computer and use it in GitHub Desktop.
ZunDoko.java
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