server/models/cpuPlayer.js
// Chooses cards that will be exchanged
Chooses cards that will be exchanged
Chooses cards that will be exchanged
selectCardsForExchange() {
    let cards = [];
    switch (this.cardExchangeRule.exchangeType) {
      case CardExchangeType.FREE:
      {
        let groups = this.groupCards(this.hand, false);
        for (let key of groups.keys) { 
          let currentCards = groups.groups[key];
          if (currentCards[0].value >= 11 || currentCards[0].value === 1) {
            break;
          }
          if (currentCards.length === 1 && CardHelper.findTwoOfClubs(currentCards) === undefined) {
            cards.push(currentCards[0]);
            if (cards.length === this.cardExchangeRule.exchangeCount) {
              break;
            }
          }
        }
        if (cards.length < this.cardExchangeRule.exchangeCount) {
          for (let key of groups.keys) { 
            let currentCards = groups.groups[key];
            for (let card of currentCards) { 
              if (CardHelper.findTwoOfClubs([ card ]) === undefined && cards.indexOf(card) === -1) {
                cards.push(card);
                if (cards.length === this.cardExchangeRule.exchangeCount) {
                  break;
                }
              }
            }
            if (cards.length === this.cardExchangeRule.exchangeCount) {
              break;
            }
          }
        }
        break;
      }
      case CardExchangeType.BEST:
        cards = _.takeRight(this.hand.sort(CardHelper.compareCards), this.cardExchangeRule.exchangeCount);
        break;
      case CardExchangeType.NONE:
      default:
        break;
    }
    this.generateComment(null, null, null, true);
    return cards;
  }
selectCardsForExchange ( ) { let cards = [ ] ; switch ( this . cardExchangeRule . exchangeType ) { case CardExchangeType . FREE : { let groups = this . groupCards ( this . hand , false ) ; for ( let key of groups . keys ) { let currentCards = groups . groups [ key ] ; if ( currentCards [ 0 ] . value >= 11 || currentCards [ 0 ] . value === 1 ) { break ; } if ( currentCards . length === 1 && CardHelper . findTwoOfClubs ( currentCards ) === undefined ) { cards . push ( currentCards [ 0 ] ) ; if ( cards . length === this . cardExchangeRule . exchangeCount ) { break ; } } } if ( cards . length < this . cardExchangeRule . exchangeCount ) { for ( let key of groups . keys ) { let currentCards = groups . groups [ key ] ; for ( let card of currentCards ) { if ( CardHelper . findTwoOfClubs ( [ card ] ) === undefined && cards . indexOf ( card ) === - 1 ) { cards . push ( card ) ; if ( cards . length === this . cardExchangeRule . exchangeCount ) { break ; } } } if ( cards . length === this . cardExchangeRule . exchangeCount ) { break ; } } } break ; } case CardExchangeType . BEST : cards = _ . takeRight ( this . hand . sort ( CardHelper . compareCards ) , this . cardExchangeRule . exchangeCount ) ; break ; case CardExchangeType . NONE : default : break ; } this . generateComment ( null , null , null , true ) ; return cards ; }
Chooses cards that will be exchanged
Chooses cards that will be exchanged
// Try to find single cards to give (other than two of clubs and smaller than 11) // eslint-disable-line no-restricted-syntax // Give smallest cards (other than two of clubs) // eslint-disable-line no-restricted-syntax // eslint-disable-line no-restricted-syntax