このツイートを見て。
Rxjavaでズンドコしてみました。ご査収ください。
public class Zundoko {
private static final String ZUN = "ズン";
private static final String DOKO = "ドコ";
HashMap<String, Integer> map = new HashMap();
Integer[] zundoko = {0, 0, 0, 0, 1};
Random rand = new Random();
boolean isKiyoshi = false;
public void run(){
map.put(ZUN, 0);
map.put(DOKO, 1);
LinkedList<String> list = new LinkedList<>();
while (!isKiyoshi) {
list.add(rand.nextInt() % 2 == 0 ? ZUN : DOKO);
if (list.size() > zundoko.length) {
list.removeFirst();
}
System.out.println("¥¥ " + list.getLast());
doLambdaKiyoshi(list);
}
System.out.println("¥¥キ・ヨ・シ!");
}
public void doLambdaKiyoshi(List<String> list) {
Observable.from(list)
.map(s -> map.get(s))
.toList().map(zunInts ->
{
if (zunInts.size() < zundoko.length) return false;
return Arrays.equals(zunInts.toArray(new Integer[zundoko.length]), zundoko);
}
).subscribe(matched -> isKiyoshi = matched);
}
}
github.com