-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Barebones structure for game state with some basic functions
- Loading branch information
ordog.ivett
committed
Sep 19, 2020
1 parent
5c2eacf
commit f191172
Showing
7 changed files
with
640 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Card { | ||
constructor(card) { | ||
this.card = card; | ||
} | ||
|
||
rank() { return this.card.rank; } | ||
suit() { return tihs.card.suit; } | ||
|
||
value() { | ||
if(['J','Q','K','A'].includes(this.card.rank)) { | ||
return ['J','Q','K','A'].indexOf(this.card.rank) + 11; | ||
} else { | ||
return parseInt(this.card.rank); | ||
} | ||
} | ||
} | ||
|
||
module.exports = Card; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const PlayerState = require('./PlayerState'); | ||
|
||
class GameState { | ||
constructor(gameState) { | ||
this.gameState = gameState; | ||
} | ||
|
||
me() { | ||
return new PlayerState(this.gameState.players[this.gameState.in_action]); | ||
} | ||
} | ||
|
||
module.exports = GameState; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const Card = require('./Card'); | ||
|
||
class PlayerState { | ||
constructor(player) { this.player = player; } | ||
|
||
id() { return this.player.id; } | ||
name() { return this.player.name; } | ||
stack() { return this.player.stack; } | ||
status() { return this.player.status; } | ||
bet() { return this.player.bet; } | ||
holeCards() { return this.player.hole_cards.map(c => new Card(c)); } | ||
version() { return this.player.version; } | ||
|
||
hasPocketPair() { | ||
const cards = this.holeCards(); | ||
return cards[0].rank == cards[1].rank; | ||
} | ||
|
||
hasPocketSuited() { | ||
const cards = this.holeCards(); | ||
return cards[0].suit == cards[1].suit; | ||
} | ||
|
||
highestPocketValue() { | ||
const cards = this.holeCards(); | ||
return Math.max(cards[0].value(), cards[1].value()) | ||
} | ||
} | ||
|
||
module.exports = PlayerState; |
Oops, something went wrong.