操作结果返回操作动作

This commit is contained in:
meixiongfeng 2023-10-23 19:05:13 +08:00
parent c55161fb6c
commit 9057112fda
4 changed files with 123 additions and 57 deletions

View File

@ -69,6 +69,9 @@ func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) {
Round: this.round, Round: this.round,
User1: this.player1, User1: this.player1,
User2: this.player2, User2: this.player2,
Itype: 0,
Curid: 0,
Targetid: 0,
}, this.szSession...); err != nil { }, this.szSession...); err != nil {
this.Errorln(err) this.Errorln(err)
} }
@ -107,6 +110,10 @@ func (this *Room) AiOperator() {
var ( var (
curScore int32 curScore int32
szMap []*pb.MapData szMap []*pb.MapData
curid int32
targetid int32
oid1 int32
oid2 int32
) )
this.module.Debugf("AI 操作\n") this.module.Debugf("AI 操作\n")
@ -117,12 +124,12 @@ func (this *Room) AiOperator() {
this.player1.Ps = MaxPs this.player1.Ps = MaxPs
// 交换元素 // 交换元素
if bSwap, m := this.chessboard.AiSwapGirde(); bSwap { _, szMap, curid, targetid = this.chessboard.AiSwapGirde()
szMap = append(szMap, m...)
}
if this.NexPower != this.curPower { if this.NexPower != this.curPower {
this.round++ this.round++
} }
oid1 = this.chessboard.Plat[targetid].Oid
oid2 = this.chessboard.Plat[curid].Oid
this.player2.Score += curScore this.player2.Score += curScore
// 广播消息 // 广播消息
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{ if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
@ -133,6 +140,9 @@ func (this *Room) AiOperator() {
Round: this.round, Round: this.round,
User1: this.player1, User1: this.player1,
User2: this.player2, User2: this.player2,
Itype: 0,
Curid: oid1,
Targetid: oid2,
}, this.szSession...); err != nil { }, this.szSession...); err != nil {
this.Errorln(err) this.Errorln(err)
} }
@ -152,6 +162,8 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
var ( var (
curScore int32 curScore int32
AIOperator bool AIOperator bool
oid1 int32 // 唯一id
oid2 int32
) )
var szMap []*pb.MapData var szMap []*pb.MapData
req := msg.(*pb.EntertainOperatorReq) req := msg.(*pb.EntertainOperatorReq)
@ -163,7 +175,8 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
} }
return return
} }
oid1 = this.chessboard.Plat[req.Curid].Oid
oid2 = this.chessboard.Plat[req.Targetid].Oid
// 交换元素 // 交换元素
if b := this.chessboard.SwapGirde(req.Curid, req.Targetid); !b { // 交换格子 if b := this.chessboard.SwapGirde(req.Curid, req.Targetid); !b { // 交换格子
errdata = &pb.ErrorData{ errdata = &pb.ErrorData{
@ -223,6 +236,9 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
Round: this.round, Round: this.round,
User1: this.player1, User1: this.player1,
User2: this.player2, User2: this.player2,
Itype: req.Itype,
Curid: oid1,
Targetid: oid2,
}, this.szSession...); err != nil { }, this.szSession...); err != nil {
this.Errorln(err) this.Errorln(err)
} }

View File

@ -46,7 +46,7 @@ func (this *MapData) CreateGride(index int32) *pb.GirdeData {
return &pb.GirdeData{ return &pb.GirdeData{
Oid: this.oid, Oid: this.oid,
Color: t, Color: t,
Cid: GetRandType(), Cid: t,
Score: 1, Score: 1,
Special: 0, Special: 0,
} }
@ -69,7 +69,7 @@ func (this *MapData) SwapGirde(oldId, newId int32) (bSwap bool) {
if (oldId%Height+1 < Total && oldId+1 == newId) || if (oldId%Height+1 < Total && oldId+1 == newId) ||
(oldId%Height > 0 && oldId-1 == newId) || (oldId%Height > 0 && oldId-1 == newId) ||
(oldId+Width < Total && oldId+Width == newId) || (oldId+Width < Total && oldId+Width == newId) ||
(oldId-Width > 0 && oldId-Width == newId) { (oldId-Width >= 0 && oldId-Width == newId) {
bSwap = true bSwap = true
tmp := new(pb.GirdeData) tmp := new(pb.GirdeData)
*tmp = *this.Plat[newId] *tmp = *this.Plat[newId]
@ -78,6 +78,7 @@ func (this *MapData) SwapGirde(oldId, newId int32) (bSwap bool) {
this.operElem = append(this.operElem, newId) this.operElem = append(this.operElem, newId)
this.operElem = append(this.operElem, oldId) this.operElem = append(this.operElem, oldId)
} }
this.Debugf()
//this.CheckMap(color) //this.CheckMap(color)
return return
} }
@ -222,26 +223,37 @@ func (this *MapData) Check4X(color int32) (bEliminate bool, score int32, count i
var ( var (
newElem int // 生成的一个新的元素CID newElem int // 生成的一个新的元素CID
) )
fmt.Printf("=====开始检测消除4x===========\n")
this.Debugf()
var xiaochu []int // 即将消除的key var xiaochu []int // 即将消除的key
for k, v := range this.Plat { for k, v := range this.Plat {
if v.Color == 0 { if v.Color == 0 {
continue continue
} }
x := int32(k % Height) // x x := int32(k % Height) // x
newElem = 0
if x+3 < Height { if x+3 < Height {
k1 := this.Plat[k].Color k1 := this.Plat[k].Color
k2 := this.Plat[k+1].Color k2 := this.Plat[k+1].Color
k3 := this.Plat[k+2].Color k3 := this.Plat[k+2].Color
k4 := this.Plat[k+3].Color k4 := this.Plat[k+3].Color
newElem = k + 2
if k1 == k2 && k3 == k4 && k2 == k3 { if k1 == k2 && k3 == k4 && k2 == k3 {
for _, v1 := range this.operElem { for _, v1 := range this.operElem {
if v1 == k2 { for i := 0; i <= 3; i++ {
newElem = k + 1 if int(v1) == k+i {
newElem = int(v1)
break break
} }
} }
if newElem != 0 {
break
}
}
if newElem == 0 {
newElem = k + 2 // 给个默认值
}
this.oid++ this.oid++
// 生成一个新的类型元素 // 生成一个新的类型元素
if this.module != nil { if this.module != nil {
@ -276,15 +288,22 @@ func (this *MapData) Check4X(color int32) (bEliminate bool, score int32, count i
k3 := this.Plat[k+2*Width].Color k3 := this.Plat[k+2*Width].Color
k4 := this.Plat[k+3*Width].Color k4 := this.Plat[k+3*Width].Color
if k1 == k2 && k3 == k4 && k2 == k3 {
newElem = k + 2*Width
if k1 == k2 && k3 == k4 && k2 == k3 { if k1 == k2 && k3 == k4 && k2 == k3 {
for _, v1 := range this.operElem { for _, v1 := range this.operElem {
if v1 == k2 { for i := 0; i <= 3; i++ {
newElem = k + Width if int(v1) == k+i*Width {
newElem = int(v1) // 创建一个特殊的元素
break break
} }
} }
if newElem != 0 {
break
}
}
if newElem != 0 {
newElem = k + 2*Width // 给个默认值
}
this.oid++ this.oid++
if this.module != nil { if this.module != nil {
// 生成一个新的类型元素 // 生成一个新的类型元素
@ -314,7 +333,6 @@ func (this *MapData) Check4X(color int32) (bEliminate bool, score int32, count i
} }
} }
} }
}
var next []int var next []int
for _, id := range xiaochu { for _, id := range xiaochu {
@ -460,7 +478,7 @@ func (this *MapData) CheckMap(color int32) (score int32, szMap []*pb.MapData, co
break break
} }
} }
//this.Debugf() this.Debugf()
return return
} }
@ -494,7 +512,7 @@ func (this *MapData) DropGirde() {
} }
// ai操作 // ai操作
func (this *MapData) AiSwapGirde() (bSwap bool, szMap []*pb.MapData) { func (this *MapData) AiSwapGirde() (bSwap bool, szMap []*pb.MapData, pre int32, aft int32) {
for pos := 0; pos < Total; pos++ { for pos := 0; pos < Total; pos++ {
y := pos % Height y := pos % Height
@ -503,11 +521,12 @@ func (this *MapData) AiSwapGirde() (bSwap bool, szMap []*pb.MapData) {
if s, m, _ := this.CheckMap(2); s == 0 { if s, m, _ := this.CheckMap(2); s == 0 {
this.operElem = []int32{} this.operElem = []int32{}
} else { } else {
pre = int32(pos)
aft = int32(pos + 1)
szMap = append(szMap, m...) szMap = append(szMap, m...)
bSwap = true bSwap = true
break break
} }
} }
} }
if pos/Width+1 < Width { if pos/Width+1 < Width {
@ -516,6 +535,8 @@ func (this *MapData) AiSwapGirde() (bSwap bool, szMap []*pb.MapData) {
this.SwapGirde(int32(pos+Width), int32(pos)) this.SwapGirde(int32(pos+Width), int32(pos))
this.operElem = []int32{} this.operElem = []int32{}
} else { } else {
pre = int32(pos)
aft = int32(pos + Width)
szMap = append(szMap, m...) szMap = append(szMap, m...)
bSwap = true bSwap = true
break break

View File

@ -87,10 +87,11 @@ func Test_Main(t *testing.T) {
m.SetMap() m.SetMap()
var szMap []*pb.MapData var szMap []*pb.MapData
if bSwap, m := m.AiSwapGirde(); bSwap { // if bSwap, m := m.AiSwapGirde(); bSwap {
szMap = append(szMap, m...) // szMap = append(szMap, m...)
} // }
m.SwapGirde(1, 8) m.SwapGirde(1, 8)
m.CheckMap(1)
m.DropGirde() m.DropGirde()

View File

@ -448,6 +448,9 @@ type EntertainOperatorRstPush struct {
Round int32 `protobuf:"varint,5,opt,name=round,proto3" json:"round"` // 轮数 Round int32 `protobuf:"varint,5,opt,name=round,proto3" json:"round"` // 轮数
User1 *PlayerData `protobuf:"bytes,6,opt,name=user1,proto3" json:"user1"` // 玩家数据也需要同步 User1 *PlayerData `protobuf:"bytes,6,opt,name=user1,proto3" json:"user1"` // 玩家数据也需要同步
User2 *PlayerData `protobuf:"bytes,7,opt,name=user2,proto3" json:"user2"` User2 *PlayerData `protobuf:"bytes,7,opt,name=user2,proto3" json:"user2"`
Itype int32 `protobuf:"varint,8,opt,name=itype,proto3" json:"itype"` // 操作类型 0 默认交换元素
Curid int32 `protobuf:"varint,9,opt,name=curid,proto3" json:"curid"` // 当前key
Targetid int32 `protobuf:"varint,10,opt,name=targetid,proto3" json:"targetid"` // 目标key
} }
func (x *EntertainOperatorRstPush) Reset() { func (x *EntertainOperatorRstPush) Reset() {
@ -531,6 +534,27 @@ func (x *EntertainOperatorRstPush) GetUser2() *PlayerData {
return nil return nil
} }
func (x *EntertainOperatorRstPush) GetItype() int32 {
if x != nil {
return x.Itype
}
return 0
}
func (x *EntertainOperatorRstPush) GetCurid() int32 {
if x != nil {
return x.Curid
}
return 0
}
func (x *EntertainOperatorRstPush) GetTargetid() int32 {
if x != nil {
return x.Targetid
}
return 0
}
// 游戏结束推送 // 游戏结束推送
type EntertainGameOverPush struct { type EntertainGameOverPush struct {
state protoimpl.MessageState state protoimpl.MessageState
@ -656,7 +680,7 @@ var file_entertain_entertain_msg_proto_rawDesc = []byte{
0x15, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74, 0x61, 0x69, 0x6e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x15, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74, 0x61, 0x69, 0x6e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74,
0x6f, 0x72, 0x52, 0x65, 0x73, 0x70, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x6f, 0x72, 0x52, 0x65, 0x73, 0x70, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73,
0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73,
0x22, 0xe2, 0x01, 0x0a, 0x18, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74, 0x61, 0x69, 0x6e, 0x4f, 0x70, 0x22, 0xaa, 0x02, 0x0a, 0x18, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74, 0x61, 0x69, 0x6e, 0x4f, 0x70,
0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x52, 0x73, 0x74, 0x50, 0x75, 0x73, 0x68, 0x12, 0x22, 0x0a, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x52, 0x73, 0x74, 0x50, 0x75, 0x73, 0x68, 0x12, 0x22, 0x0a,
0x07, 0x6d, 0x70, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x08, 0x07, 0x6d, 0x70, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x08,
0x2e, 0x4d, 0x61, 0x70, 0x44, 0x61, 0x74, 0x61, 0x52, 0x07, 0x6d, 0x70, 0x61, 0x64, 0x61, 0x74, 0x2e, 0x4d, 0x61, 0x70, 0x44, 0x61, 0x74, 0x61, 0x52, 0x07, 0x6d, 0x70, 0x61, 0x64, 0x61, 0x74,
@ -670,19 +694,23 @@ var file_entertain_entertain_msg_proto_rawDesc = []byte{
0x2e, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05, 0x75, 0x73, 0x65, 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05, 0x75, 0x73, 0x65,
0x72, 0x31, 0x12, 0x21, 0x0a, 0x05, 0x75, 0x73, 0x65, 0x72, 0x32, 0x18, 0x07, 0x20, 0x01, 0x28, 0x72, 0x31, 0x12, 0x21, 0x0a, 0x05, 0x75, 0x73, 0x65, 0x72, 0x32, 0x18, 0x07, 0x20, 0x01, 0x28,
0x0b, 0x32, 0x0b, 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05, 0x0b, 0x32, 0x0b, 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05,
0x75, 0x73, 0x65, 0x72, 0x32, 0x22, 0xad, 0x01, 0x0a, 0x15, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74, 0x75, 0x73, 0x65, 0x72, 0x32, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x74, 0x79, 0x70, 0x65, 0x18, 0x08,
0x61, 0x69, 0x6e, 0x47, 0x61, 0x6d, 0x65, 0x4f, 0x76, 0x65, 0x72, 0x50, 0x75, 0x73, 0x68, 0x12, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x69, 0x74, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x63,
0x21, 0x0a, 0x05, 0x75, 0x73, 0x65, 0x72, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x75, 0x72, 0x69, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x75, 0x72, 0x69,
0x2e, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05, 0x75, 0x73, 0x65, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x69, 0x64, 0x18, 0x0a, 0x20,
0x72, 0x31, 0x12, 0x21, 0x0a, 0x05, 0x75, 0x73, 0x65, 0x72, 0x32, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01, 0x28, 0x05, 0x52, 0x08, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x69, 0x64, 0x22, 0xad, 0x01,
0x0b, 0x32, 0x0b, 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05, 0x0a, 0x15, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74, 0x61, 0x69, 0x6e, 0x47, 0x61, 0x6d, 0x65, 0x4f,
0x75, 0x73, 0x65, 0x72, 0x32, 0x12, 0x22, 0x0a, 0x07, 0x6d, 0x70, 0x61, 0x64, 0x61, 0x74, 0x61, 0x76, 0x65, 0x72, 0x50, 0x75, 0x73, 0x68, 0x12, 0x21, 0x0a, 0x05, 0x75, 0x73, 0x65, 0x72, 0x31,
0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x4d, 0x61, 0x70, 0x44, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x44,
0x52, 0x07, 0x6d, 0x70, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x6f, 0x77, 0x61, 0x74, 0x61, 0x52, 0x05, 0x75, 0x73, 0x65, 0x72, 0x31, 0x12, 0x21, 0x0a, 0x05, 0x75, 0x73,
0x65, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x12, 0x65, 0x72, 0x32, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x50, 0x6c, 0x61, 0x79,
0x14, 0x0a, 0x05, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05, 0x75, 0x73, 0x65, 0x72, 0x32, 0x12, 0x22, 0x0a,
0x72, 0x6f, 0x75, 0x6e, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x07, 0x6d, 0x70, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08,
0x72, 0x6f, 0x74, 0x6f, 0x33, 0x2e, 0x4d, 0x61, 0x70, 0x44, 0x61, 0x74, 0x61, 0x52, 0x07, 0x6d, 0x70, 0x61, 0x64, 0x61, 0x74,
0x61, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09,
0x52, 0x05, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x6f, 0x75, 0x6e, 0x64,
0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x42, 0x06, 0x5a,
0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (