Repository to place all the computer logic for "The Broom" game. https://the-broom.glitch.me/
npm install @juandiegombr/broom-brain
import {
getMoveToPlay,
getCardToPass,
} from '@juandiegombr/broom-brain
getMoveToPlay({ playerCards, commonCards})
getCardToPass({ playerCards, commonCards})
A card is an object with a value and a suit
const card = {
value: 7, // oneOf([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
suit: 'gold', // oneOf(['gold', 'wood', 'sword', 'heart'])
}
A move is a group of cards. They are placed in the move object, splitted in the common cards and the player cards.
const move = {
common: [
{ value: 1, suit: 'gold' },
{ value: 6, suit: 'gold' },
],
player: { value: 8, suit: 'sword' }
}
To get al valid moves depending on the common cards and the players card.
const commonCards = [
{ value: 3, suit: 'wood' },
{ value: 4, suit: 'wood' },
{ value: 2, suit: 'wood' },
{ value: 1, suit: 'gold' },
{ value: 6, suit: 'gold' },
]
const playerCards = [
{ value: 6, suit: 'sword' },
{ value: 8, suit: 'sword' },
]
getMoveToPlay({ commonCards, playerCards })
/* Output:
{
common: [
{ value: 1, suit: 'gold' },
{ value: 6, suit: 'gold' },
],
player: { value: 8, suit: 'sword' }
}
*/
In case that there are no possible move, this function gives the best card to pass.
const commonCards = [
{ value: 1, suit: 'gold' },
]
const playerCards = [
{ value: 2, suit: 'sword' },
{ value: 8, suit: 'sword' },
]
getTheBestMove({ commonCards, playerCards })
// Output: { value: 2, suit: 'sword' }