File tree Expand file tree Collapse file tree 2 files changed +66
-0
lines changed
Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Original file line number Diff line number Diff line change 5959 SPADE : '黑桃'
6060 }
6161
62+ // 7>大王>小王>5>2>3>A>K>Q>J>10>9>8>6>4
63+ const TYPE_LEVEL = {
64+ [ CARD_TYPE [ 4 ] ] : 1 ,
65+ [ CARD_TYPE [ 6 ] ] : 2 ,
66+ [ CARD_TYPE [ 8 ] ] : 3 ,
67+ [ CARD_TYPE [ 9 ] ] : 4 ,
68+ [ CARD_TYPE [ 10 ] ] : 5 ,
69+ [ CARD_TYPE . J ] : 6 ,
70+ [ CARD_TYPE . Q ] : 7 ,
71+ [ CARD_TYPE . K ] : 8 ,
72+ [ CARD_TYPE . A ] : 9 ,
73+ [ CARD_TYPE [ 3 ] ] : 10 ,
74+ [ CARD_TYPE [ 2 ] ] : 11 ,
75+ [ CARD_TYPE [ 5 ] ] : 12 ,
76+ [ CARD_TYPE . LITTLE_JOKER ] : 13 ,
77+ [ CARD_TYPE . BIG_JOKER ] : 14 ,
78+ [ CARD_TYPE [ 7 ] ] : 15 ,
79+ }
80+
81+ // 黑桃>红桃>梅花>方块
82+ const SUITS_LEVEL = {
83+ [ CARD_SUITS . DIAMOND ] : 1 ,
84+ [ CARD_SUITS . CLUB ] : 2 ,
85+ [ CARD_SUITS . HEART ] : 3 ,
86+ [ CARD_SUITS . SPADE ] : 4
87+ }
88+
6289 class Card {
6390 constructor ( type = '' , suits = '' ) {
6491 this . type = type ;
118145 }
119146
120147
148+ /**
149+ * 卡牌对比
150+ * A < B True
151+ * A > B Fasle
152+ *
153+ * @author linyisonger
154+ * @date 2025-03-04
155+ * @param {Card } cardA
156+ * @param {Card } cardB
157+ */
158+ function cardComparison ( cardA , cardB ) {
159+ if ( TYPE_LEVEL [ cardA . type ] < TYPE_LEVEL [ cardB . type ] ) return true ;
160+ if ( TYPE_LEVEL [ cardA . type ] > TYPE_LEVEL [ cardB . type ] ) return false ;
161+ if ( SUITS_LEVEL [ cardA . suits ] > SUITS_LEVEL [ cardB . suits ] ) return true ;
162+ return false ;
163+ }
164+
165+
166+ /**
167+ * 最小卡牌
168+ * @author linyisonger
169+ * @date 2025-03-04
170+ * @param {Card[] } cards
171+ */
172+ function minCard ( cards ) {
173+ if ( cards . length == 1 ) return cards [ 0 ]
174+ let min = cards [ 0 ]
175+ for ( let i = 1 ; i < cards . length ; i ++ ) {
176+ const card = cards [ i ] ;
177+ if ( ! cardComparison ( min , card ) ) min = card
178+ }
179+ return min
180+ }
181+
182+
121183 /**
122184 * 开始游戏
123185 * @author linyisonger
159221 let startPlayIdx = playIdx ; // 先出牌的玩家索引
160222 let passPlayerCount = 0 ; // 过牌玩家数量
161223 let round = new Round ( ) ;
224+ let min
225+
226+
162227 // while (true) {
163228 //
164229
Original file line number Diff line number Diff line change 9090090.火柴人生成器.html
9191091.中国象棋.html
9292092.中国象棋-暗棋模式.html
93+ 093.七王五二三-人机对战.html
9394blog.html
9495index.html
You can’t perform that action at this time.
0 commit comments