Skip to content

Commit

Permalink
reset, resource count
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Oct 19, 2024
1 parent 82e7b54 commit 4568919
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/components/turn/DebugInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<p class="debug">
<b>cardDeck</b>: {{cardDeck.toPersistence()}}<br/>
<b>currentCard</b>: {{cardDeck.currentCard}}<br/>
<b>rolls</b>: action={{navigationState.actionRoll}}, territory={{navigationState.territoryRoll}}, beacon={{navigationState.beaconRoll}}<br/>
<b>rolls</b>: action={{navigationState.actionRoll}}, territory={{navigationState.territoryRoll}}, beacon={{navigationState.beaconRoll}},
<b>difficultyLevel</b>: {{navigationState.difficultyLevel}}<br/>
</p>
</div>
</template>
Expand Down
53 changes: 50 additions & 3 deletions src/components/turn/SideBar.vue
Original file line number Diff line number Diff line change
@@ -1,26 +1,52 @@
<template>
<div class="sidebar">
{{t('sideBar.round', {round:navigationState.round})}}<br/>
{{t('sideBar.round', {round:navigationState.round})}}
<h6 class="mt-2">V.I.C.I</h6>
<div class="count">
{{navigationState.evolutionCount + (botActions?.evolutionCount ?? 0)}}
<AppIcon type="action" name="advance-evolution" class="icon"/>
</div>
<div class="count">
{{navigationState.prosperityCount + (botActions?.prosperityCount ?? 0)}}
<AppIcon type="action" name="advance-prosperity" class="icon"/>
</div>
<div class="mt-2">
<div class="dotCount blue">
<template v-for="index in navigationState.blueDotCount" :key="index">■</template>
</div>
<div class="dotCount red">
<template v-for="index in navigationState.redDotCount" :key="index">■</template>
</div>
</div>
</div>
</template>

<script lang="ts">
import { defineComponent, PropType } from 'vue'
import { defineComponent } from 'vue'
import { useI18n } from 'vue-i18n'
import { useStateStore } from '@/store/state'
import NavigationState from '@/util/NavigationState'
import AppIcon from '../structure/AppIcon.vue';
import BotActions from '@/services/BotActions';
export default defineComponent({
name: 'SideBar',
components: {
AppIcon
},
setup() {
const { t } = useI18n()
const state = useStateStore()
return { t, state }
},
props: {
navigationState: {
type: Object as PropType<NavigationState>,
type: NavigationState,
required: true
},
botActions: {
type: BotActions,
required: false
}
}
})
Expand All @@ -42,4 +68,25 @@ export default defineComponent({
width: 120px;
}
}
.count {
display: inline-block;
margin-right: 0.5rem;
.icon {
max-height: 1.5rem;
max-width: 1.75rem;
@media (max-width: 600px) {
max-height: 1.25rem;
max-width: 1.5rem;
}
}
}
.dotCount {
line-height: 0.9rem;
&.blue {
color: #00c;
}
&.red {
color: #c00;
}
}
</style>
14 changes: 14 additions & 0 deletions src/services/BotActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ export default class BotActions {
return this._reset
}

public get evolutionCount() : number {
return countScoringCategory(this._items, ScoringCategory.EVOLUTION)
}

public get prosperityCount() : number {
return countScoringCategory(this._items, ScoringCategory.PROSPERITY)
}

}

export interface ActionItem {
Expand Down Expand Up @@ -140,3 +148,9 @@ function getFinalScoringCategoryActions(scoringCategories: ScoringCategory[], co
}
return items
}

function countScoringCategory(items: ActionItem[], scoringCategory: ScoringCategory) : number {
return items
.filter(item => item.action == Action.ADVANCE_SCORING_CATEGORY && item.scoringCategory == scoringCategory)
.reduce((sum, item) => sum + (item.count ?? 0), 0)
}
1 change: 1 addition & 0 deletions src/store/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export interface BotPersistence {
actionRoll: number
territoryRoll: number
beaconRoll: number
reset?: boolean
}
export interface CardDeckPersistence {
pile: number[]
Expand Down
17 changes: 11 additions & 6 deletions src/util/NavigationState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,20 @@ export default class NavigationState {
else {
const previousBotPersistence = getPreviousBotPersistence(state, this.round, this.turn)
this.cardDeck = CardDeck.fromPersistence(previousBotPersistence.cardDeck)
let { blueDotCount, redDotCount } = previousBotPersistence
if (previousBotPersistence.reset) {
blueDotCount = 0
redDotCount = 0
}
// draw next card, count dots
if (this.player == Player.BOT) {
const nextCard = this.cardDeck.draw()
this.blueDotCount = previousBotPersistence.blueDotCount + nextCard.blueDotCount
this.redDotCount = previousBotPersistence.redDotCount + nextCard.redDotCount
this.blueDotCount = blueDotCount + nextCard.blueDotCount
this.redDotCount = redDotCount + nextCard.redDotCount
}
else {
this.blueDotCount = previousBotPersistence.blueDotCount
this.redDotCount = previousBotPersistence.redDotCount
this.blueDotCount = blueDotCount
this.redDotCount = redDotCount
}
// counters
this.evolutionCount = previousBotPersistence.evolutionCount
Expand Down Expand Up @@ -154,8 +159,8 @@ function getPreviousBotPersistence(state: State, round: number, turn: number) :
}
return {
cardDeck: initialCardDeck,
evolutionCount: 0,
prosperityCount: 0,
evolutionCount: 2,
prosperityCount: 2,
blueDotCount: 0,
redDotCount: 0,
actionRoll: 0,
Expand Down
23 changes: 19 additions & 4 deletions src/views/TurnBot.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
<template>
<SideBar :navigationState="navigationState"/>
<SideBar :navigationState="navigationState" :botActions="botActions"/>

<h1>
<img src="@/assets/vici.webp" class="vici" alt=""/>
{{t('turnBot.title')}}
</h1>

<template v-if="isReset">
<p>Reset...</p>
</template>
<template v-else>
<p>Actions: {{botActions._items}}</p>
</template>

<button class="btn btn-primary btn-lg mt-4 me-2" @click="next()">
{{t('action.next')}}
</button>
Expand All @@ -26,6 +33,7 @@ import SideBar from '@/components/turn/SideBar.vue'
import NavigationState from '@/util/NavigationState'
import EndRoundButton from '@/components/turn/EndRoundButton.vue'
import DebugInfo from '@/components/turn/DebugInfo.vue'
import BotActions from '@/services/BotActions'
export default defineComponent({
name: 'TurnBot',
Expand All @@ -42,15 +50,19 @@ export default defineComponent({
const navigationState = new NavigationState(route, state)
const { round, turn } = navigationState
const botActions = new BotActions(navigationState.currentCard, navigationState)
return { t, state, navigationState, round, turn }
return { t, state, navigationState, round, turn, botActions }
},
computed: {
backButtonRouteTo() : string {
if (this.turn > 1) {
return `/round/${this.round}/turn/${this.turn-1}/player`
}
return `/round/${this.round}/start`
},
isReset() : boolean {
return this.botActions.isReset
}
},
methods: {
Expand All @@ -63,15 +75,18 @@ export default defineComponent({
player,
botPersistence: {
cardDeck: cardDeck.toPersistence(),
evolutionCount,
prosperityCount,
evolutionCount: evolutionCount + this.botActions.evolutionCount,
prosperityCount: prosperityCount + this.botActions.prosperityCount,
blueDotCount,
redDotCount,
actionRoll,
territoryRoll,
beaconRoll
}
}
if (this.isReset && turn.botPersistence) {
turn.botPersistence.reset = true
}
this.state.storeTurn(turn)
},
next() : void {
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/helper/mockTurn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export default function (params?: MockTurnParams) : Turn {
redDotCount: params?.redDotCount ?? 0,
actionRoll: params?.actionRoll ?? 0,
territoryRoll: params?.territoryRoll ?? 0,
beaconRoll: params?.beaconRoll ?? 0
beaconRoll: params?.beaconRoll ?? 0,
reset: params?.reset
}
}
return turn
Expand All @@ -37,4 +38,5 @@ export interface MockTurnParams {
actionRoll?: number
territoryRoll?: number
beaconRoll?: number
reset?: boolean
}
4 changes: 2 additions & 2 deletions tests/unit/util/NavigationState.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ describe('util/NavigationState', () => {

expect(navigationState.player).to.eq(Player.PLAYER)
expect(navigationState.cardDeck.toPersistence()).to.eql({pile:[1,2,3,4],discard:[]})
expect(navigationState.evolutionCount).to.eq(0)
expect(navigationState.prosperityCount).to.eq(0)
expect(navigationState.evolutionCount).to.eq(2)
expect(navigationState.prosperityCount).to.eq(2)
expect(navigationState.blueDotCount).to.eq(0)
expect(navigationState.redDotCount).to.eq(0)
expect(navigationState.actionRoll).to.eq(0)
Expand Down

0 comments on commit 4568919

Please sign in to comment.