Skip to content

Commit

Permalink
peg stick fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nikfrank committed Sep 24, 2017
1 parent a9d0c1d commit cedc2a9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
30 changes: 19 additions & 11 deletions canon/crib/src/Pegging/Pegging.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ class Pegging extends Component {
// passing
ci === null
) ? (
subState.getIn(['played', -1])
.equals( fromJS({ card: {}, player: hi })) ? subState : (

subState.update('played', pl =>
pl.push( fromJS({ card: {}, player: hi }))
).set('nextToPlay', (hi + 1)%2)
)
subState
.getIn(['played', -1])
.equals( fromJS({ card: {}, player: hi })) ? subState : (

subState.update('played', pl =>
pl.push( fromJS({ card: {}, player: hi }))
).set('nextToPlay',
subState.getIn(['hands', (hi + 1)%2]).size ?
(hi + 1)%2 : (hi + 2)%2
)
)
) : (

// block stack tipping
Expand Down Expand Up @@ -116,17 +120,21 @@ class Pegging extends Component {
const played = nuProps.subState.get('played');
const prevPlayed = this.props.subState.get('played');

if( played === prevPlayed ) return;

if ( !played.size ) return;


const { score, player, count, stack } = pegScore( played.toJS() );

const passes = stack.reduce( (p, c) => (c.card.rank? 0 : p+1) , 0);


if( played === prevPlayed )
return;

if ( !played.size ) return;

if ( score )
this.props.onScoringEvent({ player, type: 'peg', pts: score });

const passes = stack.reduce( (p, c) => (c.card.rank? 0 : p+1) , 0);

// if all the cards are played, onComplete
if ( nuProps.subState.getIn(['hands', 0]).size +
Expand Down
7 changes: 7 additions & 0 deletions canon/crib/src/Pegging/Pegging.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,10 @@ it('disallows stack tipping', () => {

}) )
});


// test where
// p, c, p, p || c, p, c || c

// the third round sticks because p1 is expected to play, but cant
// bug is fixed but untested (see null section in playcard hand.size? nextP : sameP

0 comments on commit cedc2a9

Please sign in to comment.