Skip to content

Commit 75a124b

Browse files
committed
shiritori: add code comment in japanese
Change-Id: I6ec5e0aadbf2dfb65820f09eb18979b85fb2319f
1 parent a2cc97e commit 75a124b

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

functions/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ const dict = k => {
3535
};
3636

3737
const app = actionssdk({
38+
// リクエストとレスポンスをロギングする。
3839
debug: true,
40+
// Actionのデフォルトデータを初期化する。
3941
init: () => ({
4042
data: {
4143
used: []

functions/shiritori/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const wanakana = require('wanakana')
2020
const smallKanas = 'ぁぃぅぇぉゃゅょ'
2121
let kuroshiroLoaded = false
2222

23+
// 辞書のローディング。
2324
exports.loaded = new Promise((resolve, reject) => {
2425
kuroshiro.init(function (err) {
2526
if (err) {
@@ -31,7 +32,7 @@ exports.loaded = new Promise((resolve, reject) => {
3132
})
3233
})
3334

34-
// Check the first word against remaining of the shiritori chain.
35+
// しりとりのルールのチェック。
3536
exports.check = (word, chain) => {
3637
if ((chain === undefined) || (chain.length === 0)) {
3738
return true
@@ -42,13 +43,16 @@ exports.check = (word, chain) => {
4243
chain = chain.map((e) => kuroshiro.toHiragana(e))
4344
}
4445

46+
// 漢字からひらがなにする。
4547
const wordHira = wanakana.toHiragana(word)
4648
const chainHira = chain.map(wanakana.toHiragana)
4749

50+
// 使った名詞をチェックする。
4851
if (chainHira.indexOf(wordHira, 0) !== -1) {
4952
return false
5053
}
5154

55+
// しりとりの最初の文字をチェックする。
5256
const validKanas = exports.kanas(chain[0])
5357
for (const k of validKanas) {
5458
const begin = wordHira.slice(0, k.length)
@@ -59,7 +63,7 @@ exports.check = (word, chain) => {
5963
return false
6064
}
6165

62-
// Returns a Set of valid kana sequences for the next word.
66+
// 名詞からしりとりのひらがなを選ぶ。
6367
exports.kanas = (word) => new Set((() => {
6468
if (kuroshiroLoaded) {
6569
word = kuroshiro.toHiragana(word)
@@ -93,14 +97,13 @@ exports.kanas = (word) => new Set((() => {
9397
]
9498
})())
9599

96-
// Evaluate one round of game with for given word and previous inputs.
100+
// しりとりのゲームループ。
97101
exports.interact = (dict, word, previousInputs, callbacks) => {
98102
const next = exports.kanas(word)
99103
if ((next.size === 0) || !exports.check(word, previousInputs)) {
100104
return callbacks.lose()
101105
}
102106
const key = next.values().next().value
103-
// TODO(proppy): add multiple key lookup
104107
dict(key).then((words) => {
105108
const unused = []
106109
if (words) {

0 commit comments

Comments
 (0)