Skip to content

Commit

Permalink
convert card ids to string
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed May 11, 2024
1 parent 3b4e5d4 commit 5bbaed3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 39 deletions.
8 changes: 4 additions & 4 deletions src/services/CardDeck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import rollDice from '@brdgm/brdgm-commons/src/util/random/rollDice'
export default class CardDeck {

// special cards for setup
private static readonly CARD_2 = 2
private static readonly CARD_9 = 9
private static readonly CARD_15 = 15
private static readonly CARD_2 = '2'
private static readonly CARD_9 = '9'
private static readonly CARD_15 = '15'

private _deck : Card[]
private _reserve : Card[]
Expand Down Expand Up @@ -135,7 +135,7 @@ export default class CardDeck {

}

function moveCardToDeck(deck1: Card[], deck2: Card[], cardId: number) {
function moveCardToDeck(deck1: Card[], deck2: Card[], cardId: string) {
const cardIndex = deck1.findIndex(card => card.id == cardId)
const movedCard = deck1.splice(cardIndex, 1)[0]
deck2.unshift(movedCard)
Expand Down
6 changes: 3 additions & 3 deletions src/store/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export interface RoundTurn {
cardDeck?: CardDeckPersistence
}
export interface CardDeckPersistence {
deck: number[]
reserve: number[]
discard: number[]
deck: string[]
reserve: string[]
discard: string[]
}
16 changes: 8 additions & 8 deletions tests/unit/services/BotActions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { expect } from 'chai'

describe('BotActions', () => {
it('1,6-round1', () => {
const botActions = new BotActions(Cards.get(1), Cards.get(6),
const botActions = new BotActions(Cards.get('1'), Cards.get('6'),
1, BotFaction.TERRANS, DifficultyLevel.AUTOMA)

expect(botActions.actions.length).to.eq(2)
Expand All @@ -26,7 +26,7 @@ describe('BotActions', () => {
})

it('13/2-terrans', () => {
const botActions = new BotActions(Cards.get(13), Cards.get(2),
const botActions = new BotActions(Cards.get('13'), Cards.get('2'),
1, BotFaction.TERRANS, DifficultyLevel.AUTOMA)

expect(botActions.actions.length).to.eq(3)
Expand All @@ -46,7 +46,7 @@ describe('BotActions', () => {
})

it('13/2-xenos', () => {
const botActions = new BotActions(Cards.get(13), Cards.get(2),
const botActions = new BotActions(Cards.get('13'), Cards.get('2'),
1, BotFaction.XENOS, DifficultyLevel.AUTOMA)

expect(botActions.actions.length).to.eq(3)
Expand All @@ -66,7 +66,7 @@ describe('BotActions', () => {
})

it('13/2-taklons', () => {
const botActions = new BotActions(Cards.get(13), Cards.get(2),
const botActions = new BotActions(Cards.get('13'), Cards.get('2'),
1, BotFaction.TAKLONS, DifficultyLevel.AUTOMA)

expect(botActions.actions.length).to.eq(3)
Expand All @@ -86,7 +86,7 @@ describe('BotActions', () => {
})

it('13/2-hadsch-hallas', () => {
const botActions = new BotActions(Cards.get(13), Cards.get(2),
const botActions = new BotActions(Cards.get('13'), Cards.get('2'),
1, BotFaction.HADSCH_HALLAS, DifficultyLevel.AUTOMA)

expect(botActions.actions.length).to.eq(2)
Expand All @@ -101,7 +101,7 @@ describe('BotActions', () => {
})

it('13/2-geodens', () => {
const botActions = new BotActions(Cards.get(13), Cards.get(2),
const botActions = new BotActions(Cards.get('13'), Cards.get('2'),
1, BotFaction.GEODENS, DifficultyLevel.AUTOMA)

expect(botActions.actions.length).to.eq(3)
Expand All @@ -121,7 +121,7 @@ describe('BotActions', () => {
})

it('13/2-firaks', () => {
const botActions = new BotActions(Cards.get(13), Cards.get(2),
const botActions = new BotActions(Cards.get('13'), Cards.get('2'),
1, BotFaction.FIRAKS, DifficultyLevel.AUTOMA)

expect(botActions.actions.length).to.eq(2)
Expand All @@ -136,7 +136,7 @@ describe('BotActions', () => {
})

it('13/2-itars', () => {
const botActions = new BotActions(Cards.get(13), Cards.get(2),
const botActions = new BotActions(Cards.get('13'), Cards.get('2'),
1, BotFaction.ITARS, DifficultyLevel.AUTOMA)

expect(botActions.actions.length).to.eq(3)
Expand Down
44 changes: 22 additions & 22 deletions tests/unit/services/CardDeck.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('CardDeck', () => {
expect(cardDeck.discard.length, 'discard size').to.eq(0)

const persistence = cardDeck.toPersistence()
expect(persistence.deck.includes(9), '9 in deck').to.true
expect(persistence.deck.includes('9'), '9 in deck').to.true
})

it('new-level4', () => {
Expand All @@ -38,8 +38,8 @@ describe('CardDeck', () => {
expect(cardDeck.discard.length, 'discard size').to.eq(0)

const persistence = cardDeck.toPersistence()
expect(persistence.deck.includes(9), '9 in deck').to.true
expect(persistence.deck.includes(15), '15 in deck').to.true
expect(persistence.deck.includes('9'), '9 in deck').to.true
expect(persistence.deck.includes('15'), '15 in deck').to.true
})

it('new-level5', () => {
Expand All @@ -50,61 +50,61 @@ describe('CardDeck', () => {
expect(cardDeck.discard.length, 'discard size').to.eq(0)

const persistence = cardDeck.toPersistence()
expect(persistence.deck.includes(9), '9 in deck').to.true
expect(persistence.deck.includes(15), '15 in deck').to.true
expect(persistence.deck.includes('9'), '9 in deck').to.true
expect(persistence.deck.includes('15'), '15 in deck').to.true
})

it('draw-pass-deck-empty', () => {
const cardDeck = CardDeck.fromPersistence({
deck: [4,6,7,9],
deck: ['4','6','7','9'],
discard: [],
reserve: []
})

expect(cardDeck.draw(), '1st draw').to.true
expect(cardDeck.actionCard?.id, '1st action card').to.eq(6)
expect(cardDeck.supportCard?.id, '1st support card').to.eq(4)
expect(cardDeck.actionCard?.id, '1st action card').to.eq('6')
expect(cardDeck.supportCard?.id, '1st support card').to.eq('4')
expect(cardDeck.isPass(), '1st pass').to.false

expect(cardDeck.draw(), '2nd draw').to.true
expect(cardDeck.actionCard?.id, '2nd action card').to.eq(7)
expect(cardDeck.supportCard?.id, '2nd support card').to.eq(6)
expect(cardDeck.actionCard?.id, '2nd action card').to.eq('7')
expect(cardDeck.supportCard?.id, '2nd support card').to.eq('6')
expect(cardDeck.isPass(), '2nd pass').to.false

expect(cardDeck.draw(), '3rd draw').to.true
expect(cardDeck.actionCard?.id, '3rd action card').to.eq(9)
expect(cardDeck.supportCard?.id, '3rd support card').to.eq(7)
expect(cardDeck.actionCard?.id, '3rd action card').to.eq('9')
expect(cardDeck.supportCard?.id, '3rd support card').to.eq('7')
expect(cardDeck.isPass(), '3rd pass').to.false

expect(cardDeck.draw(), '4th draw').to.false
expect(cardDeck.actionCard, '4th action card').to.undefined
expect(cardDeck.supportCard?.id, '4th support card').to.eq(9)
expect(cardDeck.supportCard?.id, '4th support card').to.eq('9')
expect(cardDeck.isPass(), '4th pass').to.true
})

it('draw-pass-last-3', () => {
const cardDeck = CardDeck.fromPersistence({
deck: [1,2,3,4],
deck: ['1','2','3','4'],
discard: [],
reserve: []
})

expect(cardDeck.draw(), '1st draw').to.true
expect(cardDeck.actionCard?.id, '1st action card').to.eq(2)
expect(cardDeck.supportCard?.id, '1st support card').to.eq(1)
expect(cardDeck.actionCard?.id, '1st action card').to.eq('2')
expect(cardDeck.supportCard?.id, '1st support card').to.eq('1')
expect(cardDeck.isPass(), '1st pass').to.false

expect(cardDeck.draw(), '2nd draw').to.true
expect(cardDeck.actionCard?.id, '2nd action card').to.eq(3)
expect(cardDeck.supportCard?.id, '2nd support card').to.eq(2)
expect(cardDeck.actionCard?.id, '2nd action card').to.eq('3')
expect(cardDeck.supportCard?.id, '2nd support card').to.eq('2')
expect(cardDeck.isPass(), '2nd pass').to.true
})

it('prepareForNextRound', () => {
const cardDeck = CardDeck.fromPersistence({
deck: [1,2],
discard: [3,4],
reserve: [6,7]
deck: ['1','2'],
discard: ['3','4'],
reserve: ['6','7']
})

cardDeck.prepareForNextRound()
Expand All @@ -113,6 +113,6 @@ describe('CardDeck', () => {
expect(persistence.deck.length, 'deck size').to.eq(5)
expect(persistence.discard.length, 'deck size').to.eq(0)
expect(persistence.reserve.length, 'deck size').to.eq(1)
expect(persistence.deck.includes(6), 'includes reserve card').to.true
expect(persistence.deck.includes('6'), 'includes reserve card').to.true
})
})
4 changes: 2 additions & 2 deletions tests/unit/services/Cards.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { expect } from 'chai'

describe('Cards', () => {
it('get', () => {
const card = Cards.get(1)
const card = Cards.get('1')

expect(card).not.undefined
expect(card?.id).to.eq(1)
expect(card?.id).to.eq('1')
})

it('getAll', () => {
Expand Down

0 comments on commit 5bbaed3

Please sign in to comment.