From 8efdf0af2085cadc9f7bc62487d41e9f3781d54f Mon Sep 17 00:00:00 2001 From: reismannnr2 Date: Fri, 20 Aug 2021 21:13:04 +0900 Subject: [PATCH 1/4] implementation --- lib/bcdice/game_system.rb | 1 + lib/bcdice/game_system/CastleInGray.rb | 129 +++++++++++++++++++++++++ test/data/CastleInGray.toml | 129 +++++++++++++++++++++++++ 3 files changed, 259 insertions(+) create mode 100644 lib/bcdice/game_system/CastleInGray.rb create mode 100644 test/data/CastleInGray.toml diff --git a/lib/bcdice/game_system.rb b/lib/bcdice/game_system.rb index 41de38484..7c822bd20 100644 --- a/lib/bcdice/game_system.rb +++ b/lib/bcdice/game_system.rb @@ -27,6 +27,7 @@ require "bcdice/game_system/BloodCrusade" require "bcdice/game_system/BloodMoon" require "bcdice/game_system/CardRanker" +require "bcdice/game_system/CastleInGray" require "bcdice/game_system/ChaosFlare" require "bcdice/game_system/Chill" require "bcdice/game_system/Chill3" diff --git a/lib/bcdice/game_system/CastleInGray.rb b/lib/bcdice/game_system/CastleInGray.rb new file mode 100644 index 000000000..468060295 --- /dev/null +++ b/lib/bcdice/game_system/CastleInGray.rb @@ -0,0 +1,129 @@ +module BCDice + module GameSystem + class CastleInGray < Base + # ゲームシステムの識別子 + ID = "CastleInGray".freeze + + # ゲームシステム名 + NAME = "灰色城綺譚".freeze + + # ゲームシステム名の読みがな + SORT_KEY = "はいいろしようきたん".freeze + + HELP_MESSAGE = <<~TEXT.freeze + ■ 色占い (BnWm) + n: 黒 + m: 白 + n, m は1~12の異なる整数 + + 例) B12W7 + 例) B5W12 + + ■ 悪意の渦による占い (MALn) + n: 悪意の渦 + n は1~12の整数 + + ■ その他 + ・感情表 ET + ・暗示表(黒) BIT + ・暗示表(白) WIT + TEXT + TABLES = { + "ET" => DiceTable::Table.new( + "感情表", + "1D12", + [ + "友情(白)/敵視(黒)", + "恋慕(白)/嫌悪(黒)", + "信頼(白)/不信(黒)", + "同情(白)/憐憫(黒)", + "憧憬(白)/劣等感(黒)", + "尊敬(白)/蔑視(黒)", + "忠誠(白)/執着(黒)", + "有用(白)/邪魔(黒)", + "許容(白)/罪悪感(黒)", + "羨望(白)/嫉妬(黒)", + "共感(白)/拒絶(黒)", + "愛情(白)/狂信(黒)" + ] + ), + "BIT" => DiceTable::Table.new( + "暗示表(黒)", + "1D12", + [ + "終わりなき夜に生まれつく者もあり", + "悪意もて真実を語らば", + "笑えども笑みはなし", + "影より抜け出ることあたわじ", + "心の赴くままに手をとれ", + "時ならぬ嵐の過ぎ去るを待つ", + "赦されぬと知るがゆえに", + "見張りは持ち場を離れる", + "誰もが盲いたる彷徨い人なり", + "落ちる日を眺めるがごとく", + "冷たく雨ぞ降りしきる", + "今日は笑む花も明日には枯れゆく" + ] + ), + "WIT" => DiceTable::Table.new( + "暗示表(白)", + "1D12", + [ + "無垢なる者のみが真実を得る", + "げに慈悲深きは沈黙なり", + "懐かしき日々は去りぬ", + "束の間に光さす", + "迷える者に手を差し伸べよ", + "嵐の前には静けさがある", + "どうか責めないで", + "灯した明かりを絶やさぬように", + "目を開けて見よ", + "淑やかに訪れる", + "今こそ泣け、さもなくば二度と泣くな", + "時が許す間に薔薇を摘め" + ] + ), + }.freeze + + register_prefix('B(1|2|3|4|5|6|7|8|9|10|11|12)W(1|2|3|4|5|6|7|8|9|10|11|12)', 'MAL(1|2|3|4|5|6|7|8|9|10|11|12)', TABLES.keys) + + def eval_game_system_specific_command(command) + return roll_color(command) || roll_mal(command) || roll_tables(command, TABLES) + end + + def roll_color(command) + m = /^B(1|2|3|4|5|6|7|8|9|10|11|12)W(1|2|3|4|5|6|7|8|9|10|11|12)$/.match(command) + return nil unless m + + black = m[1].to_i + white = m[2].to_i + + value = @randomizer.roll_once(12) + + if black == white + return color_text(black, white, value, '白と黒は重ねられません') + end + + if white > black + return color_text(black, white, value, value < black || value >= white ? '白' : '黒') + else + return color_text(black, white, value, value >= white && value < black ? '白' : '黒') + end + end + + def color_text(black, white, value, result) + return "色占い(黒#{black}白#{white}) > [#{value}] > #{result}" + end + + def roll_mal(command) + m = /^MAL(1|2|3|4|5|6|7|8|9|10|11|12)$/i.match(command) + return nil unless m + + mal = m[1].to_i + value = @randomizer.roll_once(12) + result = value <= mal ? '黒' : '白' + return "悪意の渦(#{mal}) > [#{value}] > #{result}" + end + end + end +end diff --git a/test/data/CastleInGray.toml b/test/data/CastleInGray.toml new file mode 100644 index 000000000..1d8868185 --- /dev/null +++ b/test/data/CastleInGray.toml @@ -0,0 +1,129 @@ +[[ test ]] +game_system = "CastleInGray" +input = "B10W10" +output = "色占い(黒10白10) > [10] > 白と黒は重ねられません" +rands = [ + { sides = 12, value = 10 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "B10W5" +output = "色占い(黒10白5) > [11] > 黒" +rands = [ + { sides = 12, value = 11 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "B10W5" +output = "色占い(黒10白5) > [7] > 白" +rands = [ + { sides = 12, value = 7 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "B10W5" +output = "色占い(黒10白5) > [5] > 白" +rands = [ + { sides = 12, value = 5 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "B10W5" +output = "色占い(黒10白5) > [10] > 黒" +rands = [ + { sides = 12, value = 10 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "B9W12" +output = "色占い(黒9白12) > [11] > 黒" +rands = [ + { sides = 12, value = 11 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "B9W12" +output = "色占い(黒9白12) > [4] > 白" +rands = [ + { sides = 12, value = 4 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "MAL1" +output = "悪意の渦(1) > [1] > 黒" +rands = [ + { sides = 12, value = 1 }, +] + + +[[ test ]] +game_system = "CastleInGray" +input = "MAL1" +output = "悪意の渦(1) > [2] > 白" +rands = [ + { sides = 12, value = 2 }, +] + + +[[ test ]] +game_system = "CastleInGray" +input = "MAL5" +output = "悪意の渦(5) > [11] > 白" +rands = [ + { sides = 12, value = 11 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "MAL5" +output = "悪意の渦(5) > [3] > 黒" +rands = [ + { sides = 12, value = 3 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "MAL5" +output = "悪意の渦(5) > [5] > 黒" +rands = [ + { sides = 12, value = 5 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "MAL5" +output = "悪意の渦(5) > [6] > 白" +rands = [ + { sides = 12, value = 6 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "MAL12" +output = "悪意の渦(12) > [12] > 黒" +rands = [ + { sides = 12, value = 12 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "MAL12" +output = "悪意の渦(12) > [3] > 黒" +rands = [ + { sides = 12, value = 3 }, +] + +[[ test ]] +game_system = "CastleInGray" +input = "MAL12" +output = "悪意の渦(12) > [3] > 黒" +rands = [ + { sides = 12, value = 3 }, +] From b8f1fb9f340f4d50ef7eec4a05d511c48ba169f9 Mon Sep 17 00:00:00 2001 From: reismannnr2 Date: Fri, 20 Aug 2021 22:33:23 +0900 Subject: [PATCH 2/4] add tests for tables --- lib/bcdice/game_system/CastleInGray.rb | 2 +- test/data/CastleInGray.toml | 324 +++++++++++++++++++++++++ 2 files changed, 325 insertions(+), 1 deletion(-) diff --git a/lib/bcdice/game_system/CastleInGray.rb b/lib/bcdice/game_system/CastleInGray.rb index 468060295..7396559a4 100644 --- a/lib/bcdice/game_system/CastleInGray.rb +++ b/lib/bcdice/game_system/CastleInGray.rb @@ -100,7 +100,7 @@ def roll_color(command) value = @randomizer.roll_once(12) - if black == white + if black == white return color_text(black, white, value, '白と黒は重ねられません') end diff --git a/test/data/CastleInGray.toml b/test/data/CastleInGray.toml index 1d8868185..7ccdc814a 100644 --- a/test/data/CastleInGray.toml +++ b/test/data/CastleInGray.toml @@ -127,3 +127,327 @@ output = "悪意の渦(12) > [3] > 黒" rands = [ { sides = 12, value = 3 }, ] + +[[test]] +game_system = "CastleInGray" +input = "ET" +output = "感情表(1) > 友情(白)/敵視(黒)" +rands = [ + { sides = 12, value = 1 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "ET" +output = "感情表(2) > 恋慕(白)/嫌悪(黒)" +rands = [ + { sides = 12, value = 2 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "ET" +output = "感情表(3) > 信頼(白)/不信(黒)" +rands = [ + { sides = 12, value = 3 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "ET" +output = "感情表(4) > 同情(白)/憐憫(黒)" +rands = [ + { sides = 12, value = 4 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "ET" +output = "感情表(5) > 憧憬(白)/劣等感(黒)" +rands = [ + { sides = 12, value = 5 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "ET" +output = "感情表(6) > 尊敬(白)/蔑視(黒)" +rands = [ + { sides = 12, value = 6 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "ET" +output = "感情表(7) > 忠誠(白)/執着(黒)" +rands = [ + { sides = 12, value = 7 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "ET" +output = "感情表(8) > 有用(白)/邪魔(黒)" +rands = [ + { sides = 12, value = 8 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "ET" +output = "感情表(9) > 許容(白)/罪悪感(黒)" +rands = [ + { sides = 12, value = 9 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "ET" +output = "感情表(10) > 羨望(白)/嫉妬(黒)" +rands = [ + { sides = 12, value = 10 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "ET" +output = "感情表(11) > 共感(白)/拒絶(黒)" +rands = [ + { sides = 12, value = 11 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "ET" +output = "感情表(12) > 愛情(白)/狂信(黒)" +rands = [ + { sides = 12, value = 12 }, +] + +[[test]] +game_system = "CastleInGray" +input = "BIT" +output = "暗示表(黒)(1) > 終わりなき夜に生まれつく者もあり" +rands = [ + { sides = 12, value = 1 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "BIT" +output = "暗示表(黒)(2) > 悪意もて真実を語らば" +rands = [ + { sides = 12, value = 2 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "BIT" +output = "暗示表(黒)(3) > 笑えども笑みはなし" +rands = [ + { sides = 12, value = 3 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "BIT" +output = "暗示表(黒)(4) > 影より抜け出ることあたわじ" +rands = [ + { sides = 12, value = 4 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "BIT" +output = "暗示表(黒)(5) > 心の赴くままに手をとれ" +rands = [ + { sides = 12, value = 5 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "BIT" +output = "暗示表(黒)(6) > 時ならぬ嵐の過ぎ去るを待つ" +rands = [ + { sides = 12, value = 6 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "BIT" +output = "暗示表(黒)(7) > 赦されぬと知るがゆえに" +rands = [ + { sides = 12, value = 7 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "BIT" +output = "暗示表(黒)(8) > 見張りは持ち場を離れる" +rands = [ + { sides = 12, value = 8 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "BIT" +output = "暗示表(黒)(9) > 誰もが盲いたる彷徨い人なり" +rands = [ + { sides = 12, value = 9 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "BIT" +output = "暗示表(黒)(10) > 落ちる日を眺めるがごとく" +rands = [ + { sides = 12, value = 10 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "BIT" +output = "暗示表(黒)(11) > 冷たく雨ぞ降りしきる" +rands = [ + { sides = 12, value = 11 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "BIT" +output = "暗示表(黒)(12) > 今日は笑む花も明日には枯れゆく" +rands = [ + { sides = 12, value = 12 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "WIT" +output = "暗示表(白)(1) > 無垢なる者のみが真実を得る" +rands = [ + { sides = 12, value = 1 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "WIT" +output = "暗示表(白)(2) > げに慈悲深きは沈黙なり" +rands = [ + { sides = 12, value = 2 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "WIT" +output = "暗示表(白)(3) > 懐かしき日々は去りぬ" +rands = [ + { sides = 12, value = 3 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "WIT" +output = "暗示表(白)(4) > 束の間に光さす" +rands = [ + { sides = 12, value = 4 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "WIT" +output = "暗示表(白)(5) > 迷える者に手を差し伸べよ" +rands = [ + { sides = 12, value = 5 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "WIT" +output = "暗示表(白)(6) > 嵐の前には静けさがある" +rands = [ + { sides = 12, value = 6 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "WIT" +output = "暗示表(白)(7) > どうか責めないで" +rands = [ + { sides = 12, value = 7 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "WIT" +output = "暗示表(白)(8) > 灯した明かりを絶やさぬように" +rands = [ + { sides = 12, value = 8 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "WIT" +output = "暗示表(白)(9) > 目を開けて見よ" +rands = [ + { sides = 12, value = 9 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "WIT" +output = "暗示表(白)(10) > 淑やかに訪れる" +rands = [ + { sides = 12, value = 10 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "WIT" +output = "暗示表(白)(11) > 今こそ泣け、さもなくば二度と泣くな" +rands = [ + { sides = 12, value = 11 }, +] + + +[[test]] +game_system = "CastleInGray" +input = "WIT" +output = "暗示表(白)(12) > 時が許す間に薔薇を摘め" +rands = [ + { sides = 12, value = 12 }, +] + + From b5ee9a6980d05461af87af4b90e17fde9884eec2 Mon Sep 17 00:00:00 2001 From: reismannnr2 Date: Fri, 20 Aug 2021 23:10:58 +0900 Subject: [PATCH 3/4] remove some tests --- test/data/CastleInGray.toml | 242 ------------------------------------ 1 file changed, 242 deletions(-) diff --git a/test/data/CastleInGray.toml b/test/data/CastleInGray.toml index 7ccdc814a..3dfe5f7d3 100644 --- a/test/data/CastleInGray.toml +++ b/test/data/CastleInGray.toml @@ -137,24 +137,6 @@ rands = [ ] -[[test]] -game_system = "CastleInGray" -input = "ET" -output = "感情表(2) > 恋慕(白)/嫌悪(黒)" -rands = [ - { sides = 12, value = 2 }, -] - - -[[test]] -game_system = "CastleInGray" -input = "ET" -output = "感情表(3) > 信頼(白)/不信(黒)" -rands = [ - { sides = 12, value = 3 }, -] - - [[test]] game_system = "CastleInGray" input = "ET" @@ -164,69 +146,6 @@ rands = [ ] -[[test]] -game_system = "CastleInGray" -input = "ET" -output = "感情表(5) > 憧憬(白)/劣等感(黒)" -rands = [ - { sides = 12, value = 5 }, -] - - -[[test]] -game_system = "CastleInGray" -input = "ET" -output = "感情表(6) > 尊敬(白)/蔑視(黒)" -rands = [ - { sides = 12, value = 6 }, -] - - -[[test]] -game_system = "CastleInGray" -input = "ET" -output = "感情表(7) > 忠誠(白)/執着(黒)" -rands = [ - { sides = 12, value = 7 }, -] - - -[[test]] -game_system = "CastleInGray" -input = "ET" -output = "感情表(8) > 有用(白)/邪魔(黒)" -rands = [ - { sides = 12, value = 8 }, -] - - -[[test]] -game_system = "CastleInGray" -input = "ET" -output = "感情表(9) > 許容(白)/罪悪感(黒)" -rands = [ - { sides = 12, value = 9 }, -] - - -[[test]] -game_system = "CastleInGray" -input = "ET" -output = "感情表(10) > 羨望(白)/嫉妬(黒)" -rands = [ - { sides = 12, value = 10 }, -] - - -[[test]] -game_system = "CastleInGray" -input = "ET" -output = "感情表(11) > 共感(白)/拒絶(黒)" -rands = [ - { sides = 12, value = 11 }, -] - - [[test]] game_system = "CastleInGray" input = "ET" @@ -244,78 +163,6 @@ rands = [ ] -[[test]] -game_system = "CastleInGray" -input = "BIT" -output = "暗示表(黒)(2) > 悪意もて真実を語らば" -rands = [ - { sides = 12, value = 2 }, -] - - -[[test]] -game_system = "CastleInGray" -input = "BIT" -output = "暗示表(黒)(3) > 笑えども笑みはなし" -rands = [ - { sides = 12, value = 3 }, -] - - -[[test]] -game_system = "CastleInGray" -input = "BIT" -output = "暗示表(黒)(4) > 影より抜け出ることあたわじ" -rands = [ - { sides = 12, value = 4 }, -] - - -[[test]] -game_system = "CastleInGray" -input = "BIT" -output = "暗示表(黒)(5) > 心の赴くままに手をとれ" -rands = [ - { sides = 12, value = 5 }, -] - - -[[test]] -game_system = "CastleInGray" -input = "BIT" -output = "暗示表(黒)(6) > 時ならぬ嵐の過ぎ去るを待つ" -rands = [ - { sides = 12, value = 6 }, -] - - -[[test]] -game_system = "CastleInGray" -input = "BIT" -output = "暗示表(黒)(7) > 赦されぬと知るがゆえに" -rands = [ - { sides = 12, value = 7 }, -] - - -[[test]] -game_system = "CastleInGray" -input = "BIT" -output = "暗示表(黒)(8) > 見張りは持ち場を離れる" -rands = [ - { sides = 12, value = 8 }, -] - - -[[test]] -game_system = "CastleInGray" -input = "BIT" -output = "暗示表(黒)(9) > 誰もが盲いたる彷徨い人なり" -rands = [ - { sides = 12, value = 9 }, -] - - [[test]] game_system = "CastleInGray" input = "BIT" @@ -325,14 +172,6 @@ rands = [ ] -[[test]] -game_system = "CastleInGray" -input = "BIT" -output = "暗示表(黒)(11) > 冷たく雨ぞ降りしきる" -rands = [ - { sides = 12, value = 11 }, -] - [[test]] game_system = "CastleInGray" @@ -352,42 +191,6 @@ rands = [ ] -[[test]] -game_system = "CastleInGray" -input = "WIT" -output = "暗示表(白)(2) > げに慈悲深きは沈黙なり" -rands = [ - { sides = 12, value = 2 }, -] - - -[[test]] -game_system = "CastleInGray" -input = "WIT" -output = "暗示表(白)(3) > 懐かしき日々は去りぬ" -rands = [ - { sides = 12, value = 3 }, -] - - -[[test]] -game_system = "CastleInGray" -input = "WIT" -output = "暗示表(白)(4) > 束の間に光さす" -rands = [ - { sides = 12, value = 4 }, -] - - -[[test]] -game_system = "CastleInGray" -input = "WIT" -output = "暗示表(白)(5) > 迷える者に手を差し伸べよ" -rands = [ - { sides = 12, value = 5 }, -] - - [[test]] game_system = "CastleInGray" input = "WIT" @@ -397,51 +200,6 @@ rands = [ ] -[[test]] -game_system = "CastleInGray" -input = "WIT" -output = "暗示表(白)(7) > どうか責めないで" -rands = [ - { sides = 12, value = 7 }, -] - - -[[test]] -game_system = "CastleInGray" -input = "WIT" -output = "暗示表(白)(8) > 灯した明かりを絶やさぬように" -rands = [ - { sides = 12, value = 8 }, -] - - -[[test]] -game_system = "CastleInGray" -input = "WIT" -output = "暗示表(白)(9) > 目を開けて見よ" -rands = [ - { sides = 12, value = 9 }, -] - - -[[test]] -game_system = "CastleInGray" -input = "WIT" -output = "暗示表(白)(10) > 淑やかに訪れる" -rands = [ - { sides = 12, value = 10 }, -] - - -[[test]] -game_system = "CastleInGray" -input = "WIT" -output = "暗示表(白)(11) > 今こそ泣け、さもなくば二度と泣くな" -rands = [ - { sides = 12, value = 11 }, -] - - [[test]] game_system = "CastleInGray" input = "WIT" From 3a87897c52b861f2446903169ed8f604bb2103c8 Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Sat, 21 Aug 2021 09:38:21 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF?= =?UTF-8?q?=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/bcdice/game_system/CastleInGray.rb | 14 +++++--- test/data/CastleInGray.toml | 47 ++++++++++++++++++-------- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/lib/bcdice/game_system/CastleInGray.rb b/lib/bcdice/game_system/CastleInGray.rb index 7396559a4..33fcebe4b 100644 --- a/lib/bcdice/game_system/CastleInGray.rb +++ b/lib/bcdice/game_system/CastleInGray.rb @@ -28,6 +28,7 @@ class CastleInGray < Base ・暗示表(黒) BIT ・暗示表(白) WIT TEXT + TABLES = { "ET" => DiceTable::Table.new( "感情表", @@ -85,18 +86,19 @@ class CastleInGray < Base ), }.freeze - register_prefix('B(1|2|3|4|5|6|7|8|9|10|11|12)W(1|2|3|4|5|6|7|8|9|10|11|12)', 'MAL(1|2|3|4|5|6|7|8|9|10|11|12)', TABLES.keys) + register_prefix('B', 'MAL', TABLES.keys) def eval_game_system_specific_command(command) return roll_color(command) || roll_mal(command) || roll_tables(command, TABLES) end def roll_color(command) - m = /^B(1|2|3|4|5|6|7|8|9|10|11|12)W(1|2|3|4|5|6|7|8|9|10|11|12)$/.match(command) + m = /^B(\d{1,2})W(\d{1,2})$/.match(command) return nil unless m black = m[1].to_i white = m[2].to_i + return nil unless black.between?(1, 12) && white.between?(1, 12) value = @randomizer.roll_once(12) @@ -105,9 +107,9 @@ def roll_color(command) end if white > black - return color_text(black, white, value, value < black || value >= white ? '白' : '黒') + return color_text(black, white, value, black <= value && value < white ? '黒' : '白') else - return color_text(black, white, value, value >= white && value < black ? '白' : '黒') + return color_text(black, white, value, white <= value && value < black ? '白' : '黒') end end @@ -116,10 +118,12 @@ def color_text(black, white, value, result) end def roll_mal(command) - m = /^MAL(1|2|3|4|5|6|7|8|9|10|11|12)$/i.match(command) + m = /^MAL(\d{1,2})$/i.match(command) return nil unless m mal = m[1].to_i + return nil unless mal.between?(1, 12) + value = @randomizer.roll_once(12) result = value <= mal ? '黒' : '白' return "悪意の渦(#{mal}) > [#{value}] > #{result}" diff --git a/test/data/CastleInGray.toml b/test/data/CastleInGray.toml index 3dfe5f7d3..1d8c933e8 100644 --- a/test/data/CastleInGray.toml +++ b/test/data/CastleInGray.toml @@ -54,6 +54,30 @@ rands = [ { sides = 12, value = 4 }, ] +[[ test ]] +game_system = "CastleInGray" +input = "B8W0" +output = "" +rands = [] + +[[ test ]] +game_system = "CastleInGray" +input = "B9W13" +output = "" +rands = [] + +[[ test ]] +game_system = "CastleInGray" +input = "B0W4" +output = "" +rands = [] + +[[ test ]] +game_system = "CastleInGray" +input = "B13W2" +output = "" +rands = [] + [[ test ]] game_system = "CastleInGray" input = "MAL1" @@ -62,7 +86,6 @@ rands = [ { sides = 12, value = 1 }, ] - [[ test ]] game_system = "CastleInGray" input = "MAL1" @@ -71,7 +94,6 @@ rands = [ { sides = 12, value = 2 }, ] - [[ test ]] game_system = "CastleInGray" input = "MAL5" @@ -122,11 +144,15 @@ rands = [ [[ test ]] game_system = "CastleInGray" -input = "MAL12" -output = "悪意の渦(12) > [3] > 黒" -rands = [ - { sides = 12, value = 3 }, -] +input = "MAL0" +output = "" +rands = [] + +[[ test ]] +game_system = "CastleInGray" +input = "MAL13" +output = "" +rands = [] [[test]] game_system = "CastleInGray" @@ -136,7 +162,6 @@ rands = [ { sides = 12, value = 1 }, ] - [[test]] game_system = "CastleInGray" input = "ET" @@ -145,7 +170,6 @@ rands = [ { sides = 12, value = 4 }, ] - [[test]] game_system = "CastleInGray" input = "ET" @@ -172,7 +196,6 @@ rands = [ ] - [[test]] game_system = "CastleInGray" input = "BIT" @@ -190,7 +213,6 @@ rands = [ { sides = 12, value = 1 }, ] - [[test]] game_system = "CastleInGray" input = "WIT" @@ -199,7 +221,6 @@ rands = [ { sides = 12, value = 6 }, ] - [[test]] game_system = "CastleInGray" input = "WIT" @@ -207,5 +228,3 @@ output = "暗示表(白)(12) > 時が許す間に薔薇を摘め" rands = [ { sides = 12, value = 12 }, ] - -