规则完善
This commit is contained in:
parent
d89e6b0898
commit
785b2f7881
@ -105,18 +105,15 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
|
||||
// 交换元素
|
||||
this.chessboard.SwapGirde(req.Curid, req.Targetid) // 交换格子
|
||||
for {
|
||||
if b, score := this.chessboard.CheckMap(); b {
|
||||
break
|
||||
} else {
|
||||
curScore += score // 统计积分
|
||||
}
|
||||
|
||||
this.chessboard.DropGirde()
|
||||
szMap = append(szMap, &pb.MapData{
|
||||
Data: this.chessboard.Data,
|
||||
})
|
||||
this.chessboard.CheckMap()
|
||||
if score, m := this.chessboard.DropGirde(); score > 0 {
|
||||
curScore += score
|
||||
szMap = append(szMap, m...)
|
||||
}
|
||||
|
||||
// 操作消息返回
|
||||
session.SendMsg(string(this.module.GetType()), "operator", &pb.EntertainOperatorResp{
|
||||
Success: true,
|
||||
|
@ -72,8 +72,11 @@ func Test_Main(t *testing.T) {
|
||||
m := new(entertainment.MapData)
|
||||
m.InitMap()
|
||||
|
||||
m.SwapGirde(0, 1)
|
||||
m.SwapGirde(1, 11)
|
||||
fmt.Printf("得分:%d\n", m.CheckMap())
|
||||
m.DropGirde()
|
||||
flag.Parse()
|
||||
|
||||
s := NewService(
|
||||
rpcx.SetConfPath(*conf),
|
||||
rpcx.SetVersion("1.0.0.0"),
|
||||
|
@ -100,7 +100,7 @@ func (this *MapData) InitMap() {
|
||||
4, 4, 1, 5, 6, 4, 1,
|
||||
6, 3, 1, 1, 3, 6, 3,
|
||||
6, 3, 5, 2, 4, 6, 1,
|
||||
5, 2, 4, 2, 1, 3, 1,
|
||||
5, 6, 5, 5, 1, 3, 1,
|
||||
6, 5, 5, 1, 2, 1, 4,
|
||||
}
|
||||
var index = 0
|
||||
@ -111,7 +111,7 @@ func (this *MapData) InitMap() {
|
||||
index++
|
||||
}
|
||||
}
|
||||
//this.Debugf()
|
||||
this.Debugf()
|
||||
}
|
||||
|
||||
// 交换2个元素(参数 id )
|
||||
@ -139,13 +139,13 @@ func (this *MapData) SwapGirde(i, j int32) bool {
|
||||
}
|
||||
this.Data[i] = g2
|
||||
this.Data[j] = tmp
|
||||
if !this.CheckSwape() { // 交换后不能消除
|
||||
if !this.CheckSwape(i, j) { // 交换后不能消除
|
||||
this.Data[i] = tmp
|
||||
this.Data[j] = g2
|
||||
bSwap = false
|
||||
}
|
||||
}
|
||||
|
||||
this.Debugf()
|
||||
return bSwap
|
||||
}
|
||||
|
||||
@ -162,20 +162,23 @@ func (this *MapData) Debugf() {
|
||||
|
||||
// 检查5消
|
||||
func (this *MapData) Check5X() (bEliminate bool, score int32) {
|
||||
m := make(map[int32]struct{}, 0)
|
||||
|
||||
m := make(map[int32]struct{}, 5)
|
||||
bEliminate = true
|
||||
del := make(map[int32]int32)
|
||||
for i := 0; i < Width; i++ {
|
||||
for j := 0; j < Height; j++ {
|
||||
m = make(map[int32]struct{}, 0)
|
||||
key := int32(i*10 + j)
|
||||
iType := this.GetKeyType(key)
|
||||
if iType == 0 {
|
||||
continue
|
||||
}
|
||||
curKey := this.Data[key].Itype
|
||||
if curKey == 0 {
|
||||
continue
|
||||
}
|
||||
m[curKey] = struct{}{}
|
||||
if j+4 < Height {
|
||||
if i+4 < Width {
|
||||
i1 := this.Data[int32((i+1)*10+j)]
|
||||
i2 := this.Data[int32((i+2)*10+j)]
|
||||
i3 := this.Data[int32((i+3)*10+j)]
|
||||
@ -186,7 +189,7 @@ func (this *MapData) Check5X() (bEliminate bool, score int32) {
|
||||
m[i3.Itype] = struct{}{}
|
||||
m[i4.Itype] = struct{}{}
|
||||
|
||||
if len(m) == 5 {
|
||||
if len(m) == 1 {
|
||||
del[int32((i+1)*10+j)] = i1.Score
|
||||
del[int32((i+2)*10+j)] = i2.Score
|
||||
del[int32((i+3)*10+j)] = i3.Score
|
||||
@ -194,7 +197,8 @@ func (this *MapData) Check5X() (bEliminate bool, score int32) {
|
||||
del[key] = this.Data[key].Score
|
||||
}
|
||||
}
|
||||
if i+4 < Width {
|
||||
m = map[int32]struct{}{}
|
||||
if j+4 < Height {
|
||||
i1 := this.Data[int32(i*10+j+1)]
|
||||
i2 := this.Data[int32(i*10+j+2)]
|
||||
i3 := this.Data[int32(i*10+j+3)]
|
||||
@ -203,7 +207,7 @@ func (this *MapData) Check5X() (bEliminate bool, score int32) {
|
||||
m[i2.Itype] = struct{}{}
|
||||
m[i3.Itype] = struct{}{}
|
||||
m[i4.Itype] = struct{}{}
|
||||
if len(m) == 5 {
|
||||
if len(m) == 1 { // 1 2 3 4 5
|
||||
del[int32(i*10+j+1)] = i1.Score
|
||||
del[int32(i*10+j+2)] = i2.Score
|
||||
del[int32(i*10+j+3)] = i3.Score
|
||||
@ -220,12 +224,13 @@ func (this *MapData) Check5X() (bEliminate bool, score int32) {
|
||||
}
|
||||
if len(del) > 0 {
|
||||
bEliminate = false
|
||||
fmt.Printf("5x消除格子===del:%v\n", del)
|
||||
}
|
||||
fmt.Printf("===del:%v", del)
|
||||
|
||||
return
|
||||
}
|
||||
func (this *MapData) Check4X() (bEliminate bool, score int32) {
|
||||
bEliminate = false
|
||||
bEliminate = true
|
||||
del := make(map[int32]int32)
|
||||
for i := 0; i < Width; i++ {
|
||||
for j := 0; j < Height; j++ {
|
||||
@ -234,7 +239,7 @@ func (this *MapData) Check4X() (bEliminate bool, score int32) {
|
||||
if iType == 0 {
|
||||
continue
|
||||
}
|
||||
if j+3 < Height {
|
||||
if i+3 < Width {
|
||||
i1 := this.Data[int32((i+1)*10+j)]
|
||||
i2 := this.Data[int32((i+2)*10+j)]
|
||||
i3 := this.Data[int32((i+3)*10+j)]
|
||||
@ -243,9 +248,10 @@ func (this *MapData) Check4X() (bEliminate bool, score int32) {
|
||||
del[int32((i+2)*10+j)] = i2.Score
|
||||
del[int32((i+3)*10+j)] = i3.Score
|
||||
del[key] = this.Data[key].Score
|
||||
|
||||
}
|
||||
}
|
||||
if i+3 < Width {
|
||||
if j+3 < Height {
|
||||
i1 := this.Data[int32(i*10+j+1)]
|
||||
i2 := this.Data[int32(i*10+j+2)]
|
||||
i3 := this.Data[int32(i*10+j+3)]
|
||||
@ -254,6 +260,7 @@ func (this *MapData) Check4X() (bEliminate bool, score int32) {
|
||||
del[int32(i*10+j+2)] = i2.Score
|
||||
del[int32(i*10+j+3)] = i3.Score
|
||||
del[key] = this.Data[key].Score
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -264,9 +271,10 @@ func (this *MapData) Check4X() (bEliminate bool, score int32) {
|
||||
score += v
|
||||
}
|
||||
if len(del) > 0 {
|
||||
bEliminate = true
|
||||
bEliminate = false
|
||||
fmt.Printf("4x消除格子===del:%v\n", del)
|
||||
}
|
||||
fmt.Printf("===del:%v", del)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@ -280,7 +288,8 @@ func (this *MapData) Check3X() (bEliminate bool, score int32) {
|
||||
if iType == 0 {
|
||||
continue
|
||||
}
|
||||
if j+2 < Height {
|
||||
|
||||
if i+2 < Width {
|
||||
i1 := this.Data[int32((i+1)*10+j)]
|
||||
i2 := this.Data[int32((i+2)*10+j)]
|
||||
if i1.Itype == i2.Itype && i1.Itype == iType {
|
||||
@ -289,7 +298,7 @@ func (this *MapData) Check3X() (bEliminate bool, score int32) {
|
||||
del[key] = i1.Score
|
||||
}
|
||||
}
|
||||
if i+2 < Width {
|
||||
if j+2 < Height {
|
||||
i1 := this.Data[int32(i*10+j+1)]
|
||||
i2 := this.Data[int32(i*10+j+2)]
|
||||
if i1.Itype == i2.Itype && i1.Itype == iType {
|
||||
@ -307,12 +316,12 @@ func (this *MapData) Check3X() (bEliminate bool, score int32) {
|
||||
}
|
||||
if len(del) > 0 {
|
||||
bEliminate = false
|
||||
fmt.Printf("3x消除格子===del:%v\n", del)
|
||||
}
|
||||
fmt.Printf("===del:%v", del)
|
||||
return
|
||||
}
|
||||
|
||||
func (this *MapData) CheckSwape() (bEliminate bool) {
|
||||
func (this *MapData) CheckSwape(g1, g2 int32) (bEliminate bool) {
|
||||
|
||||
for i := 0; i < Width; i++ {
|
||||
for j := 0; j < Height; j++ {
|
||||
@ -322,45 +331,70 @@ func (this *MapData) CheckSwape() (bEliminate bool) {
|
||||
continue
|
||||
}
|
||||
if j+2 < Height {
|
||||
i1 := this.Data[int32((i+1)*10+j)]
|
||||
i2 := this.Data[int32((i+2)*10+j)]
|
||||
k1 := int32((i+1)*10 + j)
|
||||
k2 := int32((i+2)*10 + j)
|
||||
i1 := this.Data[k1]
|
||||
i2 := this.Data[k2]
|
||||
if i1.Itype == i2.Itype && i1.Itype == iType {
|
||||
if g1 == key || k1 == g1 || k2 == g1 ||
|
||||
g2 == key || k1 == g2 || k2 == g2 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
if i+2 < Width {
|
||||
i1 := this.Data[int32(i*10+j+1)]
|
||||
i2 := this.Data[int32(i*10+j+2)]
|
||||
k1 := int32(i*10 + j + 1)
|
||||
k2 := int32(i*10 + j + 2)
|
||||
i1 := this.Data[k1]
|
||||
i2 := this.Data[k2]
|
||||
if i1.Itype == i2.Itype && i1.Itype == iType {
|
||||
if g1 == key || k1 == g1 || k2 == g1 ||
|
||||
g2 == key || k1 == g2 || k2 == g2 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 校验地图可消除的 判断各组上面2个和右边两个是否三个相等
|
||||
func (this *MapData) CheckMap() (bEliminate bool, score int32) {
|
||||
func (this *MapData) CheckMap() (score int32) {
|
||||
score = 0
|
||||
if bRet, s := this.Check5X(); !bRet {
|
||||
fmt.Printf("=====检测消除5x===========\n")
|
||||
score += s
|
||||
}
|
||||
if bRet, s := this.Check4X(); !bRet {
|
||||
fmt.Printf("=====检测消除4x===========\n")
|
||||
score += s
|
||||
}
|
||||
if bRet, s := this.Check3X(); !bRet {
|
||||
fmt.Printf("=====检测消除3x===========\n")
|
||||
score += s
|
||||
}
|
||||
if score > 0 {
|
||||
bEliminate = true
|
||||
}
|
||||
//this.Debugf()
|
||||
|
||||
this.Debugf()
|
||||
return
|
||||
}
|
||||
|
||||
// 下落 生成新的格子
|
||||
func (this *MapData) DropGirde() {
|
||||
// 下落 生成新的格子 (返回掉落所获得的分数)
|
||||
func (this *MapData) DropGirde() (score int32, szMap []*pb.MapData) {
|
||||
var bDrop bool
|
||||
for {
|
||||
bDrop = false
|
||||
for _, v := range this.Data { // 校验是否有下落
|
||||
if v.Itype == 0 {
|
||||
fmt.Printf("检测有掉落\n")
|
||||
bDrop = true // 有空位置 说明可以掉落
|
||||
break
|
||||
}
|
||||
}
|
||||
if !bDrop {
|
||||
break
|
||||
}
|
||||
for i := 0; i < Width; i++ {
|
||||
for j := 0; j < Height; j++ {
|
||||
key := int32(i*10 + j)
|
||||
@ -389,7 +423,16 @@ func (this *MapData) DropGirde() {
|
||||
}
|
||||
}
|
||||
}
|
||||
//this.Debugf()
|
||||
if s := this.CheckMap(); s > 0 {
|
||||
fmt.Printf("本次掉落得分:%d\n", s)
|
||||
score += s
|
||||
szMap = append(szMap, &pb.MapData{
|
||||
Data: this.Data,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
this.Debugf()
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user