On Mon, Jul 12, 2010 at 12:49 PM, qin ding <qindi...@yahoo.com> wrote:
> I am learning commons scxml.  I am experimenting writing a poker game using
> activemq and scxml.
>
>
> So, I have my config xml defined as follows:
>
> <?xml version="1.0"?>
> <scxml xmlns="http://www.w3.org/2005/07/scxml";
>        version="1.0"
>        initialstate="waitingRound">
>     <datamodel>
>         <data name="inputPlayer">
>           <!-- Note namespace declaration in line below -->
>           <player xmlns="com.mgt.lottery.poker.domain">
>             <id/>
>             <name/>
>             <chips/>
>             <sitin/>
>             <winner/>
>             <betOption/>
>             <gainedChips/>
>             <popocketCards/>
>             <description/>
>             <bestHand/>
>           </player>
>         </data>
>     </datamodel>
>     <state id="waitingRound">
>         <!-- shuffle deck and check players and empty pot -->
>         <transition event="game.start" target="preflopRound"/>
>     </state>
>     <state id="preflopRound">
>         <!-- place small/big blinds in pot and deal each player two hole cards
> -->
>         <transition target="firstBettingRound"/>
>     </state>
>     <state id="firstBettingRound">
>         <transition event="game.flop" target="flopRound"/>
>         <transition event="game.showdown" target="showdownRound"/>
>     </state>
>     <state id="flopRound">
>         <!-- deal three cards in the community -->
>         <transition target="secondBettingRound"/>
>     </state>
>     <state id="secondBettingRound">
>         <onentry>
>             <var name="inputPlayer" expr="#{request$player}" />
>         </onentry>
>         <transition event="game.turn" target="turnRound"/>
>         <transition event="game.showdown" target="showdownRound"/>
>     </state>
>     <state id="turnRound">
>         <!-- deal a 4th card in the community -->
>         <transition target="thirdBettingRound"/>
>     </state>
>     <state id="thirdBettingRound">
>         <!-- deal a 4th card in the community -->
>         <onentry>
>             <var name="inputPlayer" expr="#{request$player}" />
>         </onentry>
>         <transition event="game.final" target="finalRound"/>
>         <transition event="game.showdown" target="showdownRound"/>
>     </state>
>     <state id="finalRound">
>         <!-- deal a 5th card in the community -->
>         <transition target="finalBettingRound"/>
>     </state>
>     <state id="finalBettingRound">
>         <!-- bet, check, call, raise, or fold -->
>         <onentry>
>             <var name="inputPlayer" expr="#{request$player}" />
>         </onentry>
>         <transition event="game.showdown" target="showdownRound"/>
>     </state>
>     <state id="showdownRound">
>         <transition event="game.reset" target="waitingRound"/>
>     </state>
> </scxml>
>
> My questions:
> How can I pass my pojo "Player" to the firstBettingRound, secondBettingRound 
> and
> etc? This player object is coming from game client with betting information.
>
<snip/>

Data (including POJOs) can be passed into an executor either via an
external event's payload or via procedural injection to the executor's
root context.

So, as an example of the latter, the following will create a variable
"player" in the executor's root context and bind the POJO to it:

  Player p = ... // POJO from game client
  getEngine().getRootContext().set("player", p);

Subsequently, the variable "player" may be used in expressions in the
state machine.

In the above state machine, the variable "inputPlayer" doesn't seem to
be accessed anywhere, so unless the player information is needed for
the state machine logic, it can perhaps stay out of the state
machine's root context altogether (given the pattern of use you
mention below).


> After the activemq delivers it to the server end,  how can I know which method
> to call?  I think scxml handles the the state of game, so I have to say
>
>
> Set states = getEngine().getCurrentStatus().getStates();
>         return ((org.apache.commons.scxml.model.State) states.iterator().
>                 next()).getId();
>
> if the current state is firstBettingRound,  I do
> game.firstBettingRound(player);  Is it correct
>
<snap/>

If you wanted to map states to activities that way. There are a few
patterns that are commonly used, see:

  http://commons.apache.org/scxml/guide/using-commons-scxml.html

-Rahul


> I seem unable to find the example to show me how to pass pojo to the state
> correcponded method.  If I am completely wrong with my approach, Please 
> advise.
> Thank you very much.
>
> QD
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org

Reply via email to