Skip to content

Commit

Permalink
feat: change to positive boost
Browse files Browse the repository at this point in the history
  • Loading branch information
ImSoZRious committed Mar 31, 2024
1 parent 2c7b354 commit 44b573d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions apps/server/src/models/history.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,19 @@ export class GameHistoryRepository {
) {}

async createHistory(game_id: string, key: string, vote: number) {
const total = await this.redis.incrBy(`game::${game_id}::${key}`, vote)
const others: number[] = []
var now = 0
this.redis.keys(`game::${game_id}::*`).then(async (keys) => {
keys.forEach(async (k) => {
if (k !== `game::${game_id}::${key}`) {
const kTotal = parseInt((await this.redis.get(k)) || '0')
if (kTotal > total - vote) {
this.redis.decrBy(k, Math.floor((kTotal - total + vote) * 0.1))
}
others.push(parseInt((await this.redis.get(k)) || '0'))
} else {
now = parseInt((await this.redis.get(k)) || '0')
}
})
})
const follow = others.map(x => Math.max(0, x - now)).reduce((acc, x) => acc + x)
await this.redis.incrBy(`game::${game_id}::${key}`, (1.0 + follow * 0.001) * vote)
}

async getHistoryByPlayerID(game_id: string, player_id: string) {
Expand Down

0 comments on commit 44b573d

Please sign in to comment.