Skip to content

Commit fdb495c

Browse files
author
linyisonger
committed
没思路....
1 parent 8cf39ec commit fdb495c

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

093.七王五二三-人机对战.html

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,33 @@
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;
@@ -118,6 +145,41 @@
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
@@ -159,6 +221,9 @@
159221
let startPlayIdx = playIdx; // 先出牌的玩家索引
160222
let passPlayerCount = 0; // 过牌玩家数量
161223
let round = new Round();
224+
let min
225+
226+
162227
// while (true) {
163228
//
164229

examples.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,6 @@
9090
090.火柴人生成器.html
9191
091.中国象棋.html
9292
092.中国象棋-暗棋模式.html
93+
093.七王五二三-人机对战.html
9394
blog.html
9495
index.html

0 commit comments

Comments
 (0)