-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcollect.js
39 lines (36 loc) · 1004 Bytes
/
collect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const _ = require('lodash')
const fs = require('fs')
const {
WINNER,
GAME_OVER,
getAllValidMoves,
playGame,
getCardValue
} = require('./src/game')
const randomNextAction = state => {
const moves = getAllValidMoves(state)
return moves[_.random(moves.length - 1)]
}
const makeGameLog = result => ({
deck: _.map(result.initialState.deck, getCardValue),
actions: result.actions,
finalPhase: result.finalState.phase
})
const MAX = 10
const games = {
win: [],
lose: []
}
let i = 0
while (games.win.length < MAX || games.lose.length < MAX) {
i++
const result = playGame(randomNextAction)
if (result.finalState.phase === WINNER && games.win.length < MAX) {
games.win.push(makeGameLog(result))
}
if (result.finalState.phase === GAME_OVER && games.lose.length < MAX) {
games.lose.push(makeGameLog(result))
}
}
console.log(`played ${i} games`)
fs.writeFileSync('random-player-game-logs.json', JSON.stringify(games, null, 4))