diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..105d60d --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +# Go parameters +GOCMD=GO111MODULE=on go +GOBUILD=$(GOCMD) build +GOTEST=$(GOCMD) test + + +all: build +build: + rm -rf target/ + mkdir target/ + cp etc/config.toml target/config.toml + $(GOBUILD) -o target/texas cmd/main.go + +clean: + rm -rf target/ + +run: + nohup target/texas -conf=target/config.toml -region=sh -zone=sh001 -deploy.env=dev -weight=10 2>&1 > target/texas.log & + +stop: + pkill -f target/texas diff --git a/README.md b/README.md index 3b05201..ceeb83a 100644 --- a/README.md +++ b/README.md @@ -14,18 +14,5 @@ pbjs -t json api/*.proto > jsproto.json ``` -## game process -1. player join (检查筹码...) -2. player ready -3. table begin 发牌 -4. 开始流程,大盲注 小盲注 - - [网易德州扑克规则](http://sports.163.com/special/poker_rule/?ivk_sa=1025883k) -跟注规则: -小盲注:房主下一个 -大盲注:房主下下一个 -跟注/加注:大盲注下一个 - -只有两人:第一轮小盲注先,后续大盲注先下注 diff --git a/internal/game/table.go b/internal/game/table.go index 4e53875..df68243 100644 --- a/internal/game/table.go +++ b/internal/game/table.go @@ -225,44 +225,6 @@ func (t *Table) NoticeAllPlayer(message proto.Message) { } } -// RoundOver 当前回合结束 -func (t *Table) RoundOver() error { - // 游戏结束,开牌结算 - if t.Stage == 5 || 1 == len(collect.Filter(t.Players, func(i int, p *Player) bool { - return p != nil && p.Status != 7 - })) { - return t.cardFightAndSettle() - } - - // 开启下一回合, 根据回合发公共牌 - switch t.Stage { - case 2: // 发3张公共牌(翻牌) - t.Stage = 3 - for i := 0; i < 5; i++ { - if i < 3 { - t.PublicCards[i] = t.Dealer.Deal() - continue - } - // 第4,5张牌置空 - t.PublicCards[i] = nil - } - case 3: // 发第4张公共牌(转牌turn) - t.Stage = 4 - t.PublicCards[3] = t.Dealer.Deal() - case 4: // 发第5张公共牌(河牌river) - t.Stage = 5 - t.PublicCards[4] = t.Dealer.Deal() - } - - // 重置一些状态 - t.LastPosBetChip = 0 - t.RoundRaiseTimes = 0 - - // 由小盲注或小盲注后第一个未弃牌玩家开始 - t.SetNextPlayerWithRoundStart() - return nil -} - // SetNextPlayerWithRoundStart 回合开始, 设置下一个下注玩家 func (t *Table) SetNextPlayerWithRoundStart() { nextPos := t.SmallBlindPos @@ -389,6 +351,44 @@ func (t *Table) SetNextPlayer(current int) { } } +// RoundOver 当前回合结束 +func (t *Table) RoundOver() error { + // 游戏结束,开牌结算 + if t.Stage == 5 || 1 == len(collect.Filter(t.Players, func(i int, p *Player) bool { + return p != nil && p.Status != 7 + })) { + return t.cardFightAndSettle() + } + + // 开启下一回合, 根据回合发公共牌 + switch t.Stage { + case 2: // 发3张公共牌(翻牌) + t.Stage = 3 + for i := 0; i < 5; i++ { + if i < 3 { + t.PublicCards[i] = t.Dealer.Deal() + continue + } + // 第4,5张牌置空 + t.PublicCards[i] = nil + } + case 3: // 发第4张公共牌(转牌turn) + t.Stage = 4 + t.PublicCards[3] = t.Dealer.Deal() + case 4: // 发第5张公共牌(河牌river) + t.Stage = 5 + t.PublicCards[4] = t.Dealer.Deal() + } + + // 重置一些状态 + t.LastPosBetChip = 0 + t.RoundRaiseTimes = 0 + + // 由小盲注或小盲注后第一个未弃牌玩家开始 + t.SetNextPlayerWithRoundStart() + return nil +} + // cardFightAndSettle 斗牌并结算 func (t *Table) cardFightAndSettle() error { var winners []*Player = nil @@ -470,7 +470,13 @@ func (t *Table) cardFightAndSettle() error { t.Chip = 0 } - // 玩家置为待操作状态 + // 斗牌结束, 玩家置为待操作状态 + for _, p := range t.Players { + if p != nil { + p.WaitBet() + p.SetStatus(8) + } + } // 手牌: stage(1,2) other // 1.展示其他玩家手牌(组合牌型) diff --git a/internal/service/auth.go b/internal/service/auth.go index a0c29cc..107eb4b 100644 --- a/internal/service/auth.go +++ b/internal/service/auth.go @@ -178,7 +178,7 @@ func HandleReqIdentity(client *session.NetClient, msg *api.ReqIdentity) (proto.M subject, err := DecodeSubject(msg.Token) if err != nil { // client.Close("authorize failed!") - return nil, err + return &api.ResFail{Code: 401, Msg: err.Error()}, nil } account := &session.NetAccount{ diff --git a/internal/service/table.go b/internal/service/table.go index 15ec517..57ed440 100644 --- a/internal/service/table.go +++ b/internal/service/table.go @@ -247,11 +247,14 @@ func HandleReqGameFullStatus(player *game.Player, msg *api.ReqGameFullStatus) (p } resGame := player.GameTable.BuildResGameFullStatus() resGame.PlayerId = player.Id + gameEnd := collect.In(player.GameTable.Stage, 1, 7, 9) // 其他玩家手牌不返回,TODO 计算自己的5张推荐牌 - for _, p := range resGame.Players { - if p != nil && p.Id != player.Id { - p.HandCard[0] = nil - p.HandCard[1] = nil + if !gameEnd { + for _, p := range resGame.Players { + if p != nil && p.Id != player.Id { + p.HandCard[0] = nil + p.HandCard[1] = nil + } } } return resGame, nil @@ -264,7 +267,7 @@ func HandleReqReadyStart(player *game.Player, msg *api.ReqReadyStart) (proto.Mes if player.Id == player.GameTable.MasterId { return &api.ResFail{Msg: "房主不用准备"}, nil } - if player.Status != 1 { + if !collect.In(player.Status, 1, 8) { msg := "" switch player.Status { case 2: @@ -299,7 +302,7 @@ func HandleReqCancelReady(player *game.Player, msg *api.ReqCancelReady) (proto.M func HandleReqDismissGameTable(player *game.Player, msg *api.ReqDismissGameTable) (proto.Message, error) { player.GameTable.Lock.Lock() defer player.GameTable.Lock.Unlock() - if player.GameTable.Stage != 1 { + if !collect.In(player.GameTable.Stage, 1, 7) { return &api.ResFail{Msg: fmt.Sprintf("#%d,牌局进行中", player.GameTable.Stage)}, nil } player.GameTable.Stage = 9 @@ -336,7 +339,7 @@ func HandleReqGameStart(player *game.Player, msg *api.ReqGameStart) (proto.Messa if player.Id != table.MasterId { return &api.ResFail{Msg: "你不是房主"}, nil } - if table.Stage != 1 { + if !collect.In(table.Stage, 1, 7) { return &api.ResFail{Msg: fmt.Sprintf("牌局状态有误%d", table.Stage)}, nil } // 检查所有玩家准备状态 @@ -436,6 +439,9 @@ func HandleReqBetting(player *game.Player, msg *api.ReqBetting) (proto.Message, if !collect.In(msg.BetType, player.BetOpts...) { return &api.ResFail{Msg: fmt.Sprintf("当前不可执行该操作#%d", msg.BetType)}, nil } + if !collect.In(player.GameTable.Stage, 2, 3, 4, 5) { + return &api.ResFail{Msg: fmt.Sprintf("当前阶段不可下注#%d", msg.BetType)}, nil + } // 投注结束广播牌桌状态 defer player.GameTable.NoticeGameFullStatus() @@ -491,11 +497,11 @@ func HandleReqBetting(player *game.Player, msg *api.ReqBetting) (proto.Message, betNotice.Line1 = fmt.Sprintf("+%d", msg.BetChip) if playerBettingChip == player.BetMin { - betNotice.Line2 = "跟注" + betNotice.Line2 = fmt.Sprintf("跟注%d", player.BetMin) } else { betNotice.Line2 = fmt.Sprintf("加注:%d", msg.BetChip-player.BetMin) if player.BetMin > 0 { - betNotice.Line2 = fmt.Sprintf("跟注:%d", player.BetMin) + betNotice.Line3 = fmt.Sprintf("跟注:%d", player.BetMin) } } diff --git a/ws.html b/ws.html deleted file mode 100644 index c57723c..0000000 --- a/ws.html +++ /dev/null @@ -1,43 +0,0 @@ - - - - - websocket - - - - - - - - - \ No newline at end of file