-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared.js
63 lines (51 loc) · 1.75 KB
/
shared.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const pm = {}
pm.maxSuspects = 8
pm.betsPerSuspect = 24
let cheapestBet = .04501 //probably the lowest percentage people think about is 5%
pm.betPrices = Array(pm.betsPerSuspect)
for (let i = 0.; i < pm.betsPerSuspect; ++i)
pm.betPrices[i] = Math.pow(cheapestBet, 1. - i / pm.betsPerSuspect)
{
let entireColumnPrice = 0.
for (let i = 0.; i < pm.betsPerSuspect; ++i)
entireColumnPrice += pm.betPrices[i]
let arbitraryValueChosenByRobinHanson = .6
pm.startingCash = entireColumnPrice * arbitraryValueChosenByRobinHanson // STARTING CASH
}
pm.BOARD_OWNERSHIP = -1
pm.NO_OWNERSHIP = -2 //urgh, or "no association"? bit of a mess
// function getCheapestBet() {
// return getMax(suspect.bets, (bet) => {
// return bet.ownerIndex === pm.BOARD_OWNERSHIP ? 1. / bet.scale.x : -Infinity
// })
// }
pm.getNumBoardBets = (suspect) => {
let numInBoard = 0
suspect.betOwners.forEach((betOwner) => {
if (betOwner === pm.BOARD_OWNERSHIP)
++numInBoard
})
return numInBoard
}
pm.isCashBitOnBoard = (suspect,index) => {
let numBetsOnBoard = pm.getNumBoardBets(suspect)
let numCashBitsOnBoard = pm.betsPerSuspect - numBetsOnBoard
return index < numCashBitsOnBoard
}
pm.getCashBitOwnership = (suspect,cashBit) => {
if (pm.isCashBitOnBoard(suspect,suspect.cashBits.indexOf(cashBit)))
return pm.NO_OWNERSHIP //more like board ownership
else
return cashBit.associatedPlayer
}
pm.getLooseCash = (playerId, susArray) => {
let ret = 0.
susArray.forEach((suspect) => {
suspect.cashBits.forEach((cashBit, i) => {
if (pm.getCashBitOwnership(suspect, cashBit) === playerId)
ret += pm.betPrices[i]
})
})
return ret
}
module.exports = pm