245 lines
6.3 KiB
Go
245 lines
6.3 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"
|
|
)
|
|
|
|
type RobotRadical struct {
|
|
*BaseRobot
|
|
}
|
|
|
|
func NewRobotRadical(cnf stub.RobotTemper, userInfo *model.UserInfo, seat *TrucoSeat, room *TrucoRoom) *RobotRadical {
|
|
return &RobotRadical{
|
|
BaseRobot: NewBaseRobot(cnf, userInfo, seat, room),
|
|
}
|
|
}
|
|
|
|
func (r *RobotRadical) 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:
|
|
r.sortPokers()
|
|
msg := iMsg.(*proto.NtfDealPokers)
|
|
if util.RandHappened(50) {
|
|
break
|
|
}
|
|
r.NewSecretEmoteTimer(time.Second*time.Duration(rand.Int()%2+RobotOnMsgTime+3), func() {
|
|
r.sendSecretEmote(r.room, msg)
|
|
})
|
|
|
|
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 *RobotRadical) outPokerRound1(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 *RobotRadical) outPokerRound2(room *TrucoRoom, _ interface{}) {
|
|
var outPoker *poker.Poker
|
|
pos := r.positionInOutPoker(room)
|
|
if pos == 0 {
|
|
if r.roundWinLose(room, 0) != poker.CppEqual {
|
|
outPoker = r.outMinPoker(room)
|
|
} else {
|
|
if r.handlePokerBiggerThenTeammate(room) {
|
|
outPoker = r.outMaxPoker(room)
|
|
} else {
|
|
outPoker = r.outMinPoker(room)
|
|
}
|
|
}
|
|
} else if pos == 1 {
|
|
if r.roundWinLose(room, 0) != poker.CppEqual {
|
|
outPoker = r.outMaxPoker(room)
|
|
} else {
|
|
if r.handlePokerBiggerThenTeammate(room) {
|
|
outPoker = r.outMaxPoker(room)
|
|
} else {
|
|
outPoker = r.outMinPoker(room)
|
|
}
|
|
}
|
|
//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 *RobotRadical) 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 *RobotRadical) outPoker(room *TrucoRoom, msg interface{}) {
|
|
if r.getRound() == 0 {
|
|
r.outPokerRound1(room, msg)
|
|
} else if r.getRound() == 1 {
|
|
r.outPokerRound2(room, msg)
|
|
} else {
|
|
r.outPokerRound3(room, msg)
|
|
}
|
|
}
|
|
|
|
func (r *RobotRadical) onPlayerAct(room *TrucoRoom, msg *proto.NtfPlayerAct) {
|
|
if r.canRaise(msg) {
|
|
// 前8张为大牌数量
|
|
colorNum := r.bigPokerNumForTeam(room, stub.GGlobalAI.TrucoBiggerPoker)
|
|
if colorNum >= stub.GGlobalAI.TrucoRadicalRaise {
|
|
r.sendRaise(room, IntToActType(msg.CanCall), true)
|
|
return
|
|
}
|
|
}
|
|
r.outPoker(room, msg)
|
|
}
|
|
|
|
func (r *RobotRadical) onRspRaise(room *TrucoRoom, _ interface{}) {
|
|
colorNum := r.bigPokerNumForTeam(room, stub.GGlobalAI.TrucoBiggerPoker)
|
|
if colorNum >= stub.GGlobalAI.TrucoRadicalRaise {
|
|
r.sendRaise(room, AtAgree, false)
|
|
} else {
|
|
r.sendRaise(room, AtGiveUp, false)
|
|
}
|
|
}
|
|
|
|
func (r *RobotRadical) onDecidingAct(room *TrucoRoom, _ *proto.NtfDecidingGame) {
|
|
colorNum := r.bigPokerNumForTeam(room, 4)
|
|
if colorNum >= stub.GGlobalAI.TrucoAplombRaise1 {
|
|
r.sendRaise(room, AtAgree, true)
|
|
} else {
|
|
r.sendRaise(room, AtGiveUp, true)
|
|
}
|
|
}
|