-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moves code for shuffling and dealing to server
- Loading branch information
1 parent
a1bad7d
commit e5ac441
Showing
4 changed files
with
61 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import CONFIG from '../src/data/config.js'; | ||
import getResetDeck from '../src/data/deck.js'; | ||
import { shuffleDeck } from '../src/data/randomizing.js'; | ||
import { uid } from 'uid/single'; | ||
|
||
const serverStore = { | ||
players: [ | ||
{ | ||
id: uid(16), | ||
name: 'Dealer', | ||
isDealer: true, | ||
}, | ||
{ | ||
id: uid(16), | ||
name: 'Player 1', | ||
isDealer: false, | ||
}, | ||
{ | ||
id: uid(16), | ||
name: 'Player 2', | ||
isDealer: false, | ||
}, | ||
{ | ||
id: uid(16), | ||
name: 'Player 3', | ||
isDealer: false, | ||
}, | ||
{ | ||
id: uid(16), | ||
name: 'Player 4', | ||
isDealer: false, | ||
}, | ||
], | ||
deck: shuffleDeck(getResetDeck()), | ||
}; | ||
|
||
export const resetShuffleAndDeal = () => { | ||
const shuffledResetDeck = shuffleDeck(getResetDeck()); | ||
const players = serverStore.players.filter(player => !player.isDealer); | ||
const numberOfPlayers = players.length; | ||
const numberOfCards = Math.floor(CONFIG.CARDS_IN_DECK / numberOfPlayers); | ||
const numberOfCardsToDeal = numberOfCards * numberOfPlayers; | ||
[...new Array(numberOfCardsToDeal).keys()].forEach(i => { | ||
const playerIndex = Math.floor(i / numberOfCards); | ||
shuffledResetDeck[i].player = players[playerIndex].id; | ||
}); | ||
serverStore.deck = shuffledResetDeck; | ||
}; | ||
|
||
export default serverStore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters