Here is the code with notes included.
E IS BUY-IN AMOUNT
L IS LITTLE BLIND, RESET EVERY GAME
M IS CURRENT BETTER
N IS THE NUMBER OF PLAYERS
R IS BET RAISE
P IS THE CURRENT BETTERS VALUE
S IS NUMBER OF CARDS SHOWN
L₁ IS FLUSH LIST
L₂ IS PAIR, TRIP, QUAD LIST
L₃ IS BETS
L₄ WILL BE TEMP PKR
L₅ IS WIN MONEY
L₆ IS DEAL
Sets up graph screen
Store card values as STR1. Stores LPRK as L4 during gameplay to reduce game size. L4 has a sforter name.
Looks for existing game. If not found, sets up new game w/ 1000 credits.
Disp "YOU HAVE
Menu("WELCOME","HOLDEM",HM,"SIT N GO",T,"VIEW MONEY",NW,"RESET GAME",N,"EXIT",E
Begin regular holdem or tournament. For tournament, if player doesn't have enough credits to join that value tournament it jumps back to the menu. For Holdem, it deducts 100 credits or the amount of credits you have remaining. The DelVar L resets little blind to player 0.
B=2 and A>L₄(6→C
Pause "NOT ENOUGH MONEY
The game is about to deal cards to each player. Before that, it looks for players that ran out of money on the last round. In Holdem, it simply resets that player to 100 credits. For Tournament, it removes that player.
Here it removes and resets players. When it removes a player that ran out of money in Tournament mode, it shifts the remaining players to the left so that there are no empty spots in L4.
If A<5 and 2=L₄(7
Sets the number of players by looking for values above 0 in the first 5 places of L4. This applies to Tournaments.
Looks at L4(1) to see if you lose. In Holdem it takes me back to the home screen. In Tournament, it checks to see whether you came in 2nd or 3rd place and pays if you did.
If 2=L₄(7) and not(L₄(1
Disp "YOU WIN"
Looks at L4(2-5) to see if you win. Pays out and sends you back to the home screen. This doesn't do anything in Holdem, just Tournament.
Deals cards. This is the standard deal you can find on the site.
Adds +1 to little blind. If little blind exceeds the number of players, its sets to 1.
Draws the cards and sets up the text on the graph screen. I used variables because many of the points intersect and it saves a few bytes.
S is the number of cards shown. 3 is flop, 4 is turn, 5 is river.
It's about to analyze the cards and give a value for each player. It only analyzes the cards currently shown, so the AI doesn't get to cheat and see the Flop, Turn, and River until the human player does. The down side of this is that it has to analyze the cards more than once. It only analyzes from the Flop onward. The game uses a modified Chen formula for the Draw.
Here it displays the cards. First none, then 3, then 4, then 5.
Now begins to analyze the hands when S is greater than 0. It displays the status on the graph screen.
Tells it to only calculate players that have not folded. When a player folds it sets that player's LWIN value to 0. Each player's LWIN status is set to 1 a little later during Flop betting.
Sets up the current player's cards as LH. It only sets up cards that are shown.
Sets up 2 matrices. One provides a fast way of detecting a flush, and the other gives a fast way of detecting pairs, trips, and fours. It doesn't know yet what cards have those values, just that they exist. It sets the Ace L2(14) to L2(1) so the program correctly finds Straights and Straight Flushes.
If L1 has a number 5 or greater, it means this player has a flush. The code then runs to determine which cards make up the sequence. It will also determine whether is has a royal flush or straight flush. The value stored to LV(1) shows what the player has. 6 means flush, 9 means straight flush, 10 means royal flush.
Looks for Royal and Straight Flush
If ⌊H(A)>9 and 1=prod(List(⌊H),A,A+3
If ⌊V(1)<9 and 1=prod(List(⌊H),A,A+3
Looks for regular Flush
If a Royal or Straight flush is found, jump to the Lbl F because further analysis isn't needed.
If L2 has a max of 4, it means Four of a Kind exists. If then looks for the cards the player has 4 of and sets that to LV(2). It then looks for the kicker and stores to LV(3). If 2 players have the same Four of a Kind, the kicker decides the winner. It then goes to Lbl F because V is 8.
If L₂(A) and A≠⌊V(2
This looks for Three of a Kind and a Full House. I combined them because it makes no sense to do the same math twice. Works in the same way as Four of a Kind.
If L₂(A)>1 and A≠⌊V(2
Looks for a Straight. If found, stores to LV and goes to Lbl F.
If Three of a Kind was found when looking for a Full House, it looks for the remaining 2 cards.
If A≠⌊V(2) and L₂(A
Looks for Pairs and 2 Pairs
If L₂(B)=2 and B≠A
If L₂(A) and A≠⌊V(2
If L₂(A) and A≠⌊V(2) and A≠⌊V(3)
If nothing was found (LV(1) is still 1), it stores the player's 5 highest cards to Lv(2-6)
Stores all players hand value to LWIN. Each player now has a value of at least 1.
This is the end of the hand analysis. Now it moves on to betting.
Resets R, which is the number of times the sequence has run without a bet being raised. This makes sure each player bets after a raise. Stores L to M. M is the current better, and should start with the little blind.
If S=0 (We are at the Draw) it puts in the little and big blinds. L3 is the list of bets. If the player doesn't have enough money to put in, it puts them all-in.
Displays each player's number of credits.
If S and ⌊WIN(A) and L₄(A
Begins the betting, and keeps going until R=N
Stores the current better's number of credits to P to save space in the code. Displays text of who the current better is. Draws an arrow pointing toward the better.
B is the highest bet. This will be the minimum that any player can bet. If little and big blinds are all-in and were not able to put in the whole 4 credits, it still makes sure that 4 is the minimum bet.
If B<4 and not(S
The is where and AIs bet. The first part is a modified Chen formula, and only runs on the Draw. The second part uses the values from the hand analysis and the player checks, calls, bets, and folds depending on the value of LWIN(M)
Here is the Chen formula.
If M>1 and ⌊WIN(M) and P and P≠int(L₃(M
"B IS HIGH BET"
If U=V+2 or U=14 and V=3
If U=V+3 or U=14 and V=4
If U=V+4 or U=14 and V=5
If U-V>4 and U<14 or U=14 and V=8 or U=14 and V=7 or U=14 and V=6
If V+1=U and U<13
If V+2=U and U<13
If W<6 and B>5 or W<9 and B>10
If W≥12 and B≤10 or W≥9 and B≤5
Here is the code for Flop onward. It values the size of the pot against the current minimum bet and the player's hand value. The square is the little E.
If K-.25>C and not(B
Human betting. Up/down/left/right adjust the bet.
If M=1 and ⌊WIN(M) and P and P≠int(L₃(M
If X=24 or X=34
If X=25 or X=26
Adds +1 to R. If the bet was increased, it resets R to 1 to continue betting.
If the player didn't fold and they have enough money, add the bet to the integer part of L3(M)
If the player didn't fold and they don't have enough money, the players entire value will be stored to L3(M)
If B≤P and ⌊WIN(M
If B>P and ⌊WIN(M
Display the amount the current better put in. If they folded, show folded. If they are all-in, show all-in.
If not(P) or P=int(L₃(M
Remove the arrow that was drawn next to the better.
Add +1 to M so it moves on to the next better. If M is greater than the number of betters, it sets M to 1.
If all players folded and only one player remains, end betting immediately.
Betting is not complete for this round. This subtracts the player's bets from L4. These bets are the integer part of L3.
Stores the integer part of L3 as the fpart of L3.
Displays the pot.
Betting is complete. This displays the cards of all players that didn't fold and sets the fpart of L3 to a whole number again.
This code looks for winners and pays them accordingly. It handles possible combination of winners(multiple winners, multiple all-in players with different bets, etc). I'm quite proud of what I did here. It wasn't really complicated math, but it was hard figuring out the right way to execute it.
It looks for players with the highest LWIN value and pays out the lowest amount that the the player put in. For example, if 2 players has the highest valued cards, one put in 25 and the other put in 30, then it will subtract 25 from all players and divide the money between the 2 winners. It first looks for players that didn't have 25, and subtract the difference from the winnings. The L3 of the 25 player is now at 0 so he isn't included in the next sequence. It continues until all L3s are at 0.
This part is graphical only and tells the player to push enter to continue playing or clear to go back to the home screen.
Repeat B=105 or B=45
Exits back to the home screen. It does this by setting L4(1) to zero. If you are playing regular Holdem, it first moves your money back to L4(6). It still goes back to Lbl D because it will go back to the code that looks for you to be 2nd or 3rd place winner in Tournament. It will then pay you what you won and send you back to the home screen.
If B=45 and 1=L₄(7
Disp "YOU GET