]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - data/rbot/plugins/games/uno.rb
1df903d3fd3c58863a4eee0abf27ab4710a6b5b7
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / games / uno.rb
1 #-- vim:sw=2:et
2 #++
3 #
4 # :title: Uno Game Plugin for rbot
5 #
6 # Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
7 #
8 # Copyright:: (C) 2008 Giuseppe Bilotta
9 #
10 # License:: GPL v2
11 #
12 # Uno Game: get rid of the cards you have
13 #
14 # TODO documentation
15 # TODO allow full form card names for play
16 # TODO allow color specification with wild
17 # TODO allow choice of rules re stacking + and playing Reverse with them
18 # TODO highscore table
19
20 class UnoGame
21   COLORS = %w{Red Green Blue Yellow}
22   SPECIALS = %w{+2 Reverse Skip}
23   NUMERICS = (0..9).to_a
24   VALUES = NUMERICS + SPECIALS
25
26   def UnoGame.color_map(clr)
27     case clr
28     when 'Red'
29       :red
30     when 'Blue'
31       :royal_blue
32     when 'Green'
33       :limegreen
34     when 'Yellow'
35       :yellow
36     end
37   end
38
39   def UnoGame.irc_color_bg(clr)
40     Irc.color([:white,:black][COLORS.index(clr)%2],UnoGame.color_map(clr))
41   end
42
43   def UnoGame.irc_color_fg(clr)
44     Irc.color(UnoGame.color_map(clr))
45   end
46
47   def UnoGame.colorify(str, fg=false)
48     ret = Bold.dup
49     str.length.times do |i|
50       ret << (fg ?
51               UnoGame.irc_color_fg(COLORS[i%4]) :
52               UnoGame.irc_color_bg(COLORS[i%4]) ) +str[i,1]
53     end
54     ret << NormalText
55   end
56
57   UNO = UnoGame.colorify('UNO!', true)
58
59   # Colored play cards
60   class Card
61     attr_reader :color
62     attr_reader :value
63     attr_reader :shortform
64     attr_reader :to_s
65     attr_reader :score
66
67     def initialize(color, value)
68       raise unless COLORS.include? color
69       @color = color.dup
70       raise unless VALUES.include? value
71       if NUMERICS.include? value
72         @value = value
73         @score = value
74       else
75         @value = value.dup
76         @score = 20
77       end
78       if @value == '+2'
79         @shortform = (@color[0,1]+@value).downcase
80       else
81         @shortform = (@color[0,1]+@value.to_s[0,1]).downcase
82       end
83       @to_s = UnoGame.irc_color_bg(@color) +
84         Bold + ['', @color, @value, ''].join(' ') + NormalText
85     end
86
87     def picker
88       return 0 unless @value.to_s[0,1] == '+'
89       return @value[1,1].to_i
90     end
91
92     def special?
93       SPECIALS.include?(@value)
94     end
95
96     def <=>(other)
97       cc = self.color <=> other.color
98       if cc == 0
99         return self.value.to_s <=> other.value.to_s
100       else
101         return cc
102       end
103     end
104     include Comparable
105   end
106
107   # Wild, Wild +4 cards
108   class Wild < Card
109     def initialize(value=nil)
110       @color = 'Wild'
111       raise if value and not value == '+4'
112       if value
113         @value = value.dup 
114         @shortform = 'w'+value
115       else
116         @value = nil
117         @shortform = 'w'
118       end
119       @score = 50
120       @to_s = UnoGame.colorify(['', @color, @value, ''].compact.join(' '))
121     end
122     def special?
123       @value
124     end
125   end
126
127   class Player
128     attr_accessor :cards
129     attr_accessor :user
130     def initialize(user)
131       @user = user
132       @cards = []
133     end
134     def has_card?(short)
135       has = []
136       @cards.each { |c|
137         has << c if c.shortform == short
138       }
139       if has.empty?
140         return false
141       else
142         return has
143       end
144     end
145     def to_s
146       Bold + @user.to_s + Bold
147     end
148   end
149
150   # cards in stock
151   attr_reader :stock
152   # current discard
153   attr_reader :discard
154   # previous discard, in case of challenge
155   attr_reader :last_discard
156   # channel the game is played in
157   attr_reader :channel
158   # list of players
159   attr :players
160   # true if the player picked a card (and can thus pass turn)
161   attr_reader :player_has_picked
162   # number of cards to be picked if the player can't play an appropriate card
163   attr_reader :picker
164
165   def initialize(plugin, channel)
166     @channel = channel
167     @plugin = plugin
168     @bot = plugin.bot
169     @players = []
170     @dropouts = []
171     @discard = nil
172     @last_discard = nil
173     @value = nil
174     @color = nil
175     make_base_stock
176     @stock = []
177     make_stock
178     @start_time = nil
179     @join_timer = nil
180     @picker = 0
181     @last_picker = 0
182     @must_play = nil
183   end
184
185   def get_player(user)
186     @players.each { |p| return p if p.user == user }
187     return nil
188   end
189
190   def announce(msg, opts={})
191     @bot.say channel, msg, opts
192   end
193
194   def notify(player, msg, opts={})
195     @bot.notice player.user, msg, opts
196   end
197
198   def make_base_stock
199     @base_stock = COLORS.inject([]) do |list, clr|
200       VALUES.each do |n|
201         list << Card.new(clr, n)
202         list << Card.new(clr, n) unless n == 0
203       end
204       list
205     end
206     4.times do
207       @base_stock << Wild.new
208       @base_stock << Wild.new('+4')
209     end
210   end
211
212   def make_stock
213     @stock.replace @base_stock
214     # remove the cards in the players hand
215     @players.each { |p| p.cards.each { |c| @stock.delete_one c } }
216     # remove current top discarded card if present
217     if @discard
218       @stock.delete_one(discard)
219     end
220     @stock.shuffle!
221   end
222
223   def start_game
224     debug "Starting game"
225     @players.shuffle!
226     show_order
227     announce _("%{p} deals the first card from the stock") % {
228       :p => @players.first
229     }
230     card = @stock.shift
231     @picker = 0
232     @special = false
233     while Wild === card do
234       @stock.insert(rand(@stock.length), card)
235       card = @stock.shift
236     end
237     set_discard(card)
238     show_discard
239     if @special
240       do_special
241     end
242     next_turn
243     @start_time = Time.now
244   end
245
246   def elapsed_time
247     if @start_time
248       Utils.secs_to_string(Time.now-@start_time)
249     else
250       _("no time")
251     end
252   end
253
254   def reverse_turn
255     if @players.length > 2
256       @players.reverse!
257       # put the current player back in its place
258       @players.unshift @players.pop
259       announce _("Playing order was reversed!")
260     else
261       skip_turn
262     end
263   end
264
265   def skip_turn
266     @players << @players.shift
267     announce _("%{p} skips a turn!") % {
268       # this is first and not last because the actual
269       # turn change will be done by the following next_turn
270       :p => @players.first
271     }
272   end
273
274   def do_special
275     case @discard.value
276     when 'Reverse'
277       reverse_turn
278       @special = false
279     when 'Skip'
280       skip_turn
281       @special = false
282     end
283   end
284
285   def set_discard(card)
286     @discard = card
287     @value = card.value.dup rescue card.value
288     if Wild === card
289       @color = nil
290     else
291       @color = card.color.dup
292     end
293     if card.picker > 0
294       @picker += card.picker
295       @last_picker = @discard.picker
296     end
297     if card.special?
298       @special = true
299     else
300       @special = false
301     end
302     @must_play = nil
303   end
304
305   def next_turn(opts={})
306     @players << @players.shift
307     @player_has_picked = false
308     show_turn
309   end
310
311   def can_play(card)
312     # if play is forced, check against the only allowed cards
313     return false if @must_play and not @must_play.include?(card)
314
315     # When a +something is online, you can only play
316     # a +something of same or higher something, or a Reverse of
317     # the correct color
318     # TODO make optional
319     if @picker > 0
320       if (card.value == 'Reverse' and card.color == @color) or card.picker >= @last_picker
321         return true
322       else
323         return false
324       end
325     else
326       # You can always play a Wild
327       return true if Wild === card
328       # On a Wild, you must match the color
329       if Wild === @discard
330         return card.color == @color
331       else
332         # Otherwise, you can match either the value or the color
333         return (card.value == @value) || (card.color == @color)
334       end
335     end
336   end
337
338   def play_card(source, cards)
339     debug "Playing card #{cards}"
340     p = get_player(source)
341     shorts = cards.gsub(/\s+/,'').match(/^(?:([rbgy]\+?\d){1,2}|([rbgy][rs])|(w(?:\+4)?)([rbgy])?)$/).to_a
342     debug shorts.inspect
343     if shorts.empty?
344       announce _("what cards were that again?")
345       return
346     end
347     full = shorts[0]
348     short = shorts[1] || shorts[2] || shorts[3]
349     jolly = shorts[3]
350     jcolor = shorts[4]
351     if jolly
352       toplay = 1
353     else
354       toplay = (full == short) ? 1 : 2
355     end
356     debug [full, short, jolly, jcolor, toplay].inspect
357     # r7r7 -> r7r7, r7, nil, nil
358     # r7 -> r7, r7, nil, nil
359     # w -> w, nil, w, nil
360     # wg -> wg, nil, w, g
361     if cards = p.has_card?(short)
362       debug cards
363       unless can_play(cards.first)
364         announce _("you can't play that card")
365         return
366       end
367       if cards.length >= toplay
368         # if the played card is a W+4 not played during a stacking +x
369         if @picker == 0 and Wild === cards.first and cards.first.value 
370           # save the previous discard in case of challenge
371           @last_discard = @discard.dup
372           # save the color too, in case it was a Wild
373           @last_color = @color.dup
374         else
375           @last_color = nil
376         end
377         set_discard(p.cards.delete_one(cards.shift))
378         if toplay > 1
379           set_discard(p.cards.delete_one(cards.shift))
380           announce _("%{p} plays %{card} twice!") % {
381             :p => p,
382             :card => @discard
383           }
384         else
385           announce _("%{p} plays %{card}") % { :p => p, :card => @discard }
386         end
387         if p.cards.length == 1
388           announce _("%{p} has %{uno}!") % {
389             :p => p, :uno => UNO
390           }
391         elsif p.cards.length == 0
392           end_game
393           return
394         end
395         show_picker
396         if @color
397           if @special
398             do_special
399           end
400           next_turn
401         elsif jcolor
402           choose_color(p.user, jcolor)
403         else
404           announce _("%{p}, choose a color with: co r|b|g|y") % { :p => p }
405         end
406       else
407         announce _("you don't have two cards of that kind")
408       end
409     else
410       announce _("you don't have that card")
411     end
412   end
413
414   def challenge
415     return unless @last_discard
416     # current player
417     cp = @players.first
418     # previous player
419     lp = @players.last
420     announce _("%{cp} challenges %{lp}'s %{card}!") % {
421       :cp => cp, :lp => lp, :card => @discard
422     }
423     # show the cards of the previous player to the current player
424     notify cp, _("%{p} has %{cards}") % {
425       :p => lp, :cards => lp.cards.join(' ')
426     }
427     # check if the previous player had a non-special card of the correct color
428     legal = true
429     lp.cards.each do |c|
430       if c.color == @last_color and not c.special?
431         legal = false
432       end
433     end
434     if legal
435       @picker += 2
436       announce _("%{lp}'s move was legal, %{cp} must pick %{b}%{n}%{b} cards!") % {
437         :cp => cp, :lp => lp, :b => Bold, :n => @picker
438       }
439       @last_color = nil
440       @last_discard = nil
441       deal(cp, @picker)
442       @picker = 0
443       next_turn
444     else
445       announce _("%{lp}'s move was %{b}not%{b} legal, %{lp} must pick %{b}%{n}%{b} cards and play again!") % {
446         :cp => cp, :lp => lp, :b => Bold, :n => @picker
447       }
448       lp.cards << @discard # put the W+4 back in place
449
450       # reset the discard
451       @color = @last_color.dup
452       @discard = @last_discard.dup
453       @special = false
454       @value = @discard.value.dup rescue @discard.value
455       @last_color = nil
456       @last_discard = nil
457
458       # force the player to play the current cards
459       @must_play = lp.cards.dup
460
461       # give him the penalty cards
462       deal(lp, @picker)
463       @picker = 0
464
465       # and restore the turn
466       @players.unshift @players.pop
467     end
468   end
469
470   def pass(user)
471     p = get_player(user)
472     if @picker > 0
473       announce _("%{p} passes turn, and has to pick %{b}%{n}%{b} cards!") % {
474         :p => p, :b => Bold, :n => @picker
475       }
476       deal(p, @picker)
477       @picker = 0
478     else
479       if @player_has_picked
480         announce _("%{p} passes turn") % { :p => p }
481       else
482         announce _("you need to pick a card first")
483         return
484       end
485     end
486     next_turn
487   end
488
489   def choose_color(user, color)
490     case color
491     when 'r'
492       @color = 'Red'
493     when 'b'
494       @color = 'Blue'
495     when 'g'
496       @color = 'Green'
497     when 'y'
498       @color = 'Yellow'
499     else
500       announce _('what color is that?')
501       return
502     end
503     announce _('color is now %{c}') % {
504       :c => UnoGame.irc_color_bg(@color)+" #{@color} "
505     }
506     next_turn
507   end
508
509   def show_time
510     if @start_time
511       announce _("This %{uno} game has been going on for %{time}") % {
512         :uno => UNO,
513         :time => elapsed_time
514       }
515     else
516       announce _("The game hasn't started yet")
517     end
518   end
519
520   def show_order
521     announce _("%{uno} playing turn: %{players}") % {
522       :uno => UNO, :players => players.join(' ')
523     }
524   end
525
526   def show_turn(opts={})
527     cards = true
528     cards = opts[:cards] if opts.key?(:cards)
529     player = @players.first
530     announce _("it's %{player}'s turn") % { :player => player }
531     show_user_cards(player) if cards
532   end
533
534   def has_turn?(source)
535     @players.first.user == source
536   end
537
538   def show_picker
539     if @picker > 0
540       announce _("next player must respond correctly or pick %{b}%{n}%{b} cards") % {
541         :b => Bold, :n => @picker
542       }
543     end
544   end
545
546   def show_discard
547     announce _("Current discard: %{card} %{c}") % { :card => @discard,
548       :c => (Wild === @discard) ? UnoGame.irc_color_bg(@color) + " #{@color} " : nil
549     }
550     show_picker
551   end
552
553   def show_user_cards(player)
554     p = Player === player ? player : get_player(player)
555     notify p, _('Your cards: %{cards}') % {
556       :cards => p.cards.join(' ')
557     }
558   end
559
560   def show_all_cards(u=nil)
561     announce(@players.inject([]) { |list, p|
562       list << [p, p.cards.length].join(': ')
563     }.join(', '))
564     if u
565       show_user_cards(u)
566     end
567   end
568
569   def pick_card(user)
570     p = get_player(user)
571     announce _("%{player} picks a card") % { :player => p }
572     deal(p, 1)
573     @player_has_picked = true
574   end
575
576   def deal(player, num=1)
577     picked = []
578     num.times do
579       picked << @stock.delete_one
580       if @stock.length == 0
581         announce _("Shuffling discarded cards")
582         make_stock
583         if @stock.length == 0
584           announce _("No more cards!")
585           end_game # FIXME nope!
586         end
587       end
588     end
589     picked.sort!
590     notify player, _("You picked %{picked}") % { :picked => picked.join(' ') }
591     player.cards += picked
592     player.cards.sort!
593   end
594
595   def add_player(user)
596     if p = get_player(user)
597       announce _("you're already in the game, %{p}") % {
598         :p => p
599       }
600       return
601     end
602     @dropouts.each do |dp|
603       if dp.user == user
604         announce _("you dropped from the game, %{p}, you can't get back in") % {
605           :p => dp
606         }
607         return
608       end
609     end
610     cards = 7
611     if @start_time
612       cards = @players.inject(0) do |s, pl|
613         s +=pl.cards.length
614       end/@players.length
615     end
616     p = Player.new(user)
617     @players << p
618     announce _("%{p} joins this game of %{uno}") % {
619       :p => p, :uno => UNO
620     }
621     deal(p, cards)
622     return if @start_time
623     if @join_timer
624       @bot.timer.reschedule(@join_timer, 10)
625     elsif @players.length > 1
626       announce _("game will start in 20 seconds")
627       @join_timer = @bot.timer.add_once(20) {
628         start_game
629       }
630     end
631   end
632
633   def drop_player(user)
634     unless p = get_player(user)
635       announce _("%{p} isn't playing %{uno}") % {
636         :p => p, :uno => UNO
637       }
638       return
639     end
640     announce _("%{p} gives up this game of %{uno}") % {
641       :p => p, :uno => UNO
642     }
643     case @players.length
644     when 2
645       if p == @players.first
646         next_turn
647       end
648       end_game
649       return
650     when 1
651       end_game(true)
652       return
653     end
654     debug @stock.length
655     while p.cards.length > 0
656       @stock.insert(rand(@stock.length), p.cards.shift)
657     end
658     debug @stock.length
659     @dropouts << @players.delete_one(p)
660   end
661
662   def replace_player(old, new)
663     # The new user
664     user = channel.get_user(new)
665     if p = get_player(user)
666       announce _("%{p} is already playing %{uno} here") % {
667         :p => p, :uno => UNO
668       }
669       return
670     end
671     # We scan the player list of the player with the old nick, instead
672     # of using get_player, in case of IRC drops etc
673     @players.each do |p|
674       if p.user.nick == old
675         p.user = user
676         announce _("%{p} takes %{b}%{old}%{b}'s place at %{uno}") % {
677           :p => p, :b => Bold, :old => old, :uno => UNO
678         }
679         return
680       end
681     end
682     announce _("%{b}%{old}%{b} isn't playing %{uno} here") % {
683       :uno => UNO, :b => Bold, :old => old
684     }
685   end
686
687   def end_game(halted = false)
688     if halted
689       if @start_time
690         announce _("%{uno} game halted after %{time}") % {
691           :time => elapsed_time,
692           :uno => UNO
693         }
694       else
695         announce _("%{uno} game halted before it could start") % {
696           :uno => UNO
697         }
698       end
699     else
700       announce _("%{uno} game finished after %{time}! The winner is %{p}") % {
701         :time => elapsed_time,
702         :uno => UNO, :p => @players.first
703       }
704     end
705     if @picker > 0 and not halted
706       p = @players[1]
707       announce _("%{p} has to pick %{b}%{n}%{b} cards!") % {
708         :p => p, :n => @picker, :b => Bold
709       }
710       deal(p, @picker)
711       @picker = 0
712     end
713     score = @players.inject(0) do |sum, p|
714       if p.cards.length > 0
715         announce _("%{p} still had %{cards}") % {
716           :p => p, :cards => p.cards.join(' ')
717         }
718         sum += p.cards.inject(0) do |cs, c|
719           cs += c.score
720         end
721       end
722       sum
723     end
724     if not halted
725       announce _("%{p} wins with %{b}%{score}%{b} points!") % {
726         :p => @players.first, :score => score, :b => Bold
727       }
728     end
729     @plugin.do_end_game(@channel)
730   end
731
732 end
733
734 class UnoPlugin < Plugin
735   attr :games
736   def initialize
737     super
738     @games = {}
739   end
740
741   def help(plugin, topic="")
742     case topic
743     when 'commands'
744       [
745       _("'jo' to join in"),
746       _("'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"),
747       _("'pe' to pick a card"),
748       _("'pa' to pass your turn"),
749       _("'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)"),
750       _("'ca' to show current cards"),
751       _("'cd' to show the current discard"),
752       _("'ch' to challenge a Wild +4"),
753       _("'od' to show the playing order"),
754       _("'ti' to show play time"),
755       _("'tu' to show whose turn it is")
756     ].join(" ; ")
757     when 'challenge'
758       _("A Wild +4 can only be played legally if you don't have normal (not special) cards of the current color. ") +
759       _("The next player can challenge a W+4 by using the 'ch' command. ") +
760       _("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. ") +
761       _("If the W+4 play was legal, the challenger must pick 6 cards instead of 4.")
762     when 'rules'
763       _("play all your cards, one at a time, by matching either the color or the value of the currently discarded card. ") +
764       _("cards with special effects: Skip (next player skips a turn), Reverse (reverses the playing order), +2 (next player has to take 2 cards). ") +
765       _("Wilds can be played on any card, and you must specify the color for the next card. ") +
766       _("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. ") +
767       _("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. ") +
768       _("you can also play a Reverse on a +2 or +4, bouncing the effect back to the previous player (that now comes next). ")
769     else
770       (_("%{uno} game. !uno to start a game. see help uno rules for the rules. commands: %{cmds}") % {
771         :uno => UnoGame::UNO,
772         :cmds => help(plugin, 'commands')
773       })
774     end
775   end
776
777   def message(m)
778     return unless @games.key?(m.channel)
779     g = @games[m.channel]
780     case m.plugin.intern
781     when :jo # join game
782       return if m.params
783       g.add_player(m.source)
784     when :pe # pick card
785       return if m.params
786       if g.has_turn?(m.source)
787         if g.player_has_picked
788           m.reply _("you already picked a card")
789         elsif g.picker > 0
790           g.pass(m.source)
791         else
792           g.pick_card(m.source)
793         end
794       else
795         m.reply _("It's not your turn")
796       end
797     when :pa # pass turn
798       return if m.params
799       if g.has_turn?(m.source)
800         g.pass(m.source)
801       else
802         m.reply _("It's not your turn")
803       end
804     when :pl # play card
805       if g.has_turn?(m.source)
806         g.play_card(m.source, m.params.downcase)
807       else
808         m.reply _("It's not your turn")
809       end
810     when :co # pick color
811       if g.has_turn?(m.source)
812         g.choose_color(m.source, m.params.downcase)
813       else
814         m.reply _("It's not your turn")
815       end
816     when :ca # show current cards
817       return if m.params
818       g.show_all_cards(m.source)
819     when :cd # show current discard
820       return if m.params
821       g.show_discard
822     when :ch
823       if g.has_turn?(m.source)
824         if g.last_discard
825           g.challenge
826         else
827           m.reply _("previous move cannot be challenged")
828         end
829       else
830         m.reply _("It's not your turn")
831       end
832     when :od # show playing order
833       return if m.params
834       g.show_order
835     when :ti # show play time
836       return if m.params
837       g.show_time
838     when :tu # show whose turn is it
839       return if m.params
840       if g.has_turn?(m.source)
841         m.nickreply _("it's your turn, sleepyhead")
842       else
843         g.show_turn(:cards => false)
844       end
845     end
846   end
847
848   def create_game(m, p)
849     if @games.key?(m.channel)
850       m.reply _("There is already an %{uno} game running here, say 'jo' to join in") % { :uno => UnoGame::UNO }
851       return
852     end
853     @games[m.channel] = UnoGame.new(self, m.channel)
854     m.reply _("Ok, created %{uno} game on %{channel}, say 'jo' to join in") % {
855       :uno => UnoGame::UNO,
856       :channel => m.channel
857     }
858   end
859
860   def end_game(m, p)
861     unless @games.key?(m.channel)
862       m.reply _("There is no %{uno} game running here") % { :uno => UnoGame::UNO }
863       return
864     end
865     @games[m.channel].end_game(true)
866   end
867
868   def do_end_game(channel)
869     @games.delete(channel)
870   end
871
872   def replace_player(m, p)
873     unless @games.key?(m.channel)
874       m.reply _("There is no %{uno} game running here") % { :uno => UnoGame::UNO }
875       return
876     end
877     @games[m.channel].replace_player(p[:old], p[:new])
878   end
879
880   def drop_player(m, p)
881     unless @games.key?(m.channel)
882       m.reply _("There is no %{uno} game running here") % { :uno => UnoGame::UNO }
883       return
884     end
885     who = p[:nick] ? m.channel.get_user(p[:nick]) : m.source
886     @games[m.channel].drop_player(who)
887   end
888
889   def print_stock(m, p)
890     unless @games.key?(m.channel)
891       m.reply _("There is no %{uno} game running here") % { :uno => UnoGame::UNO }
892       return
893     end
894     stock = @games[m.channel].stock
895     m.reply(_("%{num} cards in stock: %{stock}") % {
896       :num => stock.length,
897       :stock => stock.join(' ')
898     }, :split_at => /#{NormalText}\s*/)
899   end
900 end
901
902 pg = UnoPlugin.new
903
904 pg.map 'uno', :private => false, :action => :create_game
905 pg.map 'uno end', :private => false, :action => :end_game
906 pg.map 'uno drop', :private => false, :action => :drop_player
907 pg.map 'uno giveup', :private => false, :action => :drop_player
908 pg.map 'uno drop :nick', :private => false, :action => :drop_player, :auth_path => ':other'
909 pg.map 'uno replace :old [with] :new', :private => false, :action => :replace_player
910 pg.map 'uno stock', :private => false, :action => :print_stock
911
912 pg.default_auth('stock', false)
913 pg.default_auth('end', false)
914 pg.default_auth('drop::other', false)
915 pg.default_auth('replace', false)