Last active
March 30, 2016 08:41
-
-
Save murakamik31/32f20ba13ab7909c9f6926348282d96a 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
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