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

init next phase at end of river #16

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
42 changes: 22 additions & 20 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ app.use(express.bodyParser());
app.use(app.router);
app.use(lessMiddleware(__dirname + '/public'));
app.use(express.static(path.join(__dirname, 'public')));
//app.use(express.static('public/js/libs'));

// Development Only
if ( 'development' == app.get('env') ) {
Expand All @@ -25,7 +26,7 @@ var players = [];
var tables = [];
var eventEmitter = {};

var port = process.env.PORT || 3000;
var port = process.env.PORT || 8080;
server.listen(port);
console.log('Listening on port ' + port);

Expand Down Expand Up @@ -159,7 +160,7 @@ io.sockets.on('connection', function( socket ) {
}
if( !nameExists ) {
// Creating the player object
players[socket.id] = new Player( socket, newScreenName, 1000 );
players[socket.id] = new Player( socket, newScreenName, 100000 );
callback( { 'success': true, screenName: newScreenName, totalChips: players[socket.id].chips } );
} else {
callback( { 'success': false, 'message': 'This name is taken' } );
Expand All @@ -177,7 +178,7 @@ io.sockets.on('connection', function( socket ) {
* @param function callback
*/
socket.on('sitOnTheTable', function( data, callback ) {
if(
if(
// A seat has been specified
typeof data.seat !== 'undefined'
// A table id is specified
Expand All @@ -186,7 +187,7 @@ io.sockets.on('connection', function( socket ) {
&& typeof tables[data.tableId] !== 'undefined'
// The seat number is an integer and less than the total number of seats
&& typeof data.seat === 'number'
&& data.seat >= 0
&& data.seat >= 0
&& data.seat < tables[data.tableId].public.seatsCount
&& typeof players[socket.id] !== 'undefined'
// The seat is empty
Expand All @@ -197,7 +198,7 @@ io.sockets.on('connection', function( socket ) {
&& players[socket.id].room === data.tableId
// The chips number chosen is a number
&& typeof data.chips !== 'undefined'
&& !isNaN(parseInt(data.chips))
&& !isNaN(parseInt(data.chips))
&& isFinite(data.chips)
// The chips number is an integer
&& data.chips % 1 === 0
Expand Down Expand Up @@ -242,10 +243,10 @@ io.sockets.on('connection', function( socket ) {
var tableId = players[socket.id].sittingOnTable;
var activeSeat = tables[tableId].public.activeSeat;

if( tables[tableId]
&& typeof tables[tableId].seats[activeSeat].public !== 'undefined'
&& tables[tableId].seats[activeSeat].socket.id === socket.id
&& ( tables[tableId].public.phase === 'smallBlind' || tables[tableId].public.phase === 'bigBlind' )
if( tables[tableId]
&& typeof tables[tableId].seats[activeSeat].public !== 'undefined'
&& tables[tableId].seats[activeSeat].socket.id === socket.id
&& ( tables[tableId].public.phase === 'smallBlind' || tables[tableId].public.phase === 'bigBlind' )
) {
if( postedBlind ) {
callback( { 'success': true } );
Expand Down Expand Up @@ -273,10 +274,10 @@ io.sockets.on('connection', function( socket ) {
var tableId = players[socket.id].sittingOnTable;
var activeSeat = tables[tableId].public.activeSeat;

if( tables[tableId]
&& tables[tableId].seats[activeSeat].socket.id === socket.id
if( tables[tableId]
&& tables[tableId].seats[activeSeat].socket.id === socket.id
&& !tables[tableId].public.biggestBet || ( tables[tableId].public.phase === 'preflop' && tables[tableId].public.biggestBet === players[socket.id].public.bet )
&& ['preflop','flop','turn','river'].indexOf(tables[tableId].public.phase) > -1
&& ['preflop','flop','turn','river'].indexOf(tables[tableId].public.phase) > -1
) {
// Sending the callback first, because the next functions may need to send data to the same player, that shouldn't be overwritten
callback( { 'success': true } );
Expand Down Expand Up @@ -335,7 +336,7 @@ io.sockets.on('connection', function( socket ) {
if ( amount && isFinite( amount ) && amount <= tables[tableId].seats[activeSeat].public.chipsInPlay ) {
// Sending the callback first, because the next functions may need to send data to the same player, that shouldn't be overwritten
callback( { 'success': true } );
tables[tableId].playerBetted( amount );
tables[tableId].playerBetted( amount );
}
}
}
Expand All @@ -349,13 +350,13 @@ io.sockets.on('connection', function( socket ) {
if( players[socket.id].sittingOnTable !== 'undefined' ) {
var tableId = players[socket.id].sittingOnTable;
var activeSeat = tables[tableId].public.activeSeat;

if(
// The table exists
typeof tables[tableId] !== 'undefined'
typeof tables[tableId] !== 'undefined'
// The player who should act is the player who raised
&& tables[tableId].seats[activeSeat].socket.id === socket.id
// The pot was betted
// The pot was betted
&& tables[tableId].public.biggestBet
// It's not a round of blinds
&& ['preflop','flop','turn','river'].indexOf(tables[tableId].public.phase) > -1
Expand Down Expand Up @@ -408,7 +409,8 @@ function htmlEntities(str) {
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}

tables[0] = new Table( 0, 'Sample 10-handed Table', eventEmitter(0), 10, 2, 1, 200, 40, false );
tables[1] = new Table( 1, 'Sample 6-handed Table', eventEmitter(1), 6, 4, 2, 400, 80, false );
tables[2] = new Table( 2, 'Sample 2-handed Table', eventEmitter(2), 2, 8, 4, 800, 160, false );
tables[3] = new Table( 3, 'Sample 6-handed Private Table', eventEmitter(3), 6, 20, 10, 2000, 400, true );
tables[0] = new Table( 0, 'Sample 10-handed Table', eventEmitter(0), 10, 2, 1, 200, 40, false, false );
tables[1] = new Table( 1, 'Sample 6-handed Table', eventEmitter(1), 6, 4, 2, 400, 80, false, false );
tables[2] = new Table( 2, 'Sample 2-handed Table', eventEmitter(2), 2, 8, 4, 800, 160, false, false );
tables[3] = new Table( 3, 'Sample 6-handed Private Table', eventEmitter(3), 6, 20, 10, 2000, 400, true, false );
tables[4] = new Table( 4, '10-handed increasing blinds', eventEmitter(4), 10, 100, 50, 10000, 10000, false, true );
Loading