Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed raise request #69

Merged
merged 2 commits into from
Jun 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions src/utils/commonRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,21 +375,20 @@ export async function playerCanBetAmount(
amount: string,
client: PoolClient
): Promise<boolean> {
const smallBlindValue = await getSmallBlindValue(gameId, client)
const playerSize = (await getPlayersInGame(gameId, client)).length
const smallBlind = await getSmallBlindToken(gameId, playerSize, client)
const smallBlindState = await getPlayerState(smallBlind, client)
const bigBlind = await getBigBlindToken(gameId, playerSize, client)
const bigBlindState = await getPlayerState(bigBlind, client)

if (playerToken === smallBlind && smallBlindState == null) {
amount = (+amount - +smallBlindValue).toString()
} else if (playerToken === bigBlind && bigBlindState == null) {
amount = (+amount - +smallBlindValue * 2).toString()
}
const bet = await getPlayerBet(playerToken, client)
const funds = await getPlayerFunds(playerToken, client)

return +amount <= +funds + +bet
}

export async function getPlayerBet(playerToken: string, client: PoolClient) {
const query = 'SELECT bet FROM Players WHERE token=$1'
return (await client.query(query, [playerToken])).rows[0].bet
}

const query = 'SELECT 1 FROM Players WHERE token=$1 AND funds>=$2'
return (await client.query(query, [playerToken, amount])).rowCount !== 0
export async function getPlayerFunds(playerToken: string, client: PoolClient) {
const query = 'SELECT funds FROM Players WHERE token=$1'
return (await client.query(query, [playerToken])).rows[0].funds
}

export async function isAmountRaise(
Expand Down