| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- package gamelogic
- import "bet24.com/log"
- const (
- GAMEID = 42
- GAME_NAME = "spinplay"
- CHAIR_COUNT = 4
- )
- const (
- CMD_ROOMINFO = "CMD_ROOMINFO"
- CMD_TABLECHAT = "CMD_TABLECHAT"
- CMD_ACTION = "CMD_ACTION"
- CMD_ACTION_FAILED = "CMD_ACTION_FAILED"
- CMD_CANCLE_AUTO = "CMD_CANCLE_AUTO"
- CMD_AUTO = "CMD_AUTO"
- )
- const (
- ScoreType_Bet = 0
- ScoreType_End = 1
- ScoreType_Return = 2
- ScoreType_Flee = 3
- )
- // 定时器时间
- const (
- SEC_READY = 60 * 1000 //准备计时
- SEC_AUTO = 800
- SEC_DELAY = 1500
- SEC_START_ACTION = 2000
- SEC_ROBBANKER_TO_ROUND_END = 1000
- SEC_ACTION_TO_ROUND_END = 1000
- SEC_COMPARE_TO_ROUND_END = 4000
- SEC_KICK_USER = 60000
- )
- const (
- TIMER_READY_0 = iota
- TIMER_READY_1
- TIMER_READY_2
- TIMER_READY_3
- TIMER_ADD_ROBOT
- TIMER_REMOVE_ROBOT
- TIMER_ROBOT_0
- TIMER_ROBOT_1
- TIMER_ROBOT_2
- TIMER_ROBOT_3
- TIMER_AUTO_ACTION_0
- TIMER_AUTO_ACTION_1
- TIMER_AUTO_ACTION_2
- TIMER_AUTO_ACTION_3
- TIMER_GAME
- TIMER_START_GAME
- TIMER_START_ACTION
- TIMER_ROUND_END
- TIMER_KICK_USER_0
- TIMER_KICK_USER_1
- TIMER_KICK_USER_2
- TIMER_KICK_USER_3
- )
- const (
- Phase_Free = iota // 空闲阶段
- Phase_JackPot // 开奖阶段
- Phase_SendCard // 发牌阶段
- Phase_RobBanker // 抢庄阶段
- Phase_ConfirmBanker // 确认庄家阶段
- Phase_Action // 庄闲动作
- Phase_CompareCard // 比牌阶段
- Phase_RoundEnd // 小结算
- Phase_End // 大结算
- )
- const (
- ActionPhase_Banker_GiveMoney = iota // 庄闲动作之庄家给钱
- ActionPhase_Player_Reply // 庄闲动作之闲家回应
- ActionPhase_Banker_Reply // 庄闲动作之庄家回应
- )
- const (
- Action_RobBanker = iota
- Action_Banker_GiveMoney // 庄家给钱
- Action_Banker_CompareCardDirect // 庄家直接比牌
- Action_Player_CompareCard // 玩家不要钱直接比牌
- Action_Player_Agree // 玩家同意给的钱
- Action_Player_AddMoney // 玩家加钱
- Action_Banker_Agree // 庄家同意加钱
- Action_Banker_DisAgree // 庄家不同意加钱,要比牌
- )
- const (
- Player_Status_Free = iota
- Player_Status_Play
- Player_Status_GiveUp
- Player_Status_AllIn
- Player_Status_CompareCard
- )
- func isValidChair(chairId int) bool {
- return chairId >= 0 && chairId < CHAIR_COUNT
- }
- func getPreviousChair(chair int) int {
- return (chair + CHAIR_COUNT - 1) % CHAIR_COUNT
- }
- type CmdAction struct {
- Action int
- Param int
- }
- type userAction struct {
- action int
- data string
- }
- func (u *userAction) dump() {
- log.Release("action[%d] data[%s]", u.action, u.data)
- }
- // 玩家动作失败
- type CmdActionFailed struct {
- CmdAction
- ErrMsg string
- }
- type cardStruct struct {
- cardType int
- cards []int
- fourValue int
- threeValue int
- pair1Value int
- pair2Value int
- }
- func (cs *cardStruct) analyzeStruct() {
- if len(cs.cards) != HOLD_CARD_COUNT {
- return
- }
- if isFour(cs.cards) {
- cs.cardType = CardType_Four
- cs.fourValue = getCardValue(cs.cards[0])
- return
- }
- if value, ret := isThree(cs.cards); ret {
- cs.cardType = CardType_Three
- cs.threeValue = value
- return
- }
- if value1, value2, ret := isDoublePair(cs.cards); ret {
- cs.cardType = CardType_DoublePair
- cs.pair1Value = value1
- cs.pair2Value = value2
- return
- }
- if value, ret := isPair(cs.cards); ret {
- cs.cardType = CardType_Pair
- cs.pair1Value = value
- return
- }
- cs.cardType = CardType_SanPai
- }
- func getSortedCards(cards []int) [][]int {
- sortedCards := make([][]int, 4)
- for i := 0; i < len(cards); i++ {
- v := getCardValue(cards[i])
- sortedCards[v] = append(sortedCards[v], cards[i])
- }
- return sortedCards
- }
- func isFour(cards []int) bool {
- cardList := getSortedCards(cards)
- for i := 0; i < 4; i++ {
- if len(cardList[i]) == 4 {
- return true
- }
- }
- return false
- }
- func isThree(cards []int) (int, bool) {
- cardList := getSortedCards(cards)
- for i := 0; i < 4; i++ {
- if len(cardList[i]) == 3 {
- return i, true
- }
- }
- return 0, false
- }
- func isDoublePair(cards []int) (int, int, bool) {
- cardList := getSortedCards(cards)
- pairCount := 0
- for i := 0; i < 4; i++ {
- if len(cardList[i]) == 2 {
- pairCount++
- }
- }
- if pairCount != 2 {
- return 0, 0, false
- }
- v1, v2 := -1, -1
- for i := 0; i < 4; i++ {
- if len(cardList[i]) == 2 {
- if v1 == -1 {
- v1 = i
- }
- v2 = i
- }
- }
- return v2, v1, true
- }
- func isPair(cards []int) (int, bool) {
- cardList := getSortedCards(cards)
- for i := 0; i < 4; i++ {
- if len(cardList[i]) == 2 {
- return i, true
- }
- }
- return 0, false
- }
- func getHandCardType(cards []int) int {
- if len(cards) != HOLD_CARD_COUNT {
- return -1
- }
- if isFour(cards) {
- return CardType_Four
- }
- if _, ret := isThree(cards); ret {
- return CardType_Three
- }
- if _, _, ret := isDoublePair(cards); ret {
- return CardType_DoublePair
- }
- if _, ret := isPair(cards); ret {
- return CardType_Pair
- }
- return CardType_SanPai
- }
- func getCardStruct(cards []int) *cardStruct {
- var c cardStruct
- c.cards = append(c.cards, cards...)
- c.analyzeStruct()
- return &c
- }
- const (
- CardType_SanPai = iota
- CardType_Pair
- CardType_DoublePair
- CardType_Three
- CardType_Four
- )
- func isBigger(cards1, cards2 []int) bool {
- c1 := getCardStruct(cards1)
- c2 := getCardStruct(cards2)
- if c1.cardType > c2.cardType {
- return true
- }
- if c1.cardType == c2.cardType {
- switch c1.cardType {
- case CardType_Four:
- return c1.fourValue > c2.fourValue
- case CardType_Three:
- return c1.threeValue > c2.threeValue
- case CardType_DoublePair:
- if c1.pair1Value > c2.pair1Value {
- return true
- } else if c1.pair1Value == c2.pair1Value {
- return c1.pair2Value > c2.pair2Value
- }
- case CardType_Pair:
- if c1.pair1Value > c2.pair1Value {
- return true
- } else if c1.pair1Value == c2.pair1Value {
- cardList1 := []int{}
- cardList2 := []int{}
- for i := 0; i < len(cards1); i++ {
- if getCardValue(cards1[i]) != c1.pair1Value {
- cardList1 = append(cardList1, cards1[i])
- }
- }
- for i := 0; i < len(cards2); i++ {
- if getCardValue(cards2[i]) != c1.pair1Value {
- cardList2 = append(cardList2, cards2[i])
- }
- }
- for i := 0; i < len(cardList1); i++ {
- if getCardValue(cardList1[i]) > getCardValue(cardList2[i]) {
- return true
- }
- }
- }
- }
- }
- return false
- }
- func isEqual(cards1, cards2 []int) bool {
- for i := 0; i < len(cards1); i++ {
- if getCardValue(cards1[i]) != getCardValue(cards2[i]) {
- return false
- }
- }
- return true
- }
|