java でひとりで遊べるしりとりを作りたいと思っているのですが
コンピューターが自動的に返事してくれるようなものを作りたいと考えているのですが
なにか参考になるようなサイトがあれば教えていただきたいのですが
ありますか?
答えのソースがあるならばそれをアレンジしたりとかもしてみたいです
よろしくお願いします
気になる質問をクリップする
クリップした質問は、後からいつでもMYページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。

回答1件
0
ベストアンサー
ヘビーに作るのでなければ,しりとりAPIのようなものを利用することになるでしょう.
http://workpiles.com/2015/01/android-docomo_api-chatbot/
しりとり自体は下のような形で,作れるとは思いますが,辞書をどこからか用意する必要があるでしょう.
Java
1public class Shiritori { 2 3 private static final BufferedReader READER = new BufferedReader( 4 new InputStreamReader(System.in)); 5 6 private static final List<String> DICTIONARY = Collections 7 .unmodifiableList(Arrays.asList("りんご", "ごりら", "らっぱ","ぱんつ","つくし", "しりとり","しめじ")); 8 9 private static final List<String> USED = new ArrayList<>(); 10 11 private static final Random RANDOM; 12 static { 13 try { 14 RANDOM = SecureRandom.getInstanceStrong(); 15 } catch (NoSuchAlgorithmException e) { 16 throw new RuntimeException(e); 17 } 18 } 19 20 public static void main(String[] args) throws IOException { 21 String yours = DICTIONARY.get(RANDOM.nextInt(DICTIONARY.size())); 22 System.out.println(new StringBuilder().append("じゃあねー最初は[").append(yours) 23 .append(']').append("だよ")); 24 25 for (;;) { 26 final String mine = READER.readLine(); 27 28 if (mine.isEmpty()) { 29 continue; 30 } 31 32 if(mine.equals("!")){ 33 System.out.println("へへん.勝ったー!"); 34 return; 35 } 36 37 if (yours.charAt(yours.length() - 1) != mine.charAt(0)) { 38 System.out.println(new StringBuilder().append("その単語[") 39 .append(yours.charAt(yours.length() - 1)) 40 .append("]で始まってないじゃん!")); 41 continue; 42 } 43 44 if (!DICTIONARY.contains(mine)) { 45 System.out.println("その単語知らない!知ってそうな単語を入力して!"); 46 continue; 47 } 48 49 if(USED.contains(mine)){ 50 System.out.println("その単語使ったよ!忘れたとはいわせないよ!"); 51 continue; 52 } 53 54 USED.add(mine); 55 56 List<String> result = search(mine.charAt(mine.length() - 1)); 57 58 if (result.isEmpty()) { 59 System.out.println("もうわかんない.負けたー"); 60 return; 61 } 62 63 yours = result.get(RANDOM.nextInt(result.size())); 64 65 if(USED.contains(yours)){ 66 System.out.println(new StringBuilder().append('[').append(yours).append(']') 67 .append("は言ったっけー.わかんない.まけたー")); 68 return; 69 } 70 71 System.out.println(new StringBuilder().append("じゃあ[") 72 .append(yours).append(']').append('!')); 73 74 } 75 76 } 77 78 public static final List<String> search(char firstChar) { 79 List<String> result = new ArrayList<>(); 80 for (String word : DICTIONARY) { 81 if (word.charAt(0) == firstChar) { 82 result.add(word); 83 } 84 } 85 return result; 86 } 87}
投稿2015/10/13 18:58

退会済みユーザー
総合スコア0
あなたの回答
tips
太字
斜体
打ち消し線
見出し
引用テキストの挿入
コードの挿入
リンクの挿入
リストの挿入
番号リストの挿入
表の挿入
水平線の挿入
プレビュー
質問の解決につながる回答をしましょう。 サンプルコードなど、より具体的な説明があると質問者の理解の助けになります。 また、読む側のことを考えた、分かりやすい文章を心がけましょう。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/10/14 01:13
退会済みユーザー
2015/10/14 05:36