module BoggleReport
BoggleReport โ IRC cards for Boogle Boggle rounds. Public: new_round, status, current, accept, reject, end_round, info_rules, info_active Tests: test/lib/boggle_game_test.rb
Constants
- STYLE_TITLE
- TAG
- TITLE
Public Instance Methods
Source
# File lib/boggle_report.rb, line 82 def accept(word:, points:, user:, gloss: nil, remaining: nil) IrcReply.card( tag: TAG, title: TITLE, body_lines: accept_body_lines(word: word, points: points, user: user, gloss: gloss, remaining: remaining), footer_parts: ["WordNet"], heading_style: STYLE_TITLE ) end
Source
# File lib/boggle_report.rb, line 92 def accept_body_lines(word:, points:, user:, gloss: nil, remaining: nil) line = "#{word} โ #{points} pt#{points == 1 ? '' : 's'} (#{user})" gloss_text = gloss.to_s line = "#{line} #{gloss_text}" unless gloss_text.empty? line = "#{line} ยท #{remaining} remaining" unless remaining.nil? [line] end
Source
# File lib/boggle_report.rb, line 68 def accept_many(accepts) list = Array(accepts) return accept(**list.first) if list.length == 1 body_lines = list.flat_map { |entry| accept_body_lines(**entry) } IrcReply.card( tag: TAG, title: TITLE, body_lines: body_lines, footer_parts: ["WordNet"], heading_style: STYLE_TITLE ) end
Source
# File lib/boggle_report.rb, line 50 def current(data) grid = data["grid"] found_count = Array(data["found"]).length total = data["total_words"] remaining = total.nil? ? nil : total - found_count body = grid_lines(grid) if total && !remaining.nil? body << IrcFormat.meta_join("#{found_count} found", "#{remaining} remaining") end IrcReply.card( tag: TAG, title: TITLE, body_lines: body, footer_parts: ["active", "WordNet"], heading_style: STYLE_TITLE ) end
Source
# File lib/boggle_report.rb, line 151 def end_round(scores, found_count:) board = Array(scores).sort_by { |nick, pts| [-pts.to_i, nick.to_s] } body = if board.empty? ["No words found this round."] else board.first(3).map.with_index do |(nick, pts), index| "#{index + 1}. #{nick} โ #{pts} pt#{pts.to_i == 1 ? '' : 's'}" end end meta = IrcFormat.meta_join("#{found_count} words", "round complete") IrcReply.card( tag: TAG, title: "Scoreboard", body_lines: body, footer_parts: [meta], heading_style: STYLE_TITLE ) end
Source
# File lib/boggle_report.rb, line 16 def grid_lines(grid) Array(grid).map { |row| Array(row).map(&:upcase).join(" ") } end
Source
# File lib/boggle_report.rb, line 110 def hint(mask:) IrcReply.card( tag: TAG, title: TITLE, body_lines: [mask.to_s], footer_parts: ["hint"], heading_style: STYLE_TITLE ) end
Source
# File lib/boggle_report.rb, line 134 def info_active(total:, breakdown:, found_count: 0, remaining: nil) label = total == 1 ? "1 word to find" : "#{total} words to find" body = ["#{label} โ #{BoggleLexicon::MIN_LENGTH}+ letters only"] breakdown_line = breakdown.sort.map { |len, count| "#{len}-letter: #{count}" } body << IrcFormat.meta_join(*breakdown_line) unless breakdown_line.empty? if found_count.positive? && !remaining.nil? body << IrcFormat.meta_join("#{found_count} found", "#{remaining} remaining") end IrcReply.card( tag: TAG, title: "Word count", body_lines: body, footer_parts: ["WordNet", "no 1โ2 letter words"], heading_style: STYLE_TITLE ) end
Source
# File lib/boggle_report.rb, line 120 def info_rules IrcReply.card( tag: TAG, title: "Word count", body_lines: [ "WordNet dictionary โ #{BoggleLexicon::MIN_LENGTH}+ letters only", "1โ2 letter words are never counted", "Words must trace adjacent cells on the grid" ], footer_parts: ["!boggle new"], heading_style: STYLE_TITLE ) end
Source
# File lib/boggle_report.rb, line 20 def new_round(grid, total_words: nil) body = grid_lines(grid) if total_words label = total_words == 1 ? "1 word to find" : "#{total_words} words to find" body << label end IrcReply.card( tag: TAG, title: TITLE, body_lines: body, footer_parts: ["WordNet", "3+ letters"], heading_style: STYLE_TITLE ) end
Source
# File lib/boggle_report.rb, line 100 def reject(reason) IrcReply.card( tag: TAG, title: TITLE, body_lines: [reason.to_s], footer_parts: ["try again"], heading_style: STYLE_TITLE ) end
Source
# File lib/boggle_report.rb, line 35 def status(data) grid = data["grid"] found_count = Array(data["found"]).length stage = data["stage"].to_s body = grid_lines(grid) body << "#{found_count} word#{found_count == 1 ? '' : 's'} found" IrcReply.card( tag: TAG, title: TITLE, body_lines: body, footer_parts: [stage], heading_style: STYLE_TITLE ) end