@@ -617,3 +617,61 @@ test('endGame', () => {
617617 expect ( t . ctx . gameover ) . toBe ( 42 ) ;
618618 }
619619} ) ;
620+
621+ test ( 'change action players' , ( ) => {
622+ const flow = FlowWithPhases ( { } ) ;
623+ const state = { ctx : { } } ;
624+ const newState = flow . processGameEvent ( state , {
625+ type : 'changeActionPlayers' ,
626+ args : [ [ 1 , 2 ] ] ,
627+ } ) ;
628+ expect ( newState . ctx . actionPlayers ) . toMatchObject ( [ 1 , 2 ] ) ;
629+ } ) ;
630+
631+ test ( 'change action players - reducer' , ( ) => {
632+ let game = Game ( {
633+ moves : {
634+ playMilitia : ( G , ctx ) => {
635+ // change which players need to act
636+ ctx . events . changeActionPlayers ( [ 1 , 2 , 3 ] ) ;
637+ return { ...G , playedCard : 'Militia' } ;
638+ } ,
639+ dropCards : ( G , ctx ) => {
640+ if ( G . playedCard === 'Militia' ) {
641+ let actedOnMilitia = G . actedOnMilitia || [ ] ;
642+ actedOnMilitia . push ( ctx . playerID ) ;
643+
644+ // this player did drop and must not take another action.
645+ var newActionPlayers = [ ...ctx . actionPlayers ] . filter (
646+ pn => pn !== ctx . playerID
647+ ) ;
648+ ctx . events . changeActionPlayers ( newActionPlayers ) ;
649+
650+ let playedCard = G . playedCard ;
651+ if ( actedOnMilitia . length === 3 ) {
652+ ctx . events . changeActionPlayers ( [ 0 ] ) ;
653+ actedOnMilitia = undefined ;
654+ playedCard = undefined ;
655+ }
656+ return { ...G , actedOnMilitia, playedCard } ;
657+ } else {
658+ return G ;
659+ }
660+ } ,
661+ } ,
662+ } ) ;
663+
664+ const reducer = createGameReducer ( { game, numPlayers : 4 } ) ;
665+
666+ let state = reducer ( undefined , { type : 'init' } ) ;
667+ state = reducer ( state , makeMove ( 'playMilitia' ) ) ;
668+ expect ( state . ctx . actionPlayers ) . toMatchObject ( [ 1 , 2 , 3 ] ) ;
669+
670+ state = reducer ( state , makeMove ( 'dropCards' , undefined , 1 ) ) ;
671+ expect ( state . ctx . actionPlayers ) . toMatchObject ( [ 2 , 3 ] ) ;
672+ state = reducer ( state , makeMove ( 'dropCards' , undefined , 3 ) ) ;
673+ expect ( state . ctx . actionPlayers ) . toMatchObject ( [ 2 ] ) ;
674+ state = reducer ( state , makeMove ( 'dropCards' , undefined , 2 ) ) ;
675+ expect ( state . ctx . actionPlayers ) . toMatchObject ( [ 0 ] ) ;
676+ expect ( state . G ) . toMatchObject ( { } ) ;
677+ } ) ;
0 commit comments