fix: 炸弹比较先比张数再比牌值
This commit is contained in:
@@ -256,6 +256,12 @@ func (cl *CardLogic) CanPlay(cards []models.Card, lastPlay *models.PlayRecord) b
|
||||
|
||||
if cardType == models.CardTypeBomb {
|
||||
if lastPlay.CardType == models.CardTypeBomb {
|
||||
// 先比张数,张数多的赢;张数相同再比牌值
|
||||
myCount := cl.getBombCount(cards)
|
||||
lastCount := cl.getBombCount(lastPlay.Cards)
|
||||
if myCount != lastCount {
|
||||
return myCount > lastCount
|
||||
}
|
||||
return cl.getMainValue(cards) > cl.getMainValue(lastPlay.Cards)
|
||||
}
|
||||
if lastPlay.CardType == models.CardTypeRocket {
|
||||
@@ -310,6 +316,17 @@ func (cl *CardLogic) getMainValue(cards []models.Card) int {
|
||||
}
|
||||
}
|
||||
return maxValue
|
||||
return maxValue
|
||||
}
|
||||
|
||||
func (cl *CardLogic) getBombCount(cards []models.Card) int {
|
||||
counts := cl.getValueCounts(cards)
|
||||
for _, c := range counts {
|
||||
if c >= 3 {
|
||||
return c
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type GameManager struct {
|
||||
|
||||
@@ -514,9 +514,14 @@ function canPlay(cards, lastPlay) {
|
||||
if (cardType === 9) return true;
|
||||
if (cardType === 8) {
|
||||
if (lastPlay.cardType === 8) {
|
||||
var myMain = 0, lastMain = 0;
|
||||
// 先比张数,张数多的赢;张数相同再比牌值
|
||||
var myCounts = getValueCounts(cards);
|
||||
var lastCounts = getValueCounts(lastPlay.cards);
|
||||
var myCount = 0, lastCount = 0;
|
||||
for (var k in myCounts) { if (myCounts[k] >= 3) myCount = myCounts[k]; }
|
||||
for (var k in lastCounts) { if (lastCounts[k] >= 3) lastCount = lastCounts[k]; }
|
||||
if (myCount !== lastCount) return myCount > lastCount;
|
||||
var myMain = 0, lastMain = 0;
|
||||
for (var k in myCounts) { if (myCounts[k] >= 3 && parseInt(k) > myMain) myMain = parseInt(k); }
|
||||
for (var k in lastCounts) { if (lastCounts[k] >= 3 && parseInt(k) > lastMain) lastMain = parseInt(k); }
|
||||
return myMain > lastMain;
|
||||
|
||||
Reference in New Issue
Block a user