184 lines
4.8 KiB
Go
184 lines
4.8 KiB
Go
![]() |
package room
|
||
|
|
||
|
import (
|
||
|
"math/rand"
|
||
|
"samba/pkg/log"
|
||
|
"samba/proto"
|
||
|
"samba/server/game/baseroom"
|
||
|
"samba/server/truco/poker"
|
||
|
"samba/stub"
|
||
|
"samba/util/model"
|
||
|
"samba/util/util"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
// RobotRotten 摆烂型机器人
|
||
|
type RobotRotten struct {
|
||
|
*BaseRobot
|
||
|
}
|
||
|
|
||
|
func NewRobotRotten(cnf stub.RobotTemper, userInfo *model.UserInfo, seat *TrucoSeat, room *TrucoRoom) *RobotRotten {
|
||
|
return &RobotRotten{
|
||
|
BaseRobot: NewBaseRobot(cnf, userInfo, seat, room),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (r *RobotRotten) OnMessage(msgId string, iMsg interface{}) {
|
||
|
switch msgId {
|
||
|
case proto.RspEnterRoomId:
|
||
|
r.NewTimer(baseroom.TtEnterRoom, time.Second*time.Duration(RobotOnMsgTime), func() {
|
||
|
r.sendReady(r.room)
|
||
|
})
|
||
|
case proto.NtfDealPokersId:
|
||
|
_ = iMsg.(*proto.NtfDealPokers)
|
||
|
case proto.NtfDecidingGameId:
|
||
|
msg := iMsg.(*proto.NtfDecidingGame)
|
||
|
if TeamColor(msg.TeamColor) == r.room.teamColor(r.seat.No()) {
|
||
|
r.NewTimer(baseroom.TtDecidingGame, time.Second*time.Duration(rand.Int()%RobotOnMsgRandTime+RobotOnMsgTime), func() {
|
||
|
r.onDecidingAct(r.room, msg)
|
||
|
})
|
||
|
|
||
|
}
|
||
|
case proto.NtfPlayerActId:
|
||
|
msg := iMsg.(*proto.NtfPlayerAct)
|
||
|
if msg.Seat == r.seat.No() {
|
||
|
r.NewTimer(baseroom.TtPlayerAct, time.Second*time.Duration(rand.Int()%RobotOnMsgRandTime+RobotOnMsgTime), func() {
|
||
|
r.onPlayerAct(r.room, msg)
|
||
|
})
|
||
|
|
||
|
}
|
||
|
case proto.NtfPlayerRspRaiseId:
|
||
|
msg := iMsg.(*proto.NtfPlayerRspRaise)
|
||
|
if TeamColor(msg.TeamColor) != r.room.teamColor(r.seat.No()) {
|
||
|
return
|
||
|
}
|
||
|
r.NewTimer(baseroom.TtPlayerRspRaise, time.Second*time.Duration(rand.Int()%RobotOnMsgRandTime+RobotOnMsgTime), func() {
|
||
|
r.onRspRaise(r.room, msg)
|
||
|
})
|
||
|
case proto.NtfEmoteId:
|
||
|
r.onEmote(iMsg.(*proto.NtfEmote))
|
||
|
case proto.NtfUserDisbandRoomId:
|
||
|
msg := iMsg.(*proto.NtfUserDisbandRoom)
|
||
|
if len(msg.Agree) == r.room.SeatPlayerNum() {
|
||
|
r.GameClean()
|
||
|
}
|
||
|
//case proto.NtfRoundSettleId:
|
||
|
case proto.NtfGameSettleId, proto.NtfMaintainId:
|
||
|
r.GameClean()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 上分型操作
|
||
|
func (r *RobotRotten) outPokerRoundUp0(room *TrucoRoom, _ interface{}) {
|
||
|
var outPoker *poker.Poker
|
||
|
pos := r.positionInOutPoker(room)
|
||
|
if pos == 0 {
|
||
|
outPoker = r.outMaxPoker(room)
|
||
|
} else if pos == 1 {
|
||
|
if r.canBigger(room) {
|
||
|
outPoker = r.outMaxPoker(room)
|
||
|
} else {
|
||
|
outPoker = r.outMinPoker(room)
|
||
|
}
|
||
|
} else if pos == 2 || pos == 4 {
|
||
|
if bigger, big := r.teammateBigger(room); bigger {
|
||
|
if big {
|
||
|
outPoker = r.outMinPoker(room)
|
||
|
} else {
|
||
|
if r.canBigger(room) {
|
||
|
outPoker = r.outMaxPoker(room)
|
||
|
} else {
|
||
|
outPoker = r.outMinPoker(room)
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
|
if r.canBigger(room) {
|
||
|
outPoker = r.outMaxPoker(room)
|
||
|
} else {
|
||
|
outPoker = r.outMinPoker(room)
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
|
if bigger, _ := r.teammateBigger(room); bigger {
|
||
|
outPoker = r.outMinPoker(room)
|
||
|
} else {
|
||
|
if r.canBigger(room) {
|
||
|
outPoker = r.outBiggerPoker(room)
|
||
|
} else {
|
||
|
outPoker = r.outMinPoker(room)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if outPoker != nil {
|
||
|
req := &proto.ReqPlayerOutPoker{Poker: outPoker.ToInt()}
|
||
|
msg := util.MakeMessage(proto.ReqPlayerOutPokerId, req, r.UID, room.Id())
|
||
|
room.OnMessage(proto.ReqPlayerOutPokerId, msg)
|
||
|
} else {
|
||
|
log.Error(r.room.SeatLog(r.seat, "ai error"))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 上分型操作
|
||
|
func (r *RobotRotten) outPokerRound(room *TrucoRoom, _ interface{}) {
|
||
|
var outPoker *poker.Poker
|
||
|
rd := rand.Int() % 100
|
||
|
if rd < stub.GGlobalAI.TrucoRottenOutPokerDeal {
|
||
|
outPoker = r.seat.Pokers[0]
|
||
|
} else {
|
||
|
rd -= stub.GGlobalAI.TrucoRottenOutPokerDeal
|
||
|
if rd < stub.GGlobalAI.TrucoRottenOutPokerAsc {
|
||
|
outPoker = r.outMinPoker(room)
|
||
|
} else {
|
||
|
outPoker = r.outMaxPoker(room)
|
||
|
}
|
||
|
}
|
||
|
if outPoker != nil {
|
||
|
req := &proto.ReqPlayerOutPoker{Poker: outPoker.ToInt()}
|
||
|
msg := util.MakeMessage(proto.ReqPlayerOutPokerId, req, r.UID, room.Id())
|
||
|
room.OnMessage(proto.ReqPlayerOutPokerId, msg)
|
||
|
} else {
|
||
|
log.Error(r.room.SeatLog(r.seat, "ai error"))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (r *RobotRotten) outPokerRound3(room *TrucoRoom, _ interface{}) {
|
||
|
if len(r.seat.Pokers) > 0 {
|
||
|
req := &proto.ReqPlayerOutPoker{Poker: r.seat.Pokers[0].ToInt()}
|
||
|
msg := util.MakeMessage(proto.ReqPlayerOutPokerId, req, r.UID, room.Id())
|
||
|
room.OnMessage(proto.ReqPlayerOutPokerId, msg)
|
||
|
} else {
|
||
|
log.Error(r.room.SeatLog(r.seat, "ai error"))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (r *RobotRotten) outPoker(room *TrucoRoom, msg interface{}) {
|
||
|
|
||
|
if r.getRound() < 2 {
|
||
|
r.outPokerRound(room, msg)
|
||
|
} else {
|
||
|
r.outPokerRound3(room, msg)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (r *RobotRotten) onPlayerAct(room *TrucoRoom, msg *proto.NtfPlayerAct) {
|
||
|
r.outPoker(room, msg)
|
||
|
}
|
||
|
|
||
|
func (r *RobotRotten) onRspRaise(room *TrucoRoom, _ *proto.NtfPlayerRspRaise) {
|
||
|
act := AtGiveUp
|
||
|
if rand.Intn(100) <= 50 {
|
||
|
act = AtAgree
|
||
|
}
|
||
|
r.sendRaise(room, act, false)
|
||
|
}
|
||
|
|
||
|
func (r *RobotRotten) onDecidingAct(room *TrucoRoom, _ *proto.NtfDecidingGame) {
|
||
|
s := rand.Int() % 100
|
||
|
log.Debug(room.SeatLog(r.seat, "决胜局概率:%v", s))
|
||
|
if s < 50 {
|
||
|
r.sendRaise(room, AtAgree, true)
|
||
|
} else {
|
||
|
r.sendRaise(room, AtGiveUp, true)
|
||
|
}
|
||
|
}
|