This commit is contained in:
meixiongfeng 2023-10-24 17:39:14 +08:00
parent 8e97e8d84e
commit 88dd4aea0e
2 changed files with 38 additions and 16 deletions

View File

@ -124,7 +124,7 @@ func (this *Room) AiOperator() {
this.player1.Ps = MaxPs this.player1.Ps = MaxPs
// 交换元素 // 交换元素
_, szMap, oid1, oid2 = this.chessboard.AiSwapGirde() curScore, szMap, oid1, oid2 = this.chessboard.AiSwapGirde()
if this.NexPower != this.curPower { if this.NexPower != this.curPower {
this.round++ this.round++
} }
@ -279,6 +279,15 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
} }
} }
// for _, v := range szMap {
// fmt.Printf("======szMap=======\n")
// for index := Width - 1; index >= 0; index-- {
// for j := 0; j < Height; j++ {
// fmt.Printf("%d:%d ", v.Data[index+j*Height].Oid, v.Data[index+j*Height].Color)
// }
// fmt.Printf("\n")
// }
// }
// 广播消息 // 广播消息
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{ if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
Mpadata: szMap, Mpadata: szMap,
@ -294,7 +303,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
}, this.szSession...); err != nil { }, this.szSession...); err != nil {
this.Errorln(err) this.Errorln(err)
} }
if this.round > this.MaxRound { // 游戏结束 if this.round > this.MaxRound && this.NexPower == this.player1.Uid { // 游戏结束
this.GameOver() this.GameOver()
return return
} }

View File

@ -85,12 +85,12 @@ func (this *MapData) SwapGirde(oldId, newId int32) (bSwap bool) {
func (this *MapData) SetMap() { func (this *MapData) SetMap() {
sz2 := []int32{ sz2 := []int32{
5, 1, 2, 5, 1, 5, 2, 1, 1, 2, 5, 1, 5, 2,
5, 2, 3, 1, 2, 4, 4, 3, 2, 3, 1, 2, 4, 4,
4, 1, 1, 3, 6, 4, 1, 2, 1, 1, 3, 6, 4, 1,
1, 3, 1, 4, 3, 6, 3, 1, 3, 1, 4, 3, 6, 3,
1, 3, 3, 5, 1, 6, 1, 1, 3, 3, 5, 1, 6, 1,
5, 1, 5, 5, 1, 3, 1, 5, 1, 2, 5, 1, 3, 1,
1, 1, 5, 1, 2, 1, 4, 1, 1, 5, 1, 2, 1, 4,
} }
var pos int var pos int
@ -461,15 +461,14 @@ func (this *MapData) CheckMap(color int32) (score int32, szMap []*pb.MapData) {
} }
score += curScore // 总分 score += curScore // 总分
this.DropGirde() if this.DropGirde() {
if curScore > 0 {
this.Debugf()
szMap = append(szMap, &pb.MapData{ szMap = append(szMap, &pb.MapData{
Data: this.Plat, Data: this.GetPalat(),
CurSocre: curScore, CurSocre: curScore,
Xgrid: count, Xgrid: count,
}) })
} }
// 检查掉落 // 检查掉落
this.operElem = []int32{} // 初始化操作元素 this.operElem = []int32{} // 初始化操作元素
if curScore == 0 { if curScore == 0 {
@ -481,12 +480,13 @@ func (this *MapData) CheckMap(color int32) (score int32, szMap []*pb.MapData) {
} }
// 下落 生成新的格子 (返回掉落所获得的分数) // 下落 生成新的格子 (返回掉落所获得的分数)
func (this *MapData) DropGirde() { func (this *MapData) DropGirde() bool {
bDrop := false
for i := 0; i < Width; i++ { for i := 0; i < Width; i++ {
for j := 0; j < Height; j++ { for j := 0; j < Height; j++ {
index := i*Width + j index := i*Width + j
if this.Plat[index].Color == 0 { // 说明这列有空 if this.Plat[index].Color == 0 { // 说明这列有空
bDrop = true
var add int var add int
for m := j + 1; m < Height; m++ { for m := j + 1; m < Height; m++ {
k1 := i*Width + m k1 := i*Width + m
@ -505,11 +505,23 @@ func (this *MapData) DropGirde() {
} }
} }
return return bDrop
}
func (this *MapData) GetPalat() (data []*pb.GirdeData) {
for _, v := range this.Plat {
data = append(data, &pb.GirdeData{
Oid: v.Oid,
Color: v.Color,
Cid: v.Cid,
Score: v.Score,
Special: v.Special,
})
}
return data
} }
// ai操作 // ai操作
func (this *MapData) AiSwapGirde() (bSwap bool, szMap []*pb.MapData, oid1 int32, oid2 int32) { func (this *MapData) AiSwapGirde() (score int32, szMap []*pb.MapData, oid1 int32, oid2 int32) {
for pos := 0; pos < Total; pos++ { for pos := 0; pos < Total; pos++ {
y := pos % Height y := pos % Height
@ -523,8 +535,9 @@ func (this *MapData) AiSwapGirde() (bSwap bool, szMap []*pb.MapData, oid1 int32,
oid1 = 0 oid1 = 0
oid2 = 0 oid2 = 0
} else { } else {
score += s
szMap = append(szMap, m...) szMap = append(szMap, m...)
bSwap = true
break break
} }
} }
@ -540,7 +553,7 @@ func (this *MapData) AiSwapGirde() (bSwap bool, szMap []*pb.MapData, oid1 int32,
oid2 = 0 oid2 = 0
} else { } else {
szMap = append(szMap, m...) szMap = append(szMap, m...)
bSwap = true score += s
break break
} }
} }