feat: smarter bot
This commit is contained in:
+4
-31
@@ -333,50 +333,23 @@ func (r *Room) autoMove(seat int) {
|
||||
}
|
||||
}
|
||||
|
||||
// autoChooseTrump خالی را انتخاب میکند که بازیکن بیشترین کارت از آن را دارد.
|
||||
// autoChooseTrump حکم را با راهبردِ باتِ هوشمند (طول + قدرتِ خال) انتخاب میکند.
|
||||
func (r *Room) autoChooseTrump(seat int) {
|
||||
hand := r.game.Hand(seat)
|
||||
if len(hand) == 0 {
|
||||
return
|
||||
}
|
||||
var counts [4]int
|
||||
for _, c := range hand {
|
||||
counts[c.Suit]++
|
||||
}
|
||||
best, bestN := hand[0].Suit, -1
|
||||
for s := game.Suit(0); s < 4; s++ {
|
||||
if counts[s] > bestN {
|
||||
bestN, best = counts[s], s
|
||||
}
|
||||
}
|
||||
_ = r.game.ChooseTrump(seat, best)
|
||||
_ = r.game.ChooseTrump(seat, botChooseTrump(hand))
|
||||
r.graceUntil = time.Now().Add(r.dealDelay) // انیمیشنِ پخشِ بقیهی کارتها
|
||||
}
|
||||
|
||||
// autoPlayCard یک کارت مجاز (پایینترین کارتِ خالِ زمینه، وگرنه پایینترین کارت) بازی میکند.
|
||||
// autoPlayCard با هوشِ باتِ اکتشافی یک کارتِ مجاز و راهبردی بازی میکند.
|
||||
func (r *Room) autoPlayCard(seat int) {
|
||||
hand := r.game.Hand(seat)
|
||||
if len(hand) == 0 {
|
||||
return
|
||||
}
|
||||
var choice game.Card
|
||||
found := false
|
||||
if len(r.game.Trick) > 0 { // خالِ زمینه تعیین شده
|
||||
lead := r.game.LeadSuit
|
||||
for _, c := range hand {
|
||||
if c.Suit == lead && (!found || c.Rank < choice.Rank) {
|
||||
choice, found = c, true
|
||||
}
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
choice = hand[0]
|
||||
for _, c := range hand {
|
||||
if c.Rank < choice.Rank {
|
||||
choice = c
|
||||
}
|
||||
}
|
||||
}
|
||||
choice := botPlay(hand, r.game.Trick, r.game.Trump, r.game.LeadSuit)
|
||||
_ = r.playCard(seat, choice)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user