Skip to content

Commit

Permalink
Barebones structure for game state with some basic functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ordog.ivett committed Sep 19, 2020
1 parent 5c2eacf commit f191172
Show file tree
Hide file tree
Showing 7 changed files with 640 additions and 2 deletions.
18 changes: 18 additions & 0 deletions Card.js
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;
13 changes: 13 additions & 0 deletions GameState.js
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;
5 changes: 5 additions & 0 deletions Player.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
const GameState = require('./GameState');

class Player {
static get VERSION() {
return '0.1';
}

static betRequest(gameState, bet) {
var game = new GameState(gameState);
console.log(game.me().highestPocketValue());
bet(0);
}

Expand All @@ -12,3 +16,4 @@ class Player {
}

module.exports = Player;

30 changes: 30 additions & 0 deletions PlayerState.js
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;
Loading

0 comments on commit f191172

Please sign in to comment.