示例#1
0
        internal void bet(Slot slot, TexasBetRequest texasBetRequest)
        {
            betInternal(slot, texasBetRequest);
            this.PrevPlayer = slot;
            Log.DebugFormat("DONE BET, PREV PLAYER = " + this.PrevPlayer.UserKey);
            int  slotIndex  = getSlotIndex(slot);
            Slot nextPlayer = getNextPlayer(slotIndex + 1);

            updateTimeForThink(nextPlayer);
            if (nextPlayer == this.Starter)
            {
                calcPot();
                // update state
                this.TableState++;
                // reset new bet
                this.CurrentBet = 0;
                // add to pot on table
                this.ChipPots.Add(this.currentChipPot);
                // create new pot
                this.currentChipPot = new ChipPot();

                // clear new prevPlayer
                this.PrevPlayer = null;
                Log.DebugFormat("Next State: " + this.TableState);
            }
            this.CurrentPlayer = nextPlayer;
            Log.DebugFormat("DONE BET, CURRENT PLAYER = " + this.CurrentPlayer.UserKey);
            if (this.TableState > 6)
            {
                // handle and game
                return;
            }
        }
示例#2
0
        private void betInternal(Slot slot, TexasBetRequest texasBetRequest)
        {
            Log.DebugFormat("BET INFO: UserKey:" + texasBetRequest.UserKey + " BetType:" + texasBetRequest.BetType + " Amount:" + texasBetRequest.amount
                            + " CurrentCredit:" + slot.CurrentCredit + " CurrentBet:" + slot.CurrentBet + " getCurrentBet:" + this.getCurrentBet() + " SmallBlind:"
                            + this.SmallBlindValue);

            // if fold
            if (texasBetRequest.BetType == (int)BetTypeCode.Fold)
            {
                fold(slot);
                return;
            }
            // if not enought money to bet. force all in
            if (slot.CurrentCredit + slot.CurrentBet < getCurrentBet() + SmallBlindValue)
            {
                // force all in
                allIn(slot);
                return;
            }
            // all in
            if (texasBetRequest.BetType == (int)BetTypeCode.AllIn)
            {
                allIn(slot);
                return;
            }
            // not amount
            if (texasBetRequest.amount == 0) // check
            {
                if (getCurrentBet() > 0)
                {
                    call(slot);
                    return;
                }
                check(slot);
                return;
            }
            // out of current credit
            if (texasBetRequest.amount >= slot.CurrentCredit)
            {
                allIn(slot);
                return;
            }
            // 0 < amount < slot.getCurrentCredit
            if (getCurrentBet() == 0)
            {
                bet(slot, texasBetRequest.amount);
                return;
            }
            if (getCurrentBet() >= slot.CurrentBet + texasBetRequest.amount)
            {
                call(slot);
                return;
            }
            raise(slot, texasBetRequest.amount);
        }
示例#3
0
        private void timeForThinkCallBack(object s)
        {
            Log.DebugFormat("TIMER STEP CALLBACK");
            if (this.CurrentPlayer == null)
            {
                return;
            }
            TexasBetRequest texasBetRequest = new TexasBetRequest();

            texasBetRequest.amount  = 0;
            texasBetRequest.BetType = (int)BetTypeCode.Fold;
            texasBetRequest.UserKey = this.CurrentPlayer.UserKey;
            bet(this.CurrentPlayer, texasBetRequest);
            Log.DebugFormat("TIMER STEP END CALLBACK");
        }
示例#4
0
        public override void Execute(INotification notification)
        {
            TexasBetRequest texasBetRequest = notification.Body as TexasBetRequest;

            Log.DebugFormat("TEXAS BET HANDLE");
            var  texasModel    = this.Facade.RetrieveProxy(TexasModel.NAME) as TexasModel;
            Slot currentPlayer = texasModel.getCurrentPlayer();

            var roomUserModel = this.Facade.RetrieveProxy(RoomUserModel.NAME) as RoomUserModel;
            var clientData    = roomUserModel.ClientData(texasBetRequest.UserKey);
            var errorParam    = new Dictionary <byte, object>()
            {
                { (byte)ServerParameterCode.PeerId, clientData.PeerId.ToByteArray() },
            };

            if (currentPlayer == null)
            {
                var response = new Response((byte)TexasOperationCode.Bet, null, errorParam, "Current player not found", (byte)TexasServerCommon.Codes.ErrorCode.Error);
                SendNotification(RoomNotification.SEND_TO_USER, response);
                return;
            }
            if (!currentPlayer.isOnGame)
            {
                var response = new Response((byte)TexasOperationCode.Bet, null, errorParam, "Not in game", (byte)TexasServerCommon.Codes.ErrorCode.NotInGame);
                SendNotification(RoomNotification.SEND_TO_USER, response);
                return;
            }
            if (currentPlayer.Status == (int)PlayerStatusCode.Fold)
            {
                var response = new Response((byte)TexasOperationCode.Bet, null, errorParam, "Can not bet on fold", (byte)TexasServerCommon.Codes.ErrorCode.NotInGame);
                SendNotification(RoomNotification.SEND_TO_USER, response);
                return;
            }
            if (currentPlayer.UserKey != texasBetRequest.UserKey)
            {
                var response = new Response((byte)TexasOperationCode.Bet, null, errorParam, "Not current player", (byte)TexasServerCommon.Codes.ErrorCode.NotCurrentPlayer);
                SendNotification(RoomNotification.SEND_TO_USER, response);
                return;
            }

            texasModel.bet(currentPlayer, texasBetRequest);

            // send min bet
            sendMinBets(texasModel);

            sendThinkingPlayer(texasModel);
        }
示例#5
0
        public override bool OnHandleMessage(IMessage message, IServerPeer sPeer)
        {
            Log.DebugFormat("OnHandleMessage:TexasBetHandler");

            var errorParam = new Dictionary <byte, object>
            {
                { (byte)ServerParameterCode.PeerId, message.Parameters[(byte)ServerParameterCode.PeerId] },
                { (byte)ClientParameterCode.SubOperationCode, message.Parameters[(byte)ClientParameterCode.SubOperationCode] },
            };

            var serverPeer = sPeer as ServerOutbouncePeer;
            var operation  = new BetOperator(serverPeer.Protocol, message);

            if (!operation.IsValid)
            {
                serverPeer.SendMessage(new Response((byte)TexasOperationCode.Bet, null, errorParam, operation.GetErrorMessage(), (int)RoomErrorCode.OperationInvalid));
                return(false);
            }
            var peerId = new Guid((Byte[])operation.PeerId);

            var roomID = operation.RoomID;

            errorParam.Add((byte)RoomParameterCode.RoomID, roomID);
            var facade = TexasApplication.GetRoom(roomID);

            if (facade == null)
            {
                serverPeer.SendMessage(new Response((byte)TexasOperationCode.Bet, null, errorParam, "RoomId Not Found", (int)RoomErrorCode.RoomIdNotFound));
                return(false);
            }
            var userItem = TexasApplication.GetRoomUser(roomID, peerId);

            if (userItem == null)
            {
                serverPeer.SendMessage(new Response((byte)TexasOperationCode.Bet, null, errorParam, "User Not Yet Join Room", (int)RoomErrorCode.UserNotYetJoinRoom));
                return(false);
            }

            TexasBetRequest texasBetRequest = JsonConvert.DeserializeObject <TexasBetRequest>(operation.TexasBetRequest);

            texasBetRequest.UserKey = userItem.UserKey;

            var stateMachine = facade.RetrieveMediator(TexasStateMachine.NAME) as TexasStateMachine;

            stateMachine.Bet(texasBetRequest);
            return(true);
        }
示例#6
0
 private void OnBet(TexasBetRequest texasBetRequest)
 {
     // Log.DebugFormat("TEXAS SIT CALLED: " + this.States.State);
     SendNotification(TexasTrigger.action_bet.ToString("G"), texasBetRequest);
 }
示例#7
0
 internal void Bet(TexasBetRequest texasBetRequest)
 {
     this.States.Fire(_betTrigger, texasBetRequest);
 }