Skip to content

Instantly share code, notes, and snippets.

@murakamik31
Last active March 30, 2016 08:41
Show Gist options
  • Save murakamik31/32f20ba13ab7909c9f6926348282d96a to your computer and use it in GitHub Desktop.
Save murakamik31/32f20ba13ab7909c9f6926348282d96a to your computer and use it in GitHub Desktop.
package zundoko;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
public class Zundoko {
private String z = "ズン";
private String d = "ドコ";
private List<String> list = Arrays.asList(z, d);
private List<String> expectedZundoko = Arrays.asList(z, z, z, z, d);
private Random rnd = new Random();
public void run(){
List<String> currentZundoko = new ArrayList<String>();
while(true) {
String word = list.get(rnd.nextInt(2));
System.out.println(word);
currentZundoko.add(word);
if(!checkCorrectSequence(currentZundoko)) {
currentZundoko.clear();
if(word.equals(z)) currentZundoko.add(word);
continue;
}
if(currentZundoko.size() == expectedZundoko.size()) {
break;
}
}
System.out.println("きよし!");
}
private Boolean checkCorrectSequence(List<String> currentZundoko){
for(int i = 0; i < currentZundoko.size(); i++){
if(!currentZundoko.get(i).equals(expectedZundoko.get(i))) {
return false;
}
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment