-
Notifications
You must be signed in to change notification settings - Fork 0
/
uno.tcl
2030 lines (1925 loc) · 63 KB
/
uno.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env tclsh
##############################################################################
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the Licence, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Product name : Uno Game for UnrealIRCD Service Framework
# Copyright (C) 2012 Damien Lesgourgues
# Author(s): Damien Lesgourgues
# Based on UNO bot by Marky v0.96
#
##############################################################################
#
# Marky's Uno v0.96
# Copyright (C) 2004 Mark A. Day (techwhiz@earthlink.net)
#
# Uno(tm) is Copyright (C) 2001 Mattel, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
##############################################################################
# TODO
#
# - Cron system for eset of scores every month
# - recode AutoSkipTimer system for nexting a player if it don't play in the
# next 2 minutes
##############################################################################
puts [::msgcat::mc loadgame "UNO"]
# Parametres pour le jeu UNO
namespace eval uno {
variable nick "UNO"
variable username "uno"
variable hostname "uno.$::irc::hostname"
variable realname "Bot de jeu UNO"
variable chan "#UNO"
# Game variables
variable Chan $chan
variable Robot $nick
variable PointsName "Points"
variable StopAfter 5
variable Bonus 1000
variable WildDrawTwos 1
variable CFGFile "files/uno.cfg"
variable ScoreFile "files/UnoScores"
variable MaxNickLen 32
variable MaxPlayers 8
variable NTC "[::tools::tok NOTICE]"
# Global Variables
variable On 0
variable Mode 0
variable Paused 0
variable Players 0
variable MasterDeck ""
variable Deck ""
variable DiscardPile ""
variable PlayCard ""
variable RoundRobin ""
variable ThisPlayer ""
variable ThisPlayerIDX 0
variable StartTime [::tools::unixtime]
variable IsColorChange 0
variable ColorPicker ""
variable IsDraw 0
variable IDX ""
variable UnPlayedRounds 0
# Scores Records And Ads
variable LastMonthCards
variable LastMonthGames
set LastMonthCards(0) "Personne 0"
set LastMonthCards(1) "Personne 0"
set LastMonthCards(2) "Personne 0"
set LastMonthGames(0) "Personne 0"
set LastMonthGames(1) "Personne 0"
set LastMonthGames(2) "Personne 0"
variable Fast "Personne 600"
variable High "Personne 0"
variable Played "Personne 0"
variable RecordHigh "Personne 0"
variable RecordFast "Personne 600"
variable RecordCard "Personne 0"
variable RecordWins "Personne 0"
variable RecordPlayed "Personne 0"
variable AdNumber 0
# Card Stats
variable CardStats
set CardStats(played) 0
set CardStats(passed) 0
set CardStats(drawn) 0
set CardStats(wilds) 0
set CardStats(draws) 0
set CardStats(skips) 0
set CardStats(revs) 0
# Timers
variable StartTimer ""
variable SkipTimer ""
variable CycleTimer ""
variable BotTimer ""
# Grace periods and timeouts
# AutoSkip period can be raised but not lower than 2
variable AutoSkipPeriod 2
variable StartGracePeriod 10
variable RobotRestartPeriod 1
variable CycleTime 30
# Nick colours
variable NickColour "06 13 03 07 12 10 04 11 09 08"
# Debugging info
variable Debug $::debug
variable Version "0.96.74.3"
# Don't modify this
::irc::hook_register privmsg-[string tolower $chan] "::uno::controlpub"
::irc::hook_register privmsg-[string tolower $nick] "::uno::controlpriv"
#::irc::hook_register join-[string tolower $chan] "::uno::controljoin"
::irc::hook_register sync "::uno::controlsync"
namespace import ::tools::tok
}
proc ::uno::controlsync {} { ::irc::bot_init $::uno::nick $::uno::username $::uno::hostname $::uno::realname ; ::irc::join_chan $::uno::nick $::uno::chan }
proc ::uno::controlinit {} { ::irc::hook_register join-[string tolower $chan] "::uno::controljoin" }
proc ::uno::controljoin { nick } { ::irc::send ":$::uno::nick [tok NOTICE] $nick :[::msgcat::mc uno_welcome [::uno::ad]]" }
proc ::uno::controlpriv { nick text } { if {$::debug==1} { ::irc::send ":$::uno::nick [tok PRIVMSG] $::uno::chan :\002PRIV\002 $nick > [join $text]" } }
proc ::uno::controlpub { nick text } {
# nick uhost hand chan arg
#if {$::debug==1} { ::irc::send ":$::uno::nick [tok PRIVMSG] $::uno::chan :\002PUB \002 $nick > [join $text]" }
switch [lindex $text 0] {
!uno-reset { ::uno::Reset; set ::uno::On 0 }
!uno { ::uno::Init $nick "none" "-" $::uno::chan "$text" }
!unocmds { ::uno::Cmds $nick "none" "-" $::uno::chan "$text" }
!remove { ::uno::Remove $nick "none" "-" $::uno::chan "$text" }
!pause { ::uno::Pause $nick "none" "-" $::uno::chan "$text" }
!unowon { ::uno::Won $nick "none" "-" $::uno::chan "$text" }
!unotop10 { ::uno::TopTen $nick "none" "-" $::uno::chan "$text" }
!unotop10won { ::uno::TopTenWon $nick "none" "-" $::uno::chan "$text" }
!unotop3last { ::uno::TopThreeLast $nick "none" "-" $::uno::chan "$text" }
!unofast { ::uno::TopFast $nick "none" "-" $::uno::chan "$text" }
!unohigh { ::uno::HighScore $nick "none" "-" $::uno::chan "$text" }
!unoplayed { ::uno::Played $nick "none" "-" $::uno::chan "$text" }
!unorecords { ::uno::Records $nick "none" "-" $::uno::chan "$text" }
!unoversion { ::uno::Version $nick "none" "-" $::uno::chan "$text" }
!stop { ::uno::Stop $nick "none" "-" $::uno::chan "$text" }
}
if {($::uno::On != 0)&&($::uno::Paused == 0)} {
switch [lindex $text 0] {
join -
jo -
!jo { ::uno::Join $nick "none" "-" $::uno::chan "$text" }
order -
od -
!od { ::uno::Order $nick "none" "-" $::uno::chan "$text" }
time -
ti -
!ti { ::uno::Time $nick "none" "-" $::uno::chan "$text" }
cards -
ca -
!ca { ::uno:ShowCards $nick "none" "-" $::uno::chan "$text" }
play -
pl -
!pl { ::uno::PlayCard $nick "none" "-" $::uno::chan "$text" }
card -
cd -
!cd { ::uno::TopCard $nick "none" "-" $::uno::chan "$text" }
turn -
tu -
!tu { ::uno::Turn $nick "none" "-" $::uno::chan "$text" }
draw -
dr -
!dr { ::uno::Draw $nick "none" "-" $::uno::chan "$text" }
color -
co -
!co { ::uno::ColorChange $nick "none" "-" $::uno::chan "$text" }
pass -
pa -
!pa { ::uno::Pass $nick "none" "-" $::uno::chan "$text" }
count -
ct -
!ct { ::uno::Count $nick "none" "-" $::uno::chan "$text" }
stats -
st -
!st { ::uno::CardStats $nick "none" "-" $::uno::chan "$text" }
}
}
}
#
# Starting game
#
proc ::uno::Init {nick uhost hand chan arg} {
if {$::debug==1} { puts [::msgcat::mc uno_unocmd $nick $chan] }
if {$::uno::On > 0} {
if {$chan != $::uno::Chan} { ::irc::send ":$::uno::nick [tok PRIVMSG] $chan :[::msgcat::mc uno_startalready0 [::uno::ad]]" }
if {$chan == $::uno::Chan} { ::irc::send ":$::uno::nick [tok PRIVMSG] $chan :[::msgcat::mc uno_startalready1 [::uno::ad]]" }
return
}
set ::uno::chan $chan
if {$::debug==1} { puts [::msgcat::mc uno_started $chan] }
::uno::msg "[::uno::ad] \00304\[\00310$nick\00304\]\003"
set ::uno::On 1
::uno::WriteCFG
::uno::Next
return
}
#
# Initialize a new game
#
proc ::uno::Next {} {
if {$::uno::On == 0} {return}
::uno::Reset
set ::uno::Mode 1
set ::uno::MasterDeck [list B0 B1 B1 B2 B2 B3 B3 B4 B4 B5 B5 B6 B6 B7 B7 B8 B8 B9 B9 BR BR BS BS BDT BDT R0 R1 R1 R2 R2 R3 R3 R4 R4 R5 R5 R6 R6 R7 R7 R8 R8 R9 R9 RR RR RS RS RDT RDT Y0 Y1 Y1 Y2 Y2 Y3 Y3 Y4 Y4 Y5 Y5 Y6 Y6 Y7 Y7 Y8 Y8 Y9 Y9 YR YR YS YS YDT YDT G0 G1 G1 G2 G2 G3 G3 G4 G4 G5 G5 G6 G6 G7 G7 G8 G8 G9 G9 GR GR GS GS GDT GDT W W W W WDF WDF WDF WDF]
set ::uno::Deck ""
set ::uno::newrand [expr srand([::tools::unixtime])]
while {[llength $::uno::Deck] != 108} {
set pcardnum [expr {int(rand()*[llength $::uno::MasterDeck])}]
set pcard [lindex $::uno::MasterDeck $pcardnum]
lappend ::uno::Deck $pcard
set ::uno::MasterDeck [lreplace $::uno::MasterDeck $pcardnum $pcardnum]
}
if [info exist ::uno::Hand] {unset ::uno::Hand}
if [info exist ::uno::NickColor] {unset ::uno::NickColor}
::uno::msg [::msgcat::mc uno_pubjoin [::uno::ad] $::uno::StartGracePeriod]
set ::uno::StartTimer [after [expr {int($::uno::StartGracePeriod * 1000)}] ::uno::Start]
if {$::debug==1} { puts "[after info]" }
return
}
#
# Start a new game
#
proc ::uno::Start {} {
if {$::uno::On == 0} {return}
if {[llength $::uno::RoundRobin] == 0} {
::uno::msg [::msgcat::mc uno_noplayers [::uno::ad] $::uno::CycleTime]
incr UnPlayedRounds
if {($::uno::StopAfter > 0)&&($UnPlayedRounds >= $::uno::StopAfter)} {
::uno::msg [::msgcat::mc uno_stopnoplayers [::uno::ad] $::uno::StopAfter]
set ::uno::On 0
after 1000 "::uno::Stop $::uno::Robot $::uno::Robot none $::uno::Chan none"
return
}
::uno::Cycle
return
}
# Bot Joins If One Player
if {[llength $::uno::RoundRobin] == 1} {
incr ::uno::Players
lappend ::uno::RoundRobin "$::uno::Robot"
lappend ::uno::IDX "$::uno::Robot"
if [info exist ::uno::Hand($::uno::Robot)] {unset ::uno::Hand($::uno::Robot)}
if [info exist ::uno::NickColor($::uno::Robot)] {unset ::uno::NickColor($::uno::Robot)}
set ::uno::Hand($::uno::Robot) ""
set ::uno::NickColor($::uno::Robot) [::uno::colornick $::uno::Players]
::uno::msg [::msgcat::mc uno_join0 [::uno::nikclr $::uno::Robot] [::uno::ad]]
if {$::debug==1} { puts [::msgcat::mc uno_join1 $::uno::Robot] }
::uno::Shuffle 7
while {[llength $::uno::Hand($::uno::Robot)] != 7} {
set pcardnum [expr {int(rand() * [llength $::uno::Deck])}]
set pcard [lindex $::uno::Deck $pcardnum]
set ::uno::Deck [lreplace ${::uno::Deck} $pcardnum $pcardnum]
lappend ::uno::Hand($::uno::Robot) "$pcard"
}
if {$::debug > 1} { ::uno::log $::uno::Robot $::uno::Hand($::uno::Robot) }
}
::uno::msg [::msgcat::mc uno_welcome0 [::uno::ad]]
::uno::msg [::msgcat::mc uno_welcome1 $::uno::Players $::uno::RoundRobin]
set ::uno::Mode 2
set ::uno::ThisPlayer [lindex $::uno::RoundRobin 0]
# Draw Card From Deck - First Top Card
set ::uno::DiscardPile ""
set pcardnum [expr {int(rand() * [llength $::uno::Deck])}]
set pcard [lindex $::uno::Deck $pcardnum]
# Play Doesnt Start With A Wild Card
while {[string range $pcard 0 0] == "W"} {
set pcardnum [expr {int(rand() * [llength $::uno::Deck])}]
set pcard [lindex $::uno::Deck $pcardnum]
}
set ::uno::PlayCard $pcard
set ::uno::Deck [lreplace ${::uno::Deck} $pcardnum $pcardnum]
set Card [::uno::CardColor $pcard]
::uno::msg [::msgcat::mc uno_start [::uno::nikclr $::uno::ThisPlayer] $Card]
set Card [::uno::CardColorAll $::uno::ThisPlayer]
::uno::showcards $::uno::ThisPlayerIDX $Card
set ::uno::StartTime [::tools::unixtime]
# Start Auto-Skip Timer
### set ::uno::SkipTimer [after [expr {int($::uno::AutoSkipPeriod*1000*60)}] ::uno::AutoSkip]
set ::uno::UnPlayedRounds 0
return
}
#
# Stop a game
#
proc ::uno::Stop {nick uhost hand chan arg} {
if {$chan != $::uno::Chan} {return}
catch {after cancel $::uno::StartTimer}
### catch {after cancel $::uno::SkipTimer}
catch {after cancel $::uno::CycleTimer}
::uno::msg [::msgcat::mc uno_stop0 [::uno::ad] $nick]
if {$::debug==1} { puts [::msgcat::mc uno_stop1 $nick $chan] }
set ::uno::On 0
set ::uno::Paused 0
set ::uno::UnPlayedRounds 0
::uno::Reset
return
}
#
# Cycle a new game
#
proc ::uno::Cycle {} {
if {$::uno::On == 0} {return}
set ::uno::Mode 4
### catch {after cancel $::uno::SkipTimer}
set ::uno::AdTime [expr $::uno::CycleTime /2]
set ::uno::AdTimer [after [expr {int($::uno::AdTime*1000)}] ::uno::ScoreAdvertise]
set ::uno::CycleTimer [after [expr {int($::uno::CycleTime*1000)}] ::uno::Next]
return
}
#
# Add a player
#
proc ::uno::Join {nick uhost hand chan arg} {
if {($chan != $::uno::Chan)||($::uno::Mode < 1)||($::uno::Mode > 2)} {return}
if {[llength $::uno::RoundRobin] == $::uno::MaxPlayers} {
::uno::ntc $nick [::msgcat::mc uno_maxplayers $nick]
return
}
set pcount 0
while {[lindex $::uno::RoundRobin $pcount] != ""} {
if {[lindex $::uno::RoundRobin $pcount] == $nick} {
return
}
incr pcount
}
incr ::uno::Players
lappend ::uno::RoundRobin $nick
lappend ::uno::IDX $nick
if [info exist ::uno::Hand($nick)] {unset ::uno::Hand($nick)}
if [info exist ::uno::NickColor($nick)] {unset ::uno::NickColor($nick)}
set ::uno::Hand($nick) ""
set ::uno::NickColor($nick) [colornick $::uno::Players]
# Re-Shuffle Deck
::uno::Shuffle 7
# Deal Cards To Player
set Card ""
while {[llength $::uno::Hand($nick)] != 7} {
set pcardnum [expr {int(rand() * [llength $::uno::Deck])}]
set pcard [lindex $::uno::Deck $pcardnum]
set ::uno:Deck [lreplace ${::uno::Deck} $pcardnum $pcardnum]
lappend ::uno::Hand($nick) $pcard
append Card [::uno::CardColor $pcard]
}
if {$::debug > 1} { ::uno::log $nick $::uno::Hand($nick) }
::uno::msg [::msgcat::mc uno_pljoin0 [::uno::nikclr $nick] [::uno::ad]]
puts [::msgcat::mc uno_pljoin1 $nick]
::uno::ntc $nick [::msgcat::mc uno_inhand $Card]
return
}
#
# Reset Game Variables
#
proc ::uno::Reset {} {
set ::uno::Mode 0
set ::uno::Paused 0
set ::uno::Players 0
set ::uno::MasterDeck ""
set ::uno::Deck ""
set ::uno::DiscardPile ""
set ::uno::RoundRobin ""
set ::uno::ThisPlayer ""
set ::uno::ThisPlayerIDX 0
set ::uno::PlayCard ""
set ::uno::IsColorChange 0
set ::uno::ColorPicker ""
set ::uno::IsDraw 0
set ::uno::IDX ""
set ::uno::AdNumber 0
set ::uno::CardStats(played) 0
set ::uno::CardStats(passed) 0
set ::uno::CardStats(drawn) 0
set ::uno::CardStats(wilds) 0
set ::uno::CardStats(draws) 0
set ::uno::CardStats(skips) 0
set ::uno::CardStats(revs) 0
set ::uno::StartTimer ""
set ::uno::SkipTimer ""
set ::uno::CycleTimer ""
return
}
#
# Add card(s) to players hand
#
proc ::uno::AddDrawToHand {cplayer idx num} {
# Check if deck needs reshuffling
::uno::Shuffle $num
set Card ""
set newhand [expr [llength $::uno::Hand($cplayer)] + $num]
while {[llength $::uno::Hand($cplayer)] != $newhand} {
set pcardnum [expr {int(rand() * [llength $::uno::Deck])}]
set pcard [lindex $::uno::Deck $pcardnum]
set ::uno::Deck [lreplace ${::uno::Deck} $pcardnum $pcardnum]
lappend ::uno::Hand($cplayer) $pcard
append Card [::uno::CardColor $pcard]
}
::uno::showdraw $idx $Card
incr ::uno::CardStats(drawn) $num
}
#
# Remove played card from player's hand
#
proc ::uno::RemoveCardFromHand {cplayer pcard} {
set ::uno::Hand($cplayer) [lreplace $::uno::Hand($cplayer) $pcard $pcard]
}
#
# Add card to discard pile
#
proc ::uno::AddToDiscardPile {playcard} {
if {[string range $playcard 1 1] != ""} {
lappend ::uno::DiscardPile $playcard
}
}
#
# Draw a card
#
proc ::uno::Draw {nick uhost hand chan arg} {
if {($chan != $::uno::Chan)||($::uno::Mode != 2)||($nick != $::uno::ThisPlayer)} {return}
if {$::uno::IsDraw == 0} {
set ::uno::IsDraw 1
::uno::Shuffle 1
set dcardnum [expr {int(rand() * [llength $::uno::Deck])}]
set dcard [lindex $::uno::Deck $dcardnum]
lappend ::uno::Hand($nick) $dcard
set ::uno::Deck [lreplace ${::uno::Deck} $dcardnum $dcardnum]
append Card [::uno::CardColor $dcard]
::uno::showdraw $::uno::ThisPlayerIDX $Card
::uno::showwhodrew $nick
incr ::uno::CardStats(drawn)
::uno::AutoSkipReset
return
}
::uno::ntc $nick [::msgcat::mc uno_alreadypick]
::uno::AutoSkipReset
return
}
#
# Pass a turn
#
proc ::uno::Pass {nick uhost hand chan arg} {
if {($chan != $::uno::Chan)||($::uno::Mode != 2)} {return}
if {($nick != $::uno::ThisPlayer)||($::uno::IsColorChange == 1)} {return}
::uno::AutoSkipReset
if {$::uno::IsDraw == 1} {
incr ::uno::CardStats(passed)
set ::uno::IsDraw 0
::uno::NextPlayer
::uno::playpass $nick $::uno::ThisPlayer
set Card [::uno::CardColorAll $::uno::ThisPlayer]
::uno::showcards $::uno::ThisPlayerIDX $Card
::uno::RobotRestart
} {
::uno::ntc $nick [::msgcat::mc uno_pickbeforepass $nick]
}
return
}
#
# Color change
#
proc ::uno::ColorChange {nick uhost hand chan arg} {
if {($chan != $::uno::Chan)||($::uno::Mode != 2)} {return}
if {($nick != $::uno::ColorPicker)||($::uno::IsColorChange == 0)} {return}
::uno::AutoSkipReset
regsub -all \[`.,!{}\ ] $arg "" arg
set NewColor [string toupper [string range $arg 2 2]]
if {$::debug == 1} {
puts "arg : $arg"
puts "Asked Color : $NewColor"
}
switch $NewColor {
"B" { set ::uno::PlayCard "B"; set Card " \00300,12 [::msgcat::mc uno_blue] \003 "}
"G" { set ::uno::PlayCard "G"; set Card " \00300,03 [::msgcat::mc uno_green] \003 "}
"Y" { set ::uno::PlayCard "Y"; set Card " \00301,08 [::msgcat::mc uno_yellow] \003 "}
"R" { set ::uno::PlayCard "R"; set Card " \00300,04 [::msgcat::mc uno_red] \003 "}
default { ::uno::ntc $nick [::msgcat::mc uno_selectcolor]; return }
}
::uno::NextPlayer
::uno::msg [::msgcat::mc uno_selectedcolor [::uno::nikclr $::uno::ColorPicker] $Card [::uno::nikclr $::uno::ThisPlayer]]
set Card [::uno::CardColorAll $::uno::ThisPlayer]
::uno::showcards $::uno::ThisPlayerIDX $Card
set ::uno::ColorPicker ""
set ::uno::IsColorChange 0
set ::uno::IsDraw 0
::uno::RobotRestart
return
}
#
# Skip card
#
proc ::uno::PlayUnoSkipCard {nick pickednum crd} {
set c0 [string range $crd 0 0]
set c1 [string range $crd 1 1]
set cip0 [string range $::uno::PlayCard 0 0]
set cip1 [string range $::uno::PlayCard 1 1]
if {$c1 != "S"} {return 0}
if {($c0 != $cip0)&&($c1 != $cip1)} {return 0}
incr ::uno::CardStats(played)
incr ::uno::CardStats(skips)
::uno::AddToDiscardPile $::uno::PlayCard
::uno::RemoveCardFromHand $nick $pickednum
set ::uno::PlayCard $crd
set Card [::uno::CardColor $crd]
set SkipPlayer $::uno::ThisPlayer
::uno::NextPlayer
set SkippedPlayer [lindex $::uno::RoundRobin $::uno::ThisPlayerIDX]
::uno::NextPlayer
# No Cards Left = Winner
if {[::uno::check_unowin $SkipPlayer $Card] > 0} {
::uno::showwin $SkipPlayer $Card
::uno::Win $SkipPlayer
::uno::Cycle
return 1
}
::uno::playskip $nick $Card $SkippedPlayer $::uno::ThisPlayer
::uno::check_hasuno $SkipPlayer
set Card [::uno::CardColorAll $::uno::ThisPlayer]
::uno::showcards $::uno::ThisPlayerIDX $Card
set ::uno::IsDraw 0
return 1
}
#
# Reverse card
#
proc ::uno::PlayUnoReverseCard {nick pickednum crd} {
set c0 [string range $crd 0 0]
set c1 [string range $crd 1 1]
set cip0 [string range $::uno::PlayCard 0 0]
set cip1 [string range $::uno::PlayCard 1 1]
if {$c1 != "R"} {return 0}
if {($c0 != $cip0)&&($c1 != $cip1)} {return 0}
incr ::uno::CardStats(played)
incr ::uno::CardStats(revs)
::uno::AddToDiscardPile $::uno::PlayCard
::uno::RemoveCardFromHand $nick $pickednum
set ::uno::PlayCard $crd
set Card [::uno::CardColor $crd]
# Reverse RoundRobin and Move To Next Player
set NewRoundRobin ""
set OrigOrderLength [llength $::uno::RoundRobin]
set IDX $OrigOrderLength
while {$OrigOrderLength != [llength $NewRoundRobin]} {
set IDX [expr ($IDX - 1)]
lappend NewRoundRobin [lindex $::uno::RoundRobin $IDX]
}
set Newindexorder ""
set OrigindexLength [llength $::uno::IDX]
set IDX $OrigindexLength
while {$OrigindexLength != [llength $Newindexorder]} {
set IDX [expr ($IDX - 1)]
lappend Newindexorder [lindex $::uno::IDX $IDX]
}
set ::uno::IDX $Newindexorder
set ::uno::RoundRobin $NewRoundRobin
set ReversePlayer $::uno::ThisPlayer
# Next Player After Reversing RoundRobin
set pcount 0
while {$pcount != [llength $::uno::RoundRobin]} {
if {[lindex $::uno::RoundRobin $pcount] == $::uno::ThisPlayer} {
set ::uno::ThisPlayerIDX $pcount
break
}
incr pcount
}
# <3 Players Act Like A Skip Card
if {[llength $::uno::RoundRobin] > 2} {
incr ::uno::ThisPlayerIDX
if {$::uno::ThisPlayerIDX >= [llength $::uno::RoundRobin]} {set ::uno::ThisPlayerIDX 0}
}
set ::uno::ThisPlayer [lindex $::uno::RoundRobin $::uno::ThisPlayerIDX]
# No Cards Left = Winner
if {[::uno::check_unowin $ReversePlayer $Card] > 0} {
::uno::showwin $ReversePlayer $Card
::uno::Win $ReversePlayer
::uno::Cycle
return 1
}
::uno::playcard $nick $Card $::uno::ThisPlayer
::uno::check_hasuno $ReversePlayer
set Card [::uno::CardColorAll $::uno::ThisPlayer]
::uno::showcards $::uno::ThisPlayerIDX $Card
set ::uno::IsDraw 0
return 1
}
#
# Draw Two card
#
proc ::uno::PlayUnoDrawTwoCard {nick pickednum crd} {
set CardOk 0
set c0 [string range $crd 0 0]
set c2 [string range $crd 2 2]
set cip0 [string range $::uno::PlayCard 0 0]
set cip1 [string range $::uno::PlayCard 1 1]
set cip2 [string range $::uno::PlayCard 2 2]
if {$c2 != "T"} {return 0}
if {$c0 == $cip0} {set CardOk 1}
if {$cip2 == "T"} {set CardOk 1}
if {$::uno::WildDrawTwos != 0} {
if {($cip1 != "")&&($cip2 != "F")} {set CardOk 1}
}
if {$CardOk == 1} {
incr ::uno::CardStats(draws)
incr ::uno::CardStats(played)
::uno::AddToDiscardPile $::uno::PlayCard
::uno::RemoveCardFromHand $nick $pickednum
set ::uno::PlayCard $crd
set Card [CardColor $crd]
set DrawPlayer $::uno::ThisPlayer
set DrawPlayerIDX $::uno::ThisPlayerIDX
# Move to the player that draws
::uno::NextPlayer
set PlayerThatDrew $::uno::ThisPlayer
set PlayerThatDrewIDX $::uno::ThisPlayerIDX
# Move To The Next Player
::uno::NextPlayer
if {[::uno::check_unowin $nick $Card] > 0} {
::uno::AddDrawToHand $PlayerThatDrew $PlayerThatDrewIDX 2
::uno::showwin $nick $Card
::uno::Win $nick
::uno::Cycle
return 1
}
::uno::playdraw $nick $Card $PlayerThatDrew $::uno::ThisPlayer
::uno::AddDrawToHand $PlayerThatDrew $PlayerThatDrewIDX 2
::uno::check_hasuno $nick
set Card [::uno::CardColorAll $::uno::ThisPlayer]
::uno::showcards $::uno::ThisPlayerIDX $Card
set ::uno::IsDraw 0
return 1
}
return 0
}
#
# Wild Draw Four card
#
proc ::uno::PlayUnoWildDrawFourCard {nick pickednum crd isrobot} {
if {[string range $crd 2 2] != "F"} {return 0}
incr ::uno::CardStats(wilds)
incr ::uno::CardStats(played)
set ::uno::ColorPicker $::uno::ThisPlayer
::uno::AddToDiscardPile $::uno::PlayCard
::uno::RemoveCardFromHand $nick $pickednum
set ::uno::PlayCard $crd
set Card [::uno::CardColor $crd]
# move to the player that draws
::uno::NextPlayer
set PlayerThatDrew $::uno::ThisPlayer
set PlayerThatDrewIDX $::uno::ThisPlayerIDX
if {$isrobot > 0} {
# choose color and move to next player
set cip [::uno::BotPickAColor]
::uno::NextPlayer
}
if {[::uno::check_unowin $nick $Card] > 0} {
::uno::AddDrawToHand $PlayerThatDrew $PlayerThatDrewIDX 4
::uno::showwin $nick $Card
::uno::Win $nick
::uno::Cycle
return 1
}
if {$isrobot > 0} {
::uno::botplaywildfour $::uno::ColorPicker $PlayerThatDrew $::uno::ColorPicker $cip $::uno::ThisPlayer
set ::uno::ColorPicker ""
set ::uno::IsColorChange 0
} {
::uno::playwildfour $nick $PlayerThatDrew $::uno::ColorPicker
set ::uno::IsColorChange 1
}
::uno::AddDrawToHand $PlayerThatDrew $PlayerThatDrewIDX 4
::uno::check_hasuno $nick
if {$isrobot > 0} {
set Card [::uno::CardColorAll $::uno::ThisPlayer]
::uno::showcards $::uno::ThisPlayerIDX $Card
}
set ::uno::IsDraw 0
return 1
}
#
# Wild card
#
proc ::uno::PlayUnoWildCard {nick pickednum crd isrobot} {
if {[string range $crd 0 0] != "W"} {return 0}
incr ::uno::CardStats(wilds)
incr ::uno::CardStats(played)
set ::uno::ColorPicker $::uno::ThisPlayer
::uno::AddToDiscardPile $::uno::PlayCard
::uno::RemoveCardFromHand $nick $pickednum
set ::uno::PlayCard $crd
set Card [::uno::CardColor $crd]
# Ok to remove this?
#set ::uno::ThisPlayer [lindex $::uno::RoundRobin $::uno::ThisPlayerIDX]
#set DrawnPlayer $::uno::ThisPlayer
if {$isrobot > 0} {
# Make A Color Choice
set cip [::uno::BotPickAColor]
::uno::NextPlayer
}
# No Cards Left = Winner
if {[check_unowin $nick $Card] > 0} {
::uno::showwin $nick $Card
::uno::Win $nick
::uno::Cycle
return 1
}
if {$isrobot > 0} {
::uno::botplaywild $nick $::uno::ColorPicker $cip $::uno::ThisPlayer
set ::uno::ColorPicker ""
set Card [::uno::CardColorAll $::uno::ThisPlayer]
::uno::showcards $::uno::ThisPlayerIDX $Card
set ::uno::IsColorChange 0
} {
::uno::playwild $nick $::uno::ColorPicker
set ::uno::IsColorChange 1
}
::uno::check_hasuno $nick
set ::uno::IsDraw 0
return 1
}
#
# Number card
#
proc ::uno::PlayUnoNumberCard {nick pickednum crd} {
set CardOk 0
set c1 [string range $crd 0 0]
set c2 [string range $crd 1 1]
set cip1 [string range $::uno::PlayCard 0 0]
set cip2 [string range $::uno::PlayCard 1 1]
if {$c2 == -1} {return 0}
if {$c1 == $cip1} {set CardOk 1}
if {($cip2 != "")} {
if {$c2 == $cip2} {set CardOk 1}
}
if {$CardOk == 1} {
incr ::uno::CardStats(played)
::uno::AddToDiscardPile $::uno::PlayCard
::uno::RemoveCardFromHand $nick $pickednum
set ::uno::PlayCard $crd
set Card [::uno::CardColor $crd]
set NumberCardPlayer $::uno::ThisPlayer
::uno::NextPlayer
if {[::uno::check_unowin $NumberCardPlayer $Card] > 0} {
::uno::showwin $NumberCardPlayer $Card
::uno::Win $NumberCardPlayer
::uno::Cycle
return 1
}
::uno::playcard $nick $Card $::uno::ThisPlayer
::uno::check_hasuno $NumberCardPlayer
set Card [::uno::CardColorAll $::uno::ThisPlayer]
::uno::showcards $::uno::ThisPlayerIDX $Card
set ::uno::IsDraw 0
return 1
}
::uno::ntc $nick [::msgcat::mc uno_invalidcard]
return 0
}
#
# Attempt to find card in hand
#
proc ::uno::FindCard {nick pickednum crd IsRobot} {
if {$::debug > 1} {::uno::log $::uno::Robot "UnoFindCard: [lindex $::uno::Hand($::uno::ThisPlayer) $pickednum"}
# Wild Draw Four
set FoundCard [::uno::PlayUnoWildDrawFourCard $nick $pickednum $crd $IsRobot]
if {$FoundCard == 1} {return 4}
# Wild
set FoundCard [::uno::PlayUnoWildCard $nick $pickednum $crd $IsRobot]
if {$FoundCard == 1} {return 5}
# Draw Two
set FoundCard [::uno::PlayUnoDrawTwoCard $nick $pickednum $crd]
if {$FoundCard == 1} {return 3}
# Skip
set FoundCard [::uno::PlayUnoSkipCard $nick $pickednum $crd]
if {$FoundCard == 1} {return 1}
# Reverse
set FoundCard [::uno::PlayUnoReverseCard $nick $pickednum $crd]
if {$FoundCard == 1} {return 2}
# Number card
set FoundCard [::uno::PlayUnoNumberCard $nick $pickednum $crd]
if {$FoundCard == 1} {return 6}
return 0
}
#
# Play a card
#
proc ::uno::PlayCard {nick uhost hand chan arg} {
if {($chan != $::uno::Chan)||($::uno::Mode != 2)||($nick != $::uno::ThisPlayer)} {return}
::uno::AutoSkipReset
if {$::uno::IsColorChange == 1} {return}
regsub -all \[`,.!{}\ ] $arg "" arg
if {$arg == ""} {return}
set pcard [string toupper [string range $arg 2 end]]
set CardInPlayerHand 0
set pcount 0
if {$::debug==1} {
puts "arg : $arg"
puts "Player hand : $::uno::Hand($nick)"
puts "Asked card : $pcard"
}
while {[lindex $::uno::Hand($nick) $pcount] != ""} {
if {$pcard == [lindex $::uno::Hand($nick) $pcount]} {
set pcardnum $pcount
set CardInPlayerHand 1
break
}
incr pcount
}
if {$CardInPlayerHand == 0} {
::uno::ntc $nick [::msgcat::mc uno_notinhand]
return
}
set CardFound [::uno::FindCard $nick $pcardnum $pcard 0]
switch $CardFound {
0 {return}
4 {return}
5 {return}
default {::uno::RobotRestart; return}
}
}
#
# Robot Player
#
proc ::uno::RobotPlayer {} {
# Check for a valid card in hand
set CardOk 0
set IsDraw 0
set CardCount 0
set cip1 [string range $::uno::PlayCard 0 0]
set cip2 [string range $::uno::PlayCard 1 1]
while {$CardCount < [llength $::uno::Hand($::uno::ThisPlayer)]} {
set playcard [lindex $::uno::Hand($::uno::ThisPlayer) $CardCount]
set c1 [string range $playcard 0 0]
set c2 [string range $playcard 1 1]
if {$::debug > 1} {::uno::log $::uno::Robot "Trying: $playcard"}
if {($c1 == $cip1)||($c2 == $cip2)||($c1 == "W")} {
set CardOk 1
set pcard $playcard
set pcardnum $CardCount
break
}
incr CardCount
}
# Play the card if found
if {$CardOk == 1} {
set CardFound [::uno::FindCard $::uno::Robot $pcardnum $pcard 1]
switch $CardFound {
0 {}
5 {return}
6 {return}
default {::uno::RobotRestart; return}
}
}
# Bot draws a card
::uno::Shuffle 1
set dcardnum [expr {int(rand() * [llength $::uno::Deck])}]
set dcard [lindex $::uno::Deck $dcardnum]
lappend ::uno::Hand($::uno::Robot) "$dcard"
set ::uno::Deck [lreplace ${::uno::Deck} $dcardnum $dcardnum]
::uno::showwhodrew $::uno::Robot
set CardOk 0
set CardCount 0
incr ::uno::CardStats(drawn)
while {$CardCount < [llength $::uno::Hand($::uno::ThisPlayer)]} {
set playcard [lindex $::uno::Hand($::uno::ThisPlayer) $CardCount]
set c1 [string range $playcard 0 0]
set c2 [string range $playcard 1 1]
if {$::debug > 1} {::uno::log $::uno::Robot "DrawTry: $playcard"}
if {($c1 == $cip1)||($c2 == $cip2)||($c1 == "W")} {
set CardOk 1
set pcard $playcard
set pcardnum $CardCount
break
}
incr CardCount
}
# Bot plays drawn card or passes turn
if {$CardOk == 1} {
set CardFound [::uno::FindCard $::uno::Robot $pcardnum $pcard 1]
if {$CardFound == 1} {::uno::RobotRestart; return}
switch $CardFound {
0 {}
5 {return}
6 {return}
default {::uno::RobotRestart; return}
}
} {
incr ::uno::CardStats(passed)
set ::uno::IsDraw 0
::uno::NextPlayer
::uno::playpass $::uno::Robot $::uno::ThisPlayer
set Card [::uno::CardColorAll $::uno::ThisPlayer]
::uno::showcards $::uno::ThisPlayerIDX $Card
}
return
}
#
# Pause play
#
proc ::uno::Pause {nick uhost hand chan arg} {
if {$chan != $::uno::Chan} {return}
if {$::uno::On != 1} {return}
if {$::uno::Mode != 2} {return}
if {[is_admin $nick]} {
if {$::uno::Paused == 0} {
set ::uno::Paused 1
::uno::msg [::msgcat::mc uno_pauseon [::uno::ad] $nick]
} {
set ::uno::Paused 0
::uno::AutoSkipReset
::uno::msg [::msgcat::mc uno_pauseoff [::uno::ad] $nick]
}
}
}
#
# Remove user from play
#
proc ::uno::Remove {nick uhost hand chan arg} {
if {$chan != $::uno::Chan} {return}
if {$::uno::On == 0} {return}
regsub -all \[`,.!{}] $arg "" arg
# Allow Ops To Remove Another Player
set UnoOpRemove 0
if {[string length $arg] > 0} {
if {[is_admin $nick]} {
set UnoOpRemove 1
set UnoOpNick $nick
set nick $arg
} {
return
}