forked from soederpop/poker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
183 lines (164 loc) · 4.1 KB
/
client.js
File metadata and controls
183 lines (164 loc) · 4.1 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import runtime from "@skypager/web"
import feathers from '@feathersjs/client'
import io from 'socket.io-client'
const baseURL = runtime.get(
"settings.client.baseURL",
runtime.get("argv.baseUrl", `/api`)
)
export const FLOP_FILTERS = {
maxRank: "cardRank",
name: "string",
minRank: "cardRank",
uniqSuits: "number",
ranks: "array",
uniqRanks: "number",
flushPossible: "boolean",
flushDraw: "boolean",
rainbow: "boolean",
sameRank: "boolean",
paired: "boolean",
trips: "boolean",
hasAce: "boolean",
hasKing: "boolean",
hasQueen: "boolean",
hasJack: "boolean",
hasTen: "boolean",
numberOfBroadwayCards: "number",
threeMediumCards: "boolean",
threeSmallCards: "boolean",
gaps: "array",
openEnded: "boolean",
possibleStraights: "boolean"
}
const realTime = feathers()
const client = {
getRealTime: () => realTime,
connect: () => {
const socket = io()
realTime.configure(feathers.socketio(socket))
return Promise.resolve(this)
},
service: (...args) => {
return realTime.service(...args)
},
getGamesService() {
return realTime.service('games')
},
/**
* View information about a Range of hands
*
* @name viewRange
* @function
* @param {String} range a common range notation e.g. 99+,AJs+,KQs+
* @param {Array<String>} deadCards
*/
viewRange(range, deadCards = []) {
return this.client({
url: `${baseURL}/ranges/view`,
params: { range, deadCards }
})
.then(r => r.data)
.catch(e => e.response)
},
/**
* Get the hand combinations which make up a range in a range chart grid
* format 13 x 13, of the normalized hand combos.
*
* @name showRangeGrid
* @function
* @param {Object} options
*/
showRangeGrid(options = {}) {
return this.client
.get(`${baseURL}/ranges/grid`)
.then(r => r.data)
.catch(e => e.response)
},
/**
* Start a new texas holdem game
*
* @name createGame
* @function
* @param {Object} options
* @param {Number} [options.players=9]
* @param {Number} [options.startingStack=3000]
* @param {Array<Number>} [options.blinds=[10,20]]
*/
createGame({ gameId, players = 9, startingStack = 3000, blinds = [10, 20] } = {}) {
const data = {
players,
startingStack,
blinds,
gameId
};
return this.gamesService.create(data)
},
/**
* List the current games
*
* @name listGames
* @function
* @param {Object} options
*/
listGames(options = {}) {
return this.gamesService.find(options).then(({ games }) => games)
},
/**
* Show information about a game
*
* @name showGame
* @function
* @param {String} gameId the unique id of the game
*/
showGame(gameId) {
return this.gamesService.get(gameId)
},
/**
* Record an action by a player in a game.
*
* @name action
* @function
* @param {String} gameId
* @param {Object} action
* @param {String} action.type
* @param {Number} action.amount
* @param {String} action.playerId
*/
action(gameId, action = {}) {
return this.gamesService.update(gameId, { action })
},
/**
* Search all possible flop combinations based on various features / textures
*
* @name searchFlops
* @function
* @param {FlopsFilters} filters
* @param {Number} [filters.sample] get a random sample of size n
* @param {Number} [filters.page=1] which page
* @param {Number} [filters.limit=500] how many results per page?
*/
searchFlops(filters = {}) {
return this.client({ url: `${baseURL}/ranges/flops`, params: filters })
.then(r => r.data)
.catch(e => e.response)
}
}
runtime.clients.register("game-api", () => ({
interfaceMethods: Object.keys(client),
...client
}))
/**
* @typedef {Object} GameAPIClient
* @property {viewRange} viewRange
* @property {showRangeGrid} showRangeGrid
* @property {listGames} listGames
* @property {showGame} showGame
* @property {action} action
* @property {searchFlops} searchFlops
*/
/**
* @type {GameAPIClient}
*/
const gameAPIClient = runtime.client("game-api")
runtime.api = gameAPIClient
export default gameAPIClient