Developing a HoldEm Acion Tracker and feel lost


#1

I am developing a Texas HoldEm action tracker, and am trying to get it to track the action of the pre-flop. I'm stuck. I don't even know the right questions to ask. Pre-flop is slightly different for heads up, so I want it to accommodate both a heads up match and 3 or more players. I feel like I need some combination of booleans and for loops to iterate through the Arrays of players, and exclude those who have folded, but feel overwhelmed. If anybody can give me a boost, I'd appreciate it.

Here is the code at the moment:

var Flop = function() {

};
var bbRaise = function() {
var Rmsg = "To what amount are you raising?";
do {
Raise = parseFloat(prompt(Rmsg, ""));
if(Raise < 2*BB || Raise > playerStacks[button]+BB) {
Rmsg = "Invalid amount. To what amount are you raising?";
};

		}while(Raise < 2*BB || Raise > playerStacks[button]+BB);
		playerStacks[button] = playerStacks[button] - (Raise-BB);
		document.write("<br/>Player 2 has raised to " + Raise + " and now has " + playerStacks[button]);
		Pot = Pot + (Raise-BB);
		document.write("<br/>Pot size is " + Pot);

};
var sbRaise = function() {
var Rmsg = "To what amount are you raising?";
do {
Raise = parseFloat(prompt(Rmsg, ""));
if(Raise < 2*BB || Raise > playerStacks[0]+SB) {
Rmsg = "Invalid amount. To what amount are you raising?";
};

		}while(Raise < 2*BB || Raise > playerStacks[0]+SB);
		playerStacks[button-1] = playerStacks[button-1] - (Raise-SB);
		document.write("<br/>Player 1 has raised to " + Raise + " and now has " + playerStacks[button-1]);

};
var preFlop = function() {
var msg = " choose action (Call, Raise or Fold):";
var BBmsg = "Big Blind choose action (Check or Raise):";
if(playerNum == 2 && button == 1) {
Action = prompt("Player " + button + msg, "Call");
if(Action == "Call"){
playerStacks[button-1] = playerStacks[button-1]-SB;
document.write("
Player " + button + " has called the big blind and now has " + playerStacks[button-1]);
Pot = Pot+SB;
document.write("
Pot size is " + Pot);
Action = prompt("Player 2 " + BBmsg, "Check");
if(Action == "Check") {
Flop();
}
else {
bbRaise();
}
}
else if (Action == "Raise") {

		sbRaise();


		Pot = Pot + (Raise-SB);
		document.write("<br/>Pot size is " + Pot);
		Action = prompt("Player 2" + msg, "Call");
		if(Action == "Call") {
			playerStacks[button] = playerStacks[button] - (Raise-BB);
			document.write("<br/>Player 2 calls and has " + playerStacks[button] + ".");
			Pot = Pot + (Raise-BB);
			document.write("<br/>Pot size is " + Pot);
		}

	}
	if(playerStacks[button-1] == 0) {
			document.write("<br/>Player 1 is all in.");
		}
	if(playerStacks[button] == 0) {
			document.write("<br/>Player 2 is all in.");
		}
}
else if(playerNum == 2 && button == 2) {
	Action = prompt("Player " + button + msg, "Call");
	if(Action = "Call"){
	playerStacks[button-1] = playerStacks[button-1]-SB;
	document.write("<br/>Player " + button + " has called the big blind and now has " + playerStacks[button-1]);
	}
}

};
var postBlinds = function() {
if (playerNum == 2 && button == 1) {
playerStacks[button-1] = playerStacks[button-1]-SB;
playerStacks[button] = playerStacks[button]-BB;
document.write("
Player " + (button) + " has posted the small blind and now has " + playerStacks[button-1]);
document.write("
Player " + (button+1) + " has posted the big blind and now has " + playerStacks[button]);
}
else if(playerNum == 2 && button == 2) {
playerStacks[button-1] = playerStacks[button-1]-SB;
playerStacks[button-2] = playerStacks[button-2]-BB;
document.write("
Player " + (button) + " has posted the small blind and now has " + playerStacks[button-1]);
document.write("
Player " + (button-1) + " has posted the big blind and now has " + playerStacks[button-2]);
}
else if(button<(playerNum-1) && button>=1){
playerStacks[button] = playerStacks[button]-SB;
playerStacks[button+1] = playerStacks[button+1]-BB;
document.write("
Player " + (button+1) + " has posted the small blind and now has " + playerStacks[button]);
document.write("
Player " + (button+2) + " has posted the big blind and now has " + playerStacks[button+1]);
}else if(button==(playerNum-1)){
playerStacks[button] = playerStacks[button]-SB;
playerStacks[0] = playerStacks[0]-BB;
document.write("
Player " + (button+1) + " has posted the small blind and now has " + playerStacks[button]);
document.write("
Player 1 has posted the big blind and now has " + playerStacks[0]);
}else {
playerStacks[0] = playerStacks[0]-SB;
playerStacks[1] = playerStacks[1]-BB;
document.write("
Player 1 has posted the small blind and now has " + playerStacks[0]);
document.write("
Player 2 has posted the big blind and now has " + playerStacks[1]);
}
Pot = BB+SB;
document.write("
Pot size is " + Pot);
preFlop();
};
var selectButton = function(){
var msg = "Enter the number of the player who will deal the first hand:";
do {
button = parseInt(prompt(msg, "1"));
document.write("
" + "Button is player " + button + ".");
if(button > playerNum || button <= 0) {
msg = "You only have " + playerNum + " players. Enter the number of the player who will deal the first hand:";
document.write(msg);
}
} while (button > playerNum || button <= 0);
postBlinds();
};

var setStackSizes = function(){
playerStacks = [];
document.write("
");
var i = 0;
do {
playerStacks[i] = parseFloat(prompt("Player "+(i+1) + " enter your buy-in:"));
if(playerStacks[i]>=(2*BB)){
i++;
}
} while(i

document.write(playerStacks);
selectButton();

};

var setBlinds = function(){
BB = parseFloat(prompt("Enter Big Blind:"));
if(BB>0){
SB = BB/2;
document.write("
Small Blind/Big Blind is $" + SB + "/" + BB);
setStackSizes();
}else{
setBlinds();
}
};

var startGame = function(){
var msg = "Enter number of players:";
do {
playerNum = parseInt(prompt(msg, ""));
if (playerNum > 9 || playerNum < 2) {
msg = "Games can have 2-9 players. Enter number of players:";
document.write("Games can have 2-9 players. You entered "+playerNum+" players.
");
} ;
} while (playerNum > 9 || playerNum < 2);

document.write(playerNum + " players");
setBlinds();

};

startGame();


#2

I think you can do for the rest :slight_smile:

var Flop = function() {

};
var bbRaise = function() {
var Rmsg = "To what amount are you raising?";
do {
Raise = parseFloat(prompt(Rmsg, ""));
if(Raise < 2*BB || Raise > playerStacks[button]+BB) {
Rmsg = "Invalid amount. To what amount are you raising?";
};

    }while(Raise < 2*BB || Raise > playerStacks[button]+BB);
	playerStacks[button] = playerStacks[button] - (Raise-BB);
	document.write("<br/>Player 2 has raised to " + Raise + " and now has " + playerStacks[button]);
	Pot = Pot + (Raise-BB);
	document.write("<br/>Pot size is " + Pot);

};
var sbRaise = function() {
var Rmsg = "To what amount are you raising?";
do {
Raise = parseFloat(prompt(Rmsg, ""));
if(Raise < 2*BB || Raise > playerStacks[0]+SB) {
Rmsg = "Invalid amount. To what amount are you raising?";
};

	}while(Raise < 2*BB || Raise > playerStacks[0]+SB);
	playerStacks[button-1] = playerStacks[button-1] - (Raise-SB);
	document.write("<br/>Player 1 has raised to " + Raise + " and now has " + playerStacks[button-1]);

};

var preFlop = function() {
var msg = " choose action (Call, Raise or Fold):";
var BBmsg = "Big Blind choose action (Check or Raise):";
if(playerNum == 2 && button == 1) {
Action = prompt("Player " + button + msg, "Call");
if(Action == "Call"){
playerStacks[button-1] = playerStacks[button-1]-SB;
console.log("Player " + button + " has called the big blind and now has " + playerStacks[button-1]);
Pot = Pot+SB;
console.log("Pot size is " + Pot);
Action = prompt("Player 2 " + BBmsg, "Check");
if(Action == "Check") {
Flop();
}
else {
bbRaise();
}
}
else if (Action == "Raise") {
sbRaise();
Pot = Pot + (Raise-SB);
console.log("
Pot size is " + Pot);
Action = prompt("Player 2" + msg, "Call");
if(Action == "Call") {
playerStacks[button] = playerStacks[button] - (Raise-BB);
console.log("
Player 2 calls and has " + playerStacks[button] + ".");
Pot = Pot + (Raise-BB);
console.log("
Pot size is " + Pot);
}

}
if(playerStacks[button-1] === 0) {
		console.log("<br/>Player 1 is all in.");
	}
if(playerStacks[button] === 0) {
		console.log("<br/>Player 2 is all in.");
	}

}
else if(playerNum == 2 && button === 2) {
Action = prompt("Player " + button + msg, "Call");
if(Action == "Call"){
playerStacks[button-1] = playerStacks[button-1]-SB;
console.log("
Player " + button + " has called the big blind and now has " + playerStacks[button-1]);
}
}
}
var postBlinds = function() {
if (playerNum == 2 && button == 1) {
playerStacks[button-1] = playerStacks[button-1]-SB;
playerStacks[button] = playerStacks[button]-BB;
console.log("Player " + (button) + " has posted the small blind and now has " + playerStacks[button-1]);
console.log("Player " + (button+1) + " has posted the big blind and now has " + playerStacks[button]);
}
else if(playerNum == 2 && button == 2) {
playerStacks[button-1] = playerStacks[button-1]-SB;
playerStacks[button-2] = playerStacks[button-2]-BB;
console.log("Player " + (button) + " has posted the small blind and now has " + playerStacks[button-1]);
console.log("Player " + (button-1) + " has posted the big blind and now has " + playerStacks[button-2]);
}
else if(button<(playerNum-1) && button>=1){
playerStacks[button] = playerStacks[button]-SB;
playerStacks[button+1] = playerStacks[button+1]-BB;
console.log("Player " + (button+1) + " has posted the small blind and now has " + playerStacks[button]);
console.log("Player " + (button+2) + " has posted the big blind and now has " + playerStacks[button+1]);
}else if(button==(playerNum-1)){
playerStacks[button] = playerStacks[button]-SB;
playerStacks[0] = playerStacks[0]-BB;
console.log("Player " + (button+1) + " has posted the small blind and now has " + playerStacks[button]);
console.log("Player 1 has posted the big blind and now has " + playerStacks[0]);
}else {
playerStacks[0] = playerStacks[0]-SB;
playerStacks[1] = playerStacks[1]-BB;
console.log("Player 1 has posted the small blind and now has " + playerStacks[0]);
console.log("Player 2 has posted the big blind and now has " + playerStacks[1]);
}
Pot = BB+SB;
console.log("Pot size is " + Pot);
preFlop();
};

var selectButton = function(){
var msg = "Enter the number of the player who will deal the first hand:";
do {
button = parseInt(prompt(msg, "1"));
console.log(" " + "Button is player " + button + ".");
if(button > playerNum || button <= 0) {
msg = "You only have " + playerNum + " players. Enter the number of the player who will deal the first hand:";
console.log(msg);
}
} while (button > playerNum || button <= 0);
postBlinds();
};

var setStackSizes = function(){
playerStacks = [];
console.log("");
var i = 0;
do {
playerStacks[i] = parseFloat(prompt("Player "+(i+1) + " enter your buy-in:"));
if(playerStacks[i]>=(2*BB)){
i++;
}
} while(i)
console.log(playerStacks);
selectButton();
};

var setBlinds = function(){
BB = parseFloat(prompt("Enter Big Blind:"));
if(BB>0){
SB = BB/2;
console.log("Small Blind/Big Blind is $" + SB + "/" + BB);
setStackSizes();
}else{
setBlinds();
}
};

var startGame = function(){
var msg = "Enter number of players:";
do {
playerNum = parseInt(prompt(msg, " "));
if (playerNum > 9 || playerNum < 2) {
msg = "Games can have 2-9 players. Enter number of players:";
console.log("Games can have 2-9 players. You entered "+playerNum+" players.");
}
} while (playerNum > 9 || playerNum < 2);

console.log(playerNum + " players");
setBlinds();
};

startGame();


#3

I'm using notepad++ and can't get console.log to work. What would you recommend I use?


#4

you won't see console results on your browser page you need to open your console on your browser.. (right click- inspect/ ctrl+shift+i)