4 # :title: Uno Game Plugin for rbot
6 # Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
8 # Copyright:: (C) 2008 Giuseppe Bilotta
12 # Uno Game: get rid of the cards you have
15 # TODO allow full form card names for play
16 # TODO allow choice of rules re stacking + and playing Reverse with them
19 COLORS = %w{Red Green Blue Yellow}
20 SPECIALS = %w{+2 Reverse Skip}
21 NUMERICS = (0..9).to_a
22 VALUES = NUMERICS + SPECIALS
24 def UnoGame.color_map(clr)
37 def UnoGame.irc_color_bg(clr)
38 Irc.color([:white,:black][COLORS.index(clr)%2],UnoGame.color_map(clr))
41 def UnoGame.irc_color_fg(clr)
42 Irc.color(UnoGame.color_map(clr))
45 def UnoGame.colorify(str, fg=false)
47 str.length.times do |i|
49 UnoGame.irc_color_fg(COLORS[i%4]) :
50 UnoGame.irc_color_bg(COLORS[i%4]) ) +str[i,1]
55 UNO = UnoGame.colorify('UNO!', true)
61 attr_reader :shortform
65 def initialize(color, value)
66 raise unless COLORS.include? color
68 raise unless VALUES.include? value
69 if NUMERICS.include? value
77 @shortform = (@color[0,1]+@value).downcase
79 @shortform = (@color[0,1]+@value.to_s[0,1]).downcase
81 @to_s = UnoGame.irc_color_bg(@color) +
82 Bold + ['', @color, @value, ''].join(' ') + NormalText
86 return 0 unless @value.to_s[0,1] == '+'
87 return @value[1,1].to_i
91 SPECIALS.include?(@value)
95 cc = self.color <=> other.color
97 return self.value.to_s <=> other.value.to_s
105 # Wild, Wild +4 cards
107 def initialize(value=nil)
109 raise if value and not value == '+4'
112 @shortform = 'w'+value
118 @to_s = UnoGame.colorify(['', @color, @value, ''].compact.join(' '))
135 has << c if c.shortform == short
144 Bold + @user.to_s + Bold
152 # previous discard, in case of challenge
153 attr_reader :last_discard
154 # channel the game is played in
158 # true if the player picked a card (and can thus pass turn)
159 attr_reader :player_has_picked
160 # number of cards to be picked if the player can't play an appropriate card
166 # the IRC user that created the game
167 attr_accessor :manager
169 def initialize(plugin, channel, manager)
194 return p if p.user == user
198 return p if p.user.irc_downcase == user.irc_downcase(channel.casemap)
201 get_player(user.to_s)
206 def announce(msg, opts={})
207 @bot.say channel, msg, opts
210 def notify(player, msg, opts={})
211 @bot.notice player.user, msg, opts
215 @base_stock = COLORS.inject([]) do |list, clr|
217 list << Card.new(clr, n)
218 list << Card.new(clr, n) unless n == 0
223 @base_stock << Wild.new
224 @base_stock << Wild.new('+4')
229 @stock.replace @base_stock
230 # remove the cards in the players hand
231 @players.each { |p| p.cards.each { |c| @stock.delete_one c } }
232 # remove current top discarded card if present
234 @stock.delete_one(discard)
240 debug "Starting game"
243 announce _("%{p} deals the first card from the stock") % {
249 while Wild === card do
250 @stock.insert(rand(@stock.length), card)
259 @start_time = Time.now
264 Utils.secs_to_string(Time.now-@start_time)
271 # if there are two players, the Reverse acts like a Skip, unless
272 # there's a @picker running, in which case the Reverse should bounce the
273 # pick on the other player
274 if @players.length > 2
276 # put the current player back in its place
277 @players.unshift @players.pop
278 announce _("Playing order was reversed!")
280 announce _("%{cp} bounces the pick to %{np}") % {
281 :cp => @players.first,
290 @players << @players.shift
291 announce _("%{p} skips a turn!") % {
292 # this is first and not last because the actual
293 # turn change will be done by the following next_turn
309 def set_discard(card)
311 @value = card.value.dup rescue card.value
315 @color = card.color.dup
318 @picker += card.picker
319 @last_picker = @discard.picker
329 def next_turn(opts={})
330 @players << @players.shift
331 @player_has_picked = false
332 show_turn unless opts[:silent]
336 # if play is forced, check against the only allowed cards
337 return false if @must_play and not @must_play.include?(card)
340 # During a picker run (i.e. after a +something was played and before a
341 # player is forced to pick) you can only play pickers (+2, +4) and
342 # Reverse. Reverse can be played if the previous card matches by color or
343 # value (as usual), a +4 can always be played, a +2 can be played on a +2
344 # of any color or on a Reverse of the correct color unless a +4 was
349 # Reverse can be played if it matches color or value
350 return (card.color == @color) || (@discard.value == card.value)
352 return false if @last_picker > 2
353 return true if @discard.value == card.value
354 return true if @discard.value == 'Reverse' and @color == card.color
362 # You can always play a Wild
363 return true if Wild === card
364 # On a Wild, you must match the color
366 return card.color == @color
368 # Otherwise, you can match either the value or the color
369 return (card.value == @value) || (card.color == @color)
374 def play_card(source, cards)
375 debug "Playing card #{cards}"
376 p = get_player(source)
377 shorts = cards.gsub(/\s+/,'').match(/^(?:([rbgy]\+?\d){1,2}|([rbgy][rs])|(w(?:\+4)?)([rbgy])?)$/).to_a
380 announce _("what cards were that again?")
384 short = shorts[1] || shorts[2] || shorts[3]
390 toplay = (full == short) ? 1 : 2
392 debug [full, short, jolly, jcolor, toplay].inspect
393 # r7r7 -> r7r7, r7, nil, nil
394 # r7 -> r7, r7, nil, nil
395 # w -> w, nil, w, nil
396 # wg -> wg, nil, w, g
397 if cards = p.has_card?(short)
399 unless can_play(cards.first)
400 announce _("you can't play that card")
403 if cards.length >= toplay
404 # if the played card is a W+4 not played during a stacking +x
405 # TODO if A plays an illegal W+4, B plays a W+4, should the next
406 # player be able to challenge A? For the time being we say no,
407 # but I think he should, and in case A's move was illegal
408 # game would have to go back, A would get the penalty and replay,
409 # while if it was legal the challenger would get 50% more cards,
410 # i.e. 12 cards (or more if the stacked +4 were more). This would
411 # only be possible if the first W+4 was illegal, so it wouldn't
412 # apply for a W+4 played on a +2 anyway.
414 if @picker == 0 and Wild === cards.first and cards.first.value
415 # save the previous discard in case of challenge
416 @last_discard = @discard.dup
417 # save the color too, in case it was a Wild
418 @last_color = @color.dup
420 # mark the move as not challengeable
424 set_discard(p.cards.delete_one(cards.shift))
426 set_discard(p.cards.delete_one(cards.shift))
427 announce _("%{p} plays %{card} twice!") % {
432 announce _("%{p} plays %{card}") % { :p => p, :card => @discard }
434 if p.cards.length == 1
435 announce _("%{p} has %{uno}!") % {
438 elsif p.cards.length == 0
449 choose_color(p.user, jcolor)
451 announce _("%{p}, choose a color with: co r|b|g|y") % { :p => p }
454 announce _("you don't have two cards of that kind")
457 announce _("you don't have that card")
462 return unless @last_discard
467 announce _("%{cp} challenges %{lp}'s %{card}!") % {
468 :cp => cp, :lp => lp, :card => @discard
470 # show the cards of the previous player to the current player
471 notify cp, _("%{p} has %{cards}") % {
472 :p => lp, :cards => lp.cards.join(' ')
474 # check if the previous player had a non-special card of the correct color
477 if c.color == @last_color and not c.special?
483 announce _("%{lp}'s move was legal, %{cp} must pick %{b}%{n}%{b} cards!") % {
484 :cp => cp, :lp => lp, :b => Bold, :n => @picker
492 announce _("%{lp}'s move was %{b}not%{b} legal, %{lp} must pick %{b}%{n}%{b} cards and play again!") % {
493 :cp => cp, :lp => lp, :b => Bold, :n => @picker
495 lp.cards << @discard # put the W+4 back in place
498 @color = @last_color.dup
499 @discard = @last_discard.dup
501 @value = @discard.value.dup rescue @discard.value
505 # force the player to play the current cards
506 @must_play = lp.cards.dup
508 # give him the penalty cards
512 # and restore the turn
513 @players.unshift @players.pop
520 announce _("%{p} passes turn, and has to pick %{b}%{n}%{b} cards!") % {
521 :p => p, :b => Bold, :n => @picker
526 if @player_has_picked
527 announce _("%{p} passes turn") % { :p => p }
529 announce _("you need to pick a card first")
536 def choose_color(user, color)
537 # you can only pick a color if the current color is unset
539 announce _("you can't pick a color now, %{p}") % {
540 :p => get_player(user)
554 announce _('what color is that?')
557 announce _('color is now %{c}') % {
558 :c => UnoGame.irc_color_bg(@color)+" #{@color} "
565 announce _("This %{uno} game has been going on for %{time}") % {
567 :time => elapsed_time
570 announce _("The game hasn't started yet")
575 announce _("%{uno} playing turn: %{players}") % {
576 :uno => UNO, :players => players.join(' ')
580 def show_turn(opts={})
582 cards = opts[:cards] if opts.key?(:cards)
583 player = @players.first
584 announce _("it's %{player}'s turn") % { :player => player }
585 show_user_cards(player) if cards
588 def has_turn?(source)
589 @start_time && (@players.first.user == source)
594 announce _("next player must respond correctly or pick %{b}%{n}%{b} cards") % {
595 :b => Bold, :n => @picker
601 announce _("Current discard: %{card} %{c}") % { :card => @discard,
602 :c => (Wild === @discard) ? UnoGame.irc_color_bg(@color) + " #{@color} " : nil
607 def show_user_cards(player)
608 p = Player === player ? player : get_player(player)
610 notify p, _('Your cards: %{cards}') % {
611 :cards => p.cards.join(' ')
615 def show_all_cards(u=nil)
616 announce(@players.inject([]) { |list, p|
617 list << [p, p.cards.length].join(': ')
626 announce _("%{player} picks a card") % { :player => p }
628 @player_has_picked = true
631 def deal(player, num=1)
634 picked << @stock.delete_one
635 if @stock.length == 0
636 announce _("Shuffling discarded cards")
638 if @stock.length == 0
639 announce _("No more cards!")
640 end_game # FIXME nope!
645 notify player, _("You picked %{picked}") % { :picked => picked.join(' ') }
646 player.cards += picked
651 if p = get_player(user)
652 announce _("you're already in the game, %{p}") % {
657 @dropouts.each do |dp|
659 announce _("you dropped from the game, %{p}, you can't get back in") % {
667 cards = (@players.inject(0) do |s, pl|
669 end*1.0/@players.length).ceil
673 announce _("%{p} joins this game of %{uno}") % {
677 return if @start_time
679 @bot.timer.reschedule(@join_timer, 10)
680 elsif @players.length > 1
681 announce _("game will start in 20 seconds")
682 @join_timer = @bot.timer.add_once(20) {
688 def drop_player(nick)
689 # A nick is passed because the original player might have left
691 unless p = get_player(nick)
692 announce _("%{p} isn't playing %{uno}") % {
697 announce _("%{p} gives up this game of %{uno}") % {
703 @bot.timer.remove(@join_timer)
704 announce _("game start countdown stopped")
707 if p == @players.first
708 next_turn :silent => @start_time.nil?
719 while p.cards.length > 0
720 @stock.insert(rand(@stock.length), p.cards.shift)
723 @dropouts << @players.delete_one(p)
726 def replace_player(old, new)
728 user = channel.get_user(new)
729 if p = get_player(user)
730 announce _("%{p} is already playing %{uno} here") % {
735 # We scan the player list of the player with the old nick, instead
736 # of using get_player, in case of IRC drops etc
738 if p.user.nick == old
740 announce _("%{p} takes %{b}%{old}%{b}'s place at %{uno}") % {
741 :p => p, :b => Bold, :old => old, :uno => UNO
746 announce _("%{b}%{old}%{b} isn't playing %{uno} here") % {
747 :uno => UNO, :b => Bold, :old => old
751 def end_game(halted = false)
752 runtime = @start_time ? Time.now - @start_time : 0
755 announce _("%{uno} game halted after %{time}") % {
756 :time => elapsed_time,
760 announce _("%{uno} game halted before it could start") % {
765 announce _("%{uno} game finished after %{time}! The winner is %{p}") % {
766 :time => elapsed_time,
767 :uno => UNO, :p => @players.first
770 if @picker > 0 and not halted
771 if @discard.value == 'Reverse'
776 announce _("%{p} has to pick %{b}%{n}%{b} cards!") % {
777 :p => p, :n => @picker, :b => Bold
782 score = @players.inject(0) do |sum, p|
783 if p.cards.length > 0
784 announce _("%{p} still had %{cards}") % {
785 :p => p, :cards => p.cards.join(' ')
787 sum += p.cards.inject(0) do |cs, c|
794 closure = { :dropouts => @dropouts, :players => @players, :runtime => runtime }
796 announce _("%{p} wins with %{b}%{score}%{b} points!") % {
797 :p => @players.first, :score => score, :b => Bold
799 closure.merge!(:winner => @players.first, :score => score,
800 :opponents => @players.length - 1)
803 @plugin.do_end_game(@channel, closure)
808 # A won game: store score and number of opponents, so we can calculate
809 # an average score per opponent (requested by Squiddhartha)
810 define_structure :UnoGameWon, :score, :opponents
811 # For each player we store the number of games played, the number of
812 # games forfeited, and an UnoGameWon for each won game
813 define_structure :UnoPlayerStats, :played, :forfeits, :won
815 class UnoPlugin < Plugin
822 def help(plugin, topic="")
826 _("'jo' to join in"),
827 _("'pl <card>' to play <card>: e.g. 'pl g7' to play Green 7, or 'pl rr' to play Red Reverse, or 'pl y2y2' to play both Yellow 2 cards"),
828 _("'pe' to pick a card"),
829 _("'pa' to pass your turn"),
830 _("'co <color>' to pick a color after playing a Wild: e.g. 'co g' to select Green (or 'pl w+4 g' to select the color when playing the Wild)"),
831 _("'ca' to show current cards"),
832 _("'cd' to show the current discard"),
833 _("'ch' to challenge a Wild +4"),
834 _("'od' to show the playing order"),
835 _("'ti' to show play time"),
836 _("'tu' to show whose turn it is")
839 _("A Wild +4 can only be played legally if you don't have normal (not special) cards of the current color. ") +
840 _("The next player can challenge a W+4 by using the 'ch' command. ") +
841 _("If the W+4 play was illegal, the player who played it must pick the W+4, pick 4 cards from the stock, and play a legal card. ") +
842 _("If the W+4 play was legal, the challenger must pick 6 cards instead of 4.")
844 _("play all your cards, one at a time, by matching either the color or the value of the currently discarded card. ") +
845 _("cards with special effects: Skip (next player skips a turn), Reverse (reverses the playing order), +2 (next player has to take 2 cards). ") +
846 _("Wilds can be played on any card, and you must specify the color for the next card. ") +
847 _("Wild +4 also forces the next player to take 4 cards, but it can only be played if you can't play a color card. ") +
848 _("you can play another +2 or +4 card on a +2 card, and a +4 on a +4, forcing the first player who can't play one to pick the cumulative sum of all cards. ") +
849 _("you can also play a Reverse on a +2 or +4, bouncing the effect back to the previous player (that now comes next). ")
850 when /scor(?:e|ing)/, /points?/
852 _("The points won with a game of %{uno} are totalled from the cards remaining in the hands of the other players."),
853 _("Each normal (not special) card is worth its face value (from 0 to 9 points)."),
854 _("Each colored special card (+2, Reverse, Skip) is worth 20 points."),
855 _("Each Wild and Wild +4 is worth 50 points."),
857 help(plugin, 'topwin'),
858 ].join(" ") % { :uno => UnoGame::UNO }
860 _("You can see the scoring table with 'uno top N' where N is the number of top scores to show.")
862 _("You can see the winners table with 'uno topwin N' where N is the number of top winners to show.")
865 _("There are 108 cards in a standard %{uno} deck."),
866 _("For each color (Blue, Green, Red, Yellow) there are 19 numbered cards (from 0 to 9), with two of each number except for 0."),
867 _("There are also 6 special cards for each color, two each of +2, Reverse, Skip."),
868 _("Finally, there are 4 Wild and 4 Wild +4 cards.")
869 ].join(" ") % { :uno => UnoGame::UNO }
871 _("The game manager (the user that started the game) can execute the following commands to manage it: ") +
873 _("'uno drop <user>' to drop a user from the game (any user can drop itself using 'uno drop')"),
874 _("'uno replace <old> [with] <new>' to replace a player with someone else (useful in case of disconnects)"),
875 _("'uno transfer [to] <nick>' to transfer game ownership to someone else"),
876 _("'uno end' to end the game before its natural completion")
879 _("%{uno} game. !uno to start a game. see 'help uno rules' for the rules, 'help uno admin' for admin commands, 'help uno score' for scoring rules. In-game commands: %{cmds}.") % {
880 :uno => UnoGame::UNO,
881 :cmds => help(plugin, 'commands')
887 return unless @games.key?(m.channel)
888 return unless m.plugin # skip messages such as: <someuser> botname,
889 g = @games[m.channel]
894 g.add_player(m.source)
897 if g.has_turn?(m.source)
898 if g.player_has_picked
899 m.reply _("you already picked a card")
903 g.pick_card(m.source)
906 m.reply _("It's not your turn")
909 return if m.params or not g.start_time
910 if g.has_turn?(m.source)
913 m.reply _("It's not your turn")
916 if g.has_turn?(m.source)
917 g.play_card(m.source, m.params.downcase)
919 m.reply _("It's not your turn")
921 when :co # pick color
922 if g.has_turn?(m.source)
923 g.choose_color(m.source, m.params.downcase)
925 m.reply _("It's not your turn")
927 when :ca # show current cards
929 g.show_all_cards(m.source)
930 when :cd # show current discard
931 return if m.params or not g.start_time
934 if g.has_turn?(m.source)
938 m.reply _("previous move cannot be challenged")
941 m.reply _("It's not your turn")
943 when :od # show playing order
946 when :ti # show play time
949 when :tu # show whose turn is it
951 if g.has_turn?(m.source)
952 m.reply _("it's your turn, sleepyhead"), :nick => true
954 g.show_turn(:cards => false)
959 m.replied=true if replied
962 def create_game(m, p)
963 if @games.key?(m.channel)
964 m.reply _("There is already an %{uno} game running here, managed by %{who}. say 'jo' to join in") % {
965 :who => @games[m.channel].manager,
970 @games[m.channel] = UnoGame.new(self, m.channel, m.source)
971 @bot.auth.irc_to_botuser(m.source).set_temp_permission('uno::manage', true, m.channel)
972 m.reply _("Ok, created %{uno} game on %{channel}, say 'jo' to join in") % {
973 :uno => UnoGame::UNO,
974 :channel => m.channel
978 def transfer_ownership(m, p)
979 unless @games.key?(m.channel)
980 m.reply _("There is no %{uno} game running here") % { :uno => UnoGame::UNO }
983 g = @games[m.channel]
985 new = m.channel.get_user(p[:nick])
988 @bot.auth.irc_to_botuser(old).reset_temp_permission('uno::manage', m.channel)
989 @bot.auth.irc_to_botuser(new).set_temp_permission('uno::manage', true, m.channel)
990 m.reply _("%{uno} game ownership transferred from %{old} to %{nick}") % {
991 :uno => UnoGame::UNO, :old => old, :nick => p[:nick]
994 m.reply _("who is this %{nick} you want me to transfer game ownership to?") % p
999 unless @games.key?(m.channel)
1000 m.reply _("There is no %{uno} game running here") % { :uno => UnoGame::UNO }
1003 @games[m.channel].end_game(true)
1007 @games.each { |k, g| g.end_game(true) }
1011 def chan_reg(channel)
1012 @registry.sub_registry(channel.downcase)
1015 def chan_stats(channel)
1016 stats = chan_reg(channel).sub_registry('stats')
1025 stats.set_default(0)
1029 def chan_pstats(channel)
1030 pstats = chan_reg(channel).sub_registry('players')
1031 pstats.set_default(UnoPlayerStats.new(0,0,[]))
1035 def do_end_game(channel, closure)
1036 reg = chan_reg(channel)
1037 stats = chan_stats(channel)
1038 stats['played'] += 1
1039 stats['played_runtime'] += closure[:runtime]
1041 stats['finished'] += 1
1042 stats['finished_runtime'] += closure[:runtime]
1044 pstats = chan_pstats(channel)
1046 closure[:players].each do |pl|
1047 k = pl.user.downcase
1053 closure[:dropouts].each do |pl|
1054 k = pl.user.downcase
1061 winner = closure[:winner]
1062 won = UnoGameWon.new(closure[:score], closure[:opponents])
1063 k = winner.user.downcase
1064 pls = pstats[k] # already marked played +1 above
1069 @bot.auth.irc_to_botuser(@games[channel].manager).reset_temp_permission('uno::manage', channel)
1070 @games.delete(channel)
1073 def do_chanstats(m, p)
1074 stats = chan_stats(m.channel)
1075 np = stats['played']
1076 nf = stats['finished']
1078 str = _("%{nf} %{uno} games completed over %{np} games played. ") % {
1079 :np => np, :uno => UnoGame::UNO, :nf => nf
1081 cgt = stats['finished_runtime']
1082 tgt = stats['played_runtime']
1083 str << _("%{cgt} game time for completed games") % {
1084 :cgt => Utils.secs_to_string(cgt)
1087 str << _(" on %{tgt} total game time. ") % {
1088 :tgt => Utils.secs_to_string(tgt)
1093 str << _("%{avg} average game time for completed games") % {
1094 :avg => Utils.secs_to_string(cgt/nf)
1096 str << _(", %{tavg} for all games") % {
1097 :tavg => Utils.secs_to_string(tgt/np)
1101 m.reply _("nobody has played %{uno} on %{chan} yet") % {
1102 :uno => UnoGame::UNO, :chan => m.channel
1108 dnick = p[:nick] || m.source # display-nick, don't later case
1109 nick = dnick.downcase
1110 ps = chan_pstats(m.channel)[nick]
1112 m.reply _("%{nick} never played %{uno} here") % {
1113 :uno => UnoGame::UNO, :nick => dnick
1120 score = ps.won.inject(0) { |sum, w| sum += w.score }
1121 str = _("%{nick} played %{np} %{uno} games here, ") % {
1122 :nick => dnick, :np => np, :uno => UnoGame::UNO
1124 str << _("forfeited %{nf} games, ") % { :nf => nf } if nf > 0
1125 str << _("won %{nw} games") % { :nw => nw}
1127 str << _(" with %{score} total points") % { :score => score }
1128 avg = ps.won.inject(0) { |sum, w| sum += w.score/w.opponents }/nw
1129 str << _(" and an average of %{avg} points per opponent") % { :avg => avg }
1134 def replace_player(m, p)
1135 unless @games.key?(m.channel)
1136 m.reply _("There is no %{uno} game running here") % { :uno => UnoGame::UNO }
1139 @games[m.channel].replace_player(p[:old], p[:new])
1142 def drop_player(m, p)
1143 unless @games.key?(m.channel)
1144 m.reply _("There is no %{uno} game running here") % { :uno => UnoGame::UNO }
1147 @games[m.channel].drop_player(p[:nick] || m.source.nick)
1150 def print_stock(m, p)
1151 unless @games.key?(m.channel)
1152 m.reply _("There is no %{uno} game running here") % { :uno => UnoGame::UNO }
1155 stock = @games[m.channel].stock
1156 m.reply(_("%{num} cards in stock: %{stock}") % {
1157 :num => stock.length,
1158 :stock => stock.join(' ')
1159 }, :split_at => /#{NormalText}\s*/)
1163 pstats = chan_pstats(m.channel)
1166 pstats.each do |k, v|
1167 wins << [v.won.length, k]
1168 scores << [v.won.inject(0) { |s, w| s+=w.score }, k]
1172 m.reply(_("no %{uno} games were completed here") % {
1173 :uno => UnoGame::UNO
1180 msg = _("%{uno} %{num} highest scores: ") % {
1181 :uno => UnoGame::UNO, :num => p[:scorenum]
1183 scores.sort! { |a1, a2| -(a1.first <=> a2.first) }
1184 scores = scores[0, n.to_i].compact
1186 if scores.length <= 5
1187 list = "\n" + scores.map { |a|
1189 _("%{i}. %{b}%{nick}%{b} with %{b}%{score}%{b} points") % {
1190 :i => i, :b => Bold, :nick => a.last, :score => a.first
1194 list = scores.map { |a|
1196 _("%{i}. %{nick} ( %{score} )") % {
1197 :i => i, :nick => a.last, :score => a.first
1201 elsif n = p[:winnum]
1202 msg = _("%{uno} %{num} most wins: ") % {
1203 :uno => UnoGame::UNO, :num => p[:winnum]
1205 wins.sort! { |a1, a2| -(a1.first <=> a2.first) }
1206 wins = wins[0, n.to_i].compact
1209 list = "\n" + wins.map { |a|
1211 _("%{i}. %{b}%{nick}%{b} with %{b}%{score}%{b} wins") % {
1212 :i => i, :b => Bold, :nick => a.last, :score => a.first
1216 list = wins.map { |a|
1218 _("%{i}. %{nick} ( %{score} )") % {
1219 :i => i, :nick => a.last, :score => a.first
1224 msg = _("uh, what kind of score list did you want, again?")
1225 list = _(" I can only show the top scores (with top) and the most wins (with topwin)")
1227 m.reply msg + list, :max_lines => (msg+list).count("\n")+1
1233 pg.map 'uno', :private => false, :action => :create_game
1234 pg.map 'uno end', :private => false, :action => :end_game, :auth_path => 'manage'
1235 pg.map 'uno drop', :private => false, :action => :drop_player, :auth_path => 'manage::drop::self!'
1236 pg.map 'uno giveup', :private => false, :action => :drop_player, :auth_path => 'manage::drop::self!'
1237 pg.map 'uno drop :nick', :private => false, :action => :drop_player, :auth_path => 'manage::drop::other!'
1238 pg.map 'uno replace :old [with] :new', :private => false, :action => :replace_player, :auth_path => 'manage'
1239 pg.map 'uno transfer [game [ownership]] [to] :nick', :private => false, :action => :transfer_ownership, :auth_path => 'manage'
1240 pg.map 'uno stock', :private => false, :action => :print_stock
1241 pg.map 'uno chanstats', :private => false, :action => :do_chanstats
1242 pg.map 'uno stats [:nick]', :private => false, :action => :do_pstats
1243 pg.map 'uno top :scorenum', :private => false, :action => :do_top, :defaults => { :scorenum => 5 }
1244 pg.map 'uno topwin :winnum', :private => false, :action => :do_top, :defaults => { :winnum => 5 }
1246 pg.default_auth('stock', false)
1247 pg.default_auth('manage', false)
1248 pg.default_auth('manage::drop::self', true)