Skip to content

Commit

Permalink
Working on multiple pots
Browse files Browse the repository at this point in the history
  • Loading branch information
geobalas committed May 18, 2014
1 parent f26823a commit 05e48bb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
14 changes: 7 additions & 7 deletions poker_modules/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var Table = function( id, name, deck, event_emitter, seats_count, big_blind, sma
// The maximum allowed buy in
'max_buy_in': max_buy_in,
// The amount of chips that are in the pot
'pot': 0,
'pot': [{ 'amount': 0, 'players': [] }],
// The biggest bet of the table in the current phase
'biggest_bet': 0,
// The seat of the dealer
Expand Down Expand Up @@ -407,7 +407,7 @@ Table.prototype.add_bets_to_the_pot = function() {
// If a player has betted
if( this.seats[i] !== null && this.seats[i].public.bet ) {
// Add the bet to the pot
this.public.pot += this.seats[i].public.bet;
this.public.pot[0].amount += this.seats[i].public.bet;
this.seats[i].public.bet = 0;
}
}
Expand All @@ -417,8 +417,8 @@ Table.prototype.add_bets_to_the_pot = function() {
* Method that adds the chips that exists in the pot, to the winner's chips
*/
Table.prototype.give_pot_to_winner = function( winners_seat ) {
this.seats[winners_seat].public.chips_in_play += this.public.pot;
this.public.pot = 0;
this.seats[winners_seat].public.chips_in_play += this.public.pot[0].amount;
this.public.pot[0].amount = 0;
}

/**
Expand Down Expand Up @@ -591,7 +591,7 @@ Table.prototype.player_sat_out = function( seat, player_left ) {

// If the player had betted, add the bets to the pot
if( this.seats[seat].public.bet ) {
this.public.pot += +this.seats[seat].public.bet;
this.public.pot[0].amount += +this.seats[seat].public.bet;
this.seats[seat].public.bet = 0;
}

Expand Down Expand Up @@ -648,7 +648,7 @@ Table.prototype.remove_all_cards_from_play = function() {
Table.prototype.end_round = function() {
// If there were any bets, they are added to the pot
this.add_bets_to_the_pot();
if( this.public.pot ) {
if( this.public.pot[0].amount ) {
var winners_seat = this.find_next_player( 0 );
this.give_pot_to_winner( winners_seat );
}
Expand All @@ -672,7 +672,7 @@ Table.prototype.end_round = function() {
*/
Table.prototype.stop_game = function() {
this.public.phase = null;
this.public.pot = null;
this.public.pot[0].amount = 0;
this.public.active_seat = null;
this.public.board = ['', '', '', '', ''];
this.public.active_seat = null;
Expand Down
6 changes: 3 additions & 3 deletions public/js/controllers/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ app.controller( 'TableController', ['$scope', '$rootScope', '$http', '$routePara
}

$scope.min_bet_amount = function() {
if( !$scope.my_seat || typeof $scope.table.seats[$scope.my_seat] === 'undefined' ) return 0;
if( $scope.my_seat === null || typeof $scope.table.seats[$scope.my_seat] === 'undefined' ) return 0;
// If the pot was raised
if( $scope.action_state === "act_betted_pot" ) {
var proposed_bet = +$scope.table.biggest_bet + $scope.table.big_blind;
Expand All @@ -53,12 +53,12 @@ app.controller( 'TableController', ['$scope', '$rootScope', '$http', '$routePara
}

$scope.max_bet_amount = function() {
if( !$scope.my_seat || typeof $scope.table.seats[$scope.my_seat] === 'undefined' ) return 0;
if( $scope.my_seat === null || typeof $scope.table.seats[$scope.my_seat] === 'undefined' ) return 0;
return $scope.action_state === "act_betted_pot" ? $scope.table.seats[$scope.my_seat].chips_in_play + $scope.table.seats[$scope.my_seat].bet : $scope.table.seats[$scope.my_seat].chips_in_play;
}

$scope.call_amount = function() {
if( !$scope.my_seat || typeof $scope.table.seats[$scope.my_seat] === 'undefined' ) return 0;
if( $scope.my_seat === null || typeof $scope.table.seats[$scope.my_seat] === 'undefined' ) return 0;
var call_amount = +$scope.table.biggest_bet - $scope.table.seats[$scope.my_seat].bet;
return call_amount > $scope.table.seats[$scope.my_seat].chips_in_play ? $scope.table.seats[$scope.my_seat].chips_in_play : call_amount;
}
Expand Down
4 changes: 2 additions & 2 deletions views/table_10_handed.jade
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
#bets_9.bets
span(ng-show="table.seats[9].bet") {{table.seats[9].bet}}
.double_cell
span#pot(ng-show="table.pot") Pot: {{table.pot}}
span#pot(ng-show="table.pot[0].amount" ng-repeat="pot in table.pot") Pot: {{pot.amount}}
.board_wrap
.card(class="card-{{table.board[0]}}" ng-show="table.board[0]")
.card(class="card-{{table.board[1]}}" ng-show="table.board[1]")
Expand Down Expand Up @@ -173,7 +173,7 @@
button(class="control_button", ng-click="call()", ng-show='action_state === "act_betted_pot" && !(action_state === "act_betted_pot" && table.biggest_bet == table.seats[my_seat].bet)') Call {{call_amount()}}
.cell
button(class="control_button", ng-click="bet()", ng-show='action_state === "act_not_betted_pot" && table.seats[my_seat].chips_in_play') Bet {{bet_amount}}
button(class="control_button", ng-click="raise()", ng-show='action_state === "act_betted_pot" && table.seats[my_seat].chips_in_play') Raise {{bet_amount}}
button(class="control_button", ng-click="raise()", ng-show='action_state === "act_betted_pot" && table.seats[my_seat].chips_in_play') Raise to {{bet_amount}}
.double_cell
.cell_content
input(type="range", ng-show='action_state === "act_not_betted_pot" || action_state === "act_betted_pot"', min="{{min_bet_amount()}}", max="{{max_bet_amount()}}", ng-model="bet_amount")
Expand Down
16 changes: 8 additions & 8 deletions views/table_2_handed.jade
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#table_wrap
#modal_wrap(ng-show="show_buy_in_modal")
#modal
form
form(ng-submit="sit_on_the_table(seat)")
h1 {{table.name}}
p Max buy-in {{table.max_buy_in}}
p Min buy-in {{table.min_buy_in}}
p You have a total of {{$root.total_chips}} chips
p.error(ng-show="buy_in_error") {{buy_in_error}}
input.input_left(type="number", ng-model="buy_in_amount", ng-trim="true")
input(type="submit", ng-click="sit_on_the_table(seat)", value="Sit in")
input.input_left(type="number", ng-model="buy_in_amount", ng-trim="true" required)
input(type="submit", value="Sit in")
#curtain(ng-show="show_buy_in_modal" ng-click="show_buy_in_modal=false;")
.table
.felt
Expand All @@ -33,7 +33,7 @@
#bets_9.bets
span(ng-show="table.seats[0].bet") {{table.seats[0].bet}}
.double_cell
span#pot(ng-show="table.pot") Pot: {{table.pot}}
span#pot(ng-show="table.pot[0].amount" ng-repeat="pot in table.pot") Pot: {{pot.amount}}
.board_wrap
.card(class="card-{{table.board[0]}}" ng-show="table.board[0]")
.card(class="card-{{table.board[1]}}" ng-show="table.board[1]")
Expand Down Expand Up @@ -74,11 +74,11 @@
button(class="control_button", ng-click="post_blind(true)", ng-show='action_state === "post_small_blind"') Small Blind ({{table.small_blind}})
button(class="control_button", ng-click="post_blind(true)", ng-show='action_state === "post_big_blind"') Big Blind ({{table.big_blind}})
button(class="control_button", ng-click="check()", ng-show='action_state === "act_not_betted_pot" || (action_state === "act_betted_pot" && table.biggest_bet == table.seats[my_seat].bet)') Check
button(class="control_button", ng-click="call()", ng-show='action_state === "act_betted_pot" && !(action_state === "act_betted_pot" && table.biggest_bet == table.seats[my_seat].bet)') Call {{table.biggest_bet - table.seats[my_seat].bet}}
button(class="control_button", ng-click="call()", ng-show='action_state === "act_betted_pot" && !(action_state === "act_betted_pot" && table.biggest_bet == table.seats[my_seat].bet)') Call {{call_amount()}}
.cell
button(class="control_button", ng-click="bet()", ng-show='action_state === "act_not_betted_pot" && table.seats[my_seat].chips_in_play') Bet {{bet_amount}}
button(class="control_button", ng-click="raise()", ng-show='action_state === "act_betted_pot" && table.seats[my_seat].chips_in_play') Raise {{bet_amount}}
button(class="control_button", ng-click="raise()", ng-show='action_state === "act_betted_pot" && table.seats[my_seat].chips_in_play') Raise to {{bet_amount}}
.double_cell
.cell_content
input(type="range", ng-show='action_state === "act_not_betted_pot" || action_state === "act_betted_pot"', min="{{min_bet_amount()}}", max="{{table.seats[my_seat].chips_in_play}}", ng-model="bet_amount")
input(type="number", id="bet_input", ng-show='action_state === "act_not_betted_pot" || action_state === "act_betted_pot"', min="{{min_bet_amount()}}", max="{{table.seats[my_seat].chips_in_play}}", ng-model="bet_amount", value="{{bet_amount}}")
input(type="range", ng-show='action_state === "act_not_betted_pot" || action_state === "act_betted_pot"', min="{{min_bet_amount()}}", max="{{max_bet_amount()}}", ng-model="bet_amount")
input(type="number", id="bet_input", ng-show='action_state === "act_not_betted_pot" || action_state === "act_betted_pot"', min="{{min_bet_amount()}}", max="{{max_bet_amount()}}", ng-model="bet_amount", value="{{bet_amount}}")
16 changes: 8 additions & 8 deletions views/table_6_handed.jade
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#table_wrap
#modal_wrap(ng-show="show_buy_in_modal")
#modal
form
form(ng-submit="sit_on_the_table(seat)")
h1 {{table.name}}
p Max buy-in {{table.max_buy_in}}
p Min buy-in {{table.min_buy_in}}
p You have a total of {{$root.total_chips}} chips
p.error(ng-show="buy_in_error") {{buy_in_error}}
input.input_left(type="number", ng-model="buy_in_amount", ng-trim="true")
input(type="submit", ng-click="sit_on_the_table(seat)", value="Sit in")
input.input_left(type="number", ng-model="buy_in_amount", ng-trim="true" required)
input(type="submit", value="Sit in")
#curtain(ng-show="show_buy_in_modal" ng-click="show_buy_in_modal=false;")
.table
.felt
Expand Down Expand Up @@ -57,7 +57,7 @@
#bets_9.bets
span(ng-show="table.seats[5].bet") {{table.seats[5].bet}}
.double_cell
span#pot(ng-show="table.pot") Pot: {{table.pot}}
span#pot(ng-show="table.pot[0].amount" ng-repeat="pot in table.pot") Pot: {{pot.amount}}
.board_wrap
.card(class="card-{{table.board[0]}}" ng-show="table.board[0]")
.card(class="card-{{table.board[1]}}" ng-show="table.board[1]")
Expand Down Expand Up @@ -122,11 +122,11 @@
button(class="control_button", ng-click="post_blind(true)", ng-show='action_state === "post_small_blind"') Small Blind ({{table.small_blind}})
button(class="control_button", ng-click="post_blind(true)", ng-show='action_state === "post_big_blind"') Big Blind ({{table.big_blind}})
button(class="control_button", ng-click="check()", ng-show='action_state === "act_not_betted_pot" || (action_state === "act_betted_pot" && table.biggest_bet == table.seats[my_seat].bet)') Check
button(class="control_button", ng-click="call()", ng-show='action_state === "act_betted_pot" && !(action_state === "act_betted_pot" && table.biggest_bet == table.seats[my_seat].bet)') Call {{table.biggest_bet - table.seats[my_seat].bet}}
button(class="control_button", ng-click="call()", ng-show='action_state === "act_betted_pot" && !(action_state === "act_betted_pot" && table.biggest_bet == table.seats[my_seat].bet)') Call {{call_amount()}}
.cell
button(class="control_button", ng-click="bet()", ng-show='action_state === "act_not_betted_pot" && table.seats[my_seat].chips_in_play') Bet {{bet_amount}}
button(class="control_button", ng-click="raise()", ng-show='action_state === "act_betted_pot" && table.seats[my_seat].chips_in_play') Raise {{bet_amount}}
button(class="control_button", ng-click="raise()", ng-show='action_state === "act_betted_pot" && table.seats[my_seat].chips_in_play') Raise to {{bet_amount}}
.double_cell
.cell_content
input(type="range", ng-show='action_state === "act_not_betted_pot" || action_state === "act_betted_pot"', min="{{min_bet_amount()}}", max="{{table.seats[my_seat].chips_in_play}}", ng-model="bet_amount")
input(type="number", id="bet_input", ng-show='action_state === "act_not_betted_pot" || action_state === "act_betted_pot"', min="{{min_bet_amount()}}", max="{{table.seats[my_seat].chips_in_play}}", ng-model="bet_amount", value="{{bet_amount}}")
input(type="range", ng-show='action_state === "act_not_betted_pot" || action_state === "act_betted_pot"', min="{{min_bet_amount()}}", max="{{max_bet_amount()}}", ng-model="bet_amount")
input(type="number", id="bet_input", ng-show='action_state === "act_not_betted_pot" || action_state === "act_betted_pot"', min="{{min_bet_amount()}}", max="{{max_bet_amount()}}", ng-model="bet_amount", value="{{bet_amount}}")

0 comments on commit 05e48bb

Please sign in to comment.