Example #1
0
 public TexasModel() : base(NAME)
 {
     initCard();
     initDefaultValue();
     TexasRoomUsers = new Dictionary <string, TexasRoomUser>();
     initSlot();
     thinkingTimer = new TimerQueue(1);
     thinkingTimer.Initialize();
 }
        public void TestTimer()
        {
            var timerQueue = new TimerQueue(10);

            timerQueue.Initialize();

            stack.Push("13000");
            stack.Push("9000");
            stack.Push("4000");
            stack.Push("8000");
            stack.Push("5000");
            stack.Push("2000");

            timerQueue.SetTimer(CallMeBack, "5000", 5000);
            timerQueue.SetTimer(CallMeBack, "2000", 2000);
            timerQueue.SetTimer(CallMeBack, "8000", 8000);

            Thread.Sleep(15000);

            timerQueue.SetTimer(CallMeBack, "13000", 13000);
            timerQueue.SetTimer(CallMeBack, "9000", 9000);
            timerQueue.SetTimer(CallMeBack, "4000", 4000);
        }
Example #3
0
        public override void OnRegister()
        {
            Log.DebugFormat("TEXAS MACHINE IS ON REGISTERED");
            base.OnRegister();

            Queue = new TimerQueue(20);

            Queue.Initialize();

            States = new StateMachine <StateCode, TexasTrigger>(StateCode.WaitingNewGame);

            _updateSlotTrigger = States.SetTriggerParameters <Slot>(TexasTrigger.action_update_slot);
            _sitTrigger        = States.SetTriggerParameters <TexasSitDown>(TexasTrigger.action_sit);
            _betTrigger        = States.SetTriggerParameters <TexasBetRequest>(TexasTrigger.action_bet);
            _startGameTrigger  = States.SetTriggerParameters <TexasStartGame>(TexasTrigger.state_pre_flop);

            States.Configure(StateCode.WaitingNewGame)
            .OnEntry(stateChanged)
            .PermitReentry(TexasTrigger.action_sit)
            .OnEntryFrom(_sitTrigger, sitPar => OnSit(sitPar))
            .PermitReentry(TexasTrigger.action_update_slot)
            .OnEntryFrom(_updateSlotTrigger, slotPar => OnUpdateSlot(slotPar))
            .Permit(TexasTrigger.state_start_game, StateCode.StartGame)
            // .Permit(TexasTrigger.state_waiting_new_game, StateCode.WaitingNewGame)
            //.OnEntryFrom(_startGameTrigger, startPar => OnStartGame(startPar));
            ;

            States.Configure(StateCode.StartGame)
            // .OnEntry(stateChanged)
            //.OnEntryFrom(_startGameTrigger, startPar => OnStartGame(startPar))
            .PermitReentry(TexasTrigger.action_sit)
            .OnEntryFrom(_sitTrigger, sitPar => OnSit(sitPar))
            .PermitReentry(TexasTrigger.action_update_slot)
            .OnEntryFrom(_updateSlotTrigger, slotPar => OnUpdateSlot(slotPar))
            .Permit(TexasTrigger.state_play, StateCode.Play)
            //.PermitReentry(TexasTrigger.action_sit)
            //.OnEntryFrom(_sitTrigger, sitPar => OnSit(sitPar))
            //.OnEntryFrom(TexasTrigger.state_pre_flop, stateChanged)
            //.Permit(TexasTrigger.state_pre_flop, StateCode.PreFlop);
            ;

            States.Configure(StateCode.Play)
            .PermitReentry(TexasTrigger.action_sit)
            .OnEntryFrom(_sitTrigger, sitPar => OnSit(sitPar))
            .PermitReentry(TexasTrigger.action_update_slot)
            .OnEntryFrom(_updateSlotTrigger, slotPar => OnUpdateSlot(slotPar))
            .PermitReentry(TexasTrigger.action_bet)
            .OnEntryFrom(_betTrigger, betPar => OnBet(betPar))
            //.OnEntry(stateChanged)
            ;

            States.Configure(StateCode.PreFlop)
            .PermitReentry(TexasTrigger.action_sit)
            .OnEntryFrom(_sitTrigger, sitPar => OnSit(sitPar))
            .PermitReentry(TexasTrigger.action_update_slot)
            .OnEntryFrom(_updateSlotTrigger, slotPar => OnUpdateSlot(slotPar))
            .PermitReentry(TexasTrigger.action_bet)
            .OnEntryFrom(_betTrigger, betPar => OnBet(betPar))
            .OnEntry(stateChanged)
            .Permit(TexasTrigger.state_flop, StateCode.Flop);


            States.Configure(StateCode.Flop)
            .PermitReentry(TexasTrigger.action_sit)
            .OnEntryFrom(_sitTrigger, sitPar => OnSit(sitPar))
            .PermitReentry(TexasTrigger.action_update_slot)
            .OnEntryFrom(_updateSlotTrigger, slotPar => OnUpdateSlot(slotPar))
            .PermitReentry(TexasTrigger.action_bet)
            .OnEntryFrom(_betTrigger, betPar => OnBet(betPar))
            .OnEntry(stateChanged)
            .Permit(TexasTrigger.state_turn, StateCode.Turn);

            States.Configure(StateCode.Turn)
            .PermitReentry(TexasTrigger.action_sit)
            .OnEntryFrom(_sitTrigger, sitPar => OnSit(sitPar))
            .PermitReentry(TexasTrigger.action_update_slot)
            .OnEntryFrom(_updateSlotTrigger, slotPar => OnUpdateSlot(slotPar))
            .PermitReentry(TexasTrigger.action_bet)
            .OnEntryFrom(_betTrigger, betPar => OnBet(betPar))
            .OnEntry(stateChanged)
            .Permit(TexasTrigger.state_river, StateCode.River);

            States.Configure(StateCode.River)
            .PermitReentry(TexasTrigger.action_sit)
            .OnEntryFrom(_sitTrigger, sitPar => OnSit(sitPar))
            .PermitReentry(TexasTrigger.action_update_slot)
            .OnEntryFrom(_updateSlotTrigger, slotPar => OnUpdateSlot(slotPar))
            .PermitReentry(TexasTrigger.action_bet)
            .OnEntryFrom(_betTrigger, betPar => OnBet(betPar))
            .OnEntry(stateChanged)
            .Permit(TexasTrigger.state_showdown, StateCode.ShowDown);

            States.Configure(StateCode.ShowDown)
            .PermitReentry(TexasTrigger.action_sit)
            .OnEntryFrom(_sitTrigger, sitPar => OnSit(sitPar))
            .PermitReentry(TexasTrigger.action_update_slot)
            .OnEntryFrom(_updateSlotTrigger, slotPar => OnUpdateSlot(slotPar))
            .PermitReentry(TexasTrigger.action_bet)
            .OnEntryFrom(_betTrigger, betPar => OnBet(betPar))
            .OnEntry(stateChanged)
            .Permit(TexasTrigger.state_flip_card, StateCode.FlipCard);

            States.Configure(StateCode.FlipCard)
            .PermitReentry(TexasTrigger.action_sit)
            .OnEntryFrom(_sitTrigger, sitPar => OnSit(sitPar))
            .PermitReentry(TexasTrigger.action_update_slot)
            .OnEntryFrom(_updateSlotTrigger, slotPar => OnUpdateSlot(slotPar))
            .OnEntry(stateChanged)
            .Permit(TexasTrigger.state_calculating, StateCode.Calculating);

            States.Configure(StateCode.Calculating)
            .PermitReentry(TexasTrigger.action_sit)
            .OnEntryFrom(_sitTrigger, sitPar => OnSit(sitPar))
            .PermitReentry(TexasTrigger.action_update_slot)
            .OnEntryFrom(_updateSlotTrigger, slotPar => OnUpdateSlot(slotPar))
            .OnEntry(stateChanged)
            .Permit(TexasTrigger.state_done, StateCode.Done);

            States.Configure(StateCode.Done)
            .PermitReentry(TexasTrigger.action_sit)
            .OnEntryFrom(_sitTrigger, sitPar => OnSit(sitPar))
            .PermitReentry(TexasTrigger.action_update_slot)
            .OnEntryFrom(_updateSlotTrigger, slotPar => OnUpdateSlot(slotPar))
            .OnEntry(stateChanged)
            .Permit(TexasTrigger.state_waiting_new_game, StateCode.WaitingNewGame);

            States.OnUnhandledTrigger((state, trigger) =>
            {
            });

            // States.Fire(TexasTrigger.state_waiting_new_game);
            // WaitingNewGame();
            SendNotification(TexasTrigger.state_waiting_new_game.ToString("G"), null);
        }