I've been working on this program for a really long time. It's Texas Holdem Poker and is very nearly functional. It deals cards to a human player and 1-4 computer players, it analyzes the hand of each player when cards get shown(flop,turn,river), and determines what each of the players has. It allows for basic betting (right now the human player raises and the comps match, and I'm working on smart comps that use the analyzed hands to make a decision on check/bet/fold). If anyone wants to look at it and give help or criticism, I would welcome the input.

I'm slowly continuing to work toward completion. As I update a portion of the program I'm going to upload the update(ex. PROGRAM(2) is newer than PROGRAM(1)). The program is broken into individual parts right now to make editing easier.

Hand analysis is still too slow, and I'm working on improving the math. Updates are coming.

UPDATE 2/15/2016

Betting now ends when all AI players fold.

After betting, the cards are shown for all players that did not fold.

Substantial updates to prgmWINNER. It now allows for every type of split pot (this one was very difficult)

Pair and 2 Pair detection is now finished

Many interface changes. Not polished yet, but functional.

UPDATE 2/4/2016

Optimized prgmBET

Hand value is no longer calculated for folded player. Also, hand value of human player is not calculated throughout betting now.

UPDATE 2/3/2016

Added optimization to prgmSTRAIGHT. Thank you kg583

Fixed text during betting

Found and fixed a problem in prgmBET that was only letting 4 of the 5 players bet after a raise.

Modified prgmWINNER so its easier to see what everyone's cards are while I'm fixing bugs.

2/2/16

Attached here is the very alpha version of Holdem. I have in quotes throughout the program to help me remember where parts of the code are. Please give feedback. I am also posting the code as a forum attachment since I cannot yet create links to Google Drive.

I'm still working on the code, but the following areas aren't complete:

-Doesn't show how much money you have total(PSAVE(6)), only how much of the current buy-in remains(PSAVE(1))

-Running out of money means nothing yet. When finished, it will cause that player to be replaced in regular holdem, and will cause the number of opponents to drop in tournament mode.

-Human player cannot fold yet. When complete, AI will keep playing after human folds.

-AI players won't raise after the flop yet, only check, call, and fold.

-Using a very basic method of determining value for AI players. They fold way too much.

-Using a basic Chen formula on the flop, and it needs adjustments.

-Hand analysis calculations are still slow on a TI-83. Slowly improving the math, **but any help here is welcome**.

-The program is still separated into many parts to make editing easier.

-Right now it uses a many lists. I am gradually combining lists and using variables instead.

Haven't yet finished the FLUSH portion. It doesn't look for straight or royal yet. It's on my to do list.

I haven't optimized anything for size yet. My focus has been on functionality.

```
A1POKER
Full
1→Xmin
95→Xmax
1→Xscl
1→Ymin
63→Ymax
1→Yscl
AxesOff
Lbl NW
6→dim(⌊PSAVE
"L IS BLIND"
"THIS SHOULD RESET FOR EVERY NEW TOURNAMENT"
1→L
If ⌊PSAVE(6
Menu("WELCOME","LOAD GAME",S,"RESET GAME",N,"EXIT",E,"SAME CARDS",SC
If not(⌊PSAVE(6
Menu("WELCOME","NEW GAME",N,"EXIT",E
Lbl E
DelVar L₁DelVar L₂DelVar L₃
Stop
Lbl N
If ⌊PSAVE(6
Menu("OVERWRITE","YES",YS,"NO",NW
Lbl YS
1000→⌊PSAVE(6
Lbl S
10
Menu("GAME TYPE","100 NO LIMIT",1,"1000 NO LIMIT",2,"10000 NO LIMIT",3
Lbl 3
10Ans
Lbl 2
10Ans
Lbl 1
10Ans
augment(seq(2,A,1,5),{⌊PSAVE(6)-Ans→⌊PSAVE
"LPSAVE 6 IS THE STARTING AMOUT SO WE KNOW HOW BIG BLINDS ARE"
5→N
Lbl D
Disp "DEALING"
rand(52→L₁
seq(A/4,A,8,59→L₆
SortA(L₁,L₆
5+2N→dim(L₆
Lbl SC
"DRAW CARDS"
ClrDraw
45→A
49→B
63→C
95→D
Text(57,50,"YOU BET:
Line(B,7,D,7
Line(B,7,B,1
Line(1,B,1,C
Line(1,C,21,C
Line(11,C,11,B
Line(21,B,1,B
Line(21,B,21,C
Line(D,C,A,C
Line(D,C,D,B
Line(D,B,A,B
Line(A,B,A,C
For(A,55,D,10
Line(A,50,A,62
End
For(A,1,2
Text(1,10(A=2)+2,sub("A23456789TJQKA",int(L₆(A)),1
Text(7,10(A=2)+2,sub("SHCD",1+4fPart(L₆(A)),1
End
"S IS THE NUMBER OF CARDS SHOWN"
DelVar S
While S<6
For(A,1,S
int(L₆(2N+A
Text(1,36+10A,sub("A23456789TJQKA",Ans,1
1+4fPart(L₆(2N+A
Text(7,36+10A,sub("SHCD",Ans,1
End
If S
prgmHANDS
Text(51,0,"BET ROUND ",1+(S>0)+(S>3)+(S>4)," -
Text(57,0,"USE ARROWS
prgmBET
"THIS IS FLOP, TURN, AND RIVER"
S+1+2(S=0→S
End
prgmWINNER
1+L(L<N→L
Goto D
```

```
BET
"L IS LITTLE BLIND"
"S IS NUMBER OF CARDS SHOWN"
"M IS CURRENT BETTER"
"R IS RAISE"
"P IS THE POT"
"L₃ IS THE BETS"
DelVar R
L→M
"BLINDS"
If S=0
Then
DelVar ⌊BET
N→dim(⌊BET
seq(1,A,1,N→⌊WIN
DelVar P
1+L(L<N→M
2→⌊BET(L
4→⌊BET(M
Text(6L+15,0,"PL",L," HAS: ",⌊PSAVE(L)-int(⌊BET(L))," BET:",2
Text(6M+15,0,"PL",M," HAS: ",⌊PSAVE(M)-int(⌊BET(M))," BET:",4
1+M(M<N→M
End
While R<N
Line(80,45-6M,90,45-6M
Line(80,45-6M,82,47-6M
Line(80,45-6M,82,43-6M
int(max(⌊BET→B
If M>1
Then
If S=0 and ⌊WIN(M)≠0
prgmDRAW
If S>0 and ⌊WIN(M)≠0
prgmFLOP
Else
B→A
getKey
Repeat X=105
Text(57,77,A," "
getKey→X
A+(X=25→A
A-(X=34→A
A-10(X=24→A
A+10(X=26→A
If A<B
B→A
End
A→B
End
R+1→R
If B>int(max(⌊BET
1→R
If 0≠⌊WIN(M)
B+fPart(⌊BET(M→⌊BET(M
"SHOW TEXT"
If ⌊WIN(M)≠0
Text(6M+15,0,"PL",M," HAS: ",⌊PSAVE(M)-int(⌊BET(M))," BET:",int(⌊BET(M))," "
If ⌊WIN(M)=0
Text(6M+15,0,"PL",M," HAS: ",⌊PSAVE(M)-int(⌊BET(M))," FOLDED
Text(0,22,"POT:
Line(80,45-6M,90,45-6M,0
Line(80,45-6M,83,48-6M,0
Line(80,45-6M,83,42-6M,0
1+M(M<N→M
If sum(⌊WIN)=max(⌊WIN)
Then
Disp "EVERYONE FOLDED"
5→S
N→R
End
End
For(A,1,N
If 0≠⌊WIN(A)
Text(6A+15,54," "
End
For(A,1,N
⌊PSAVE(A)-int(⌊BET(A)→⌊PSAVE(A
End
.01(100fPart(⌊BET)+int(⌊BET))→⌊BET
"SHOW POT"
Text(6,22,100sum(fPart(⌊BET))," "
```

```
DRAW
"B IS HIGH BET"
{L₆(2M),L₆(2M-1)}→⌊J
"CHENFORMULA"
"STEP 1"
int(max(⌊J→U
int(min(⌊J→V
10(U=14)+8(U=13)+7(U=12)+6(U=11)+.5U(U<11)→W
"STEP 2"
If U=V
2W→W
"STEP 3"
If fPart(⌊J(1))=fPart(⌊J(2))
W+2→W
"STEP 4"
If U=V+2 or U=14 and V=3
W-1→W
If U=V+3 or U=14 and V=4
W-2→W
If U=V+4 or U=14 and V=5
W-4→W
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
W-5→W
"STEP 5"
If U=V+1 and U<13
W+1→W
If U=V+2 and U<13
W+1→W
round(W,0)→W
"FOLD"
If W<6 and B>5 or W<9 and B>10
0→⌊WIN(M)
If 0=⌊WIN(M)
Disp "FOLDED"
"RAISE"
If W≥12 and B≤10 or W≥9 and B≤5
2B→B
"CHECKCALL"
Disp "CHEN
Disp W
```

```
FLOP
"HANDVALUE"
⌊WIN(M)→K
0→C
"ADDS CARD VALUE"
If K>200
.25+(K-200)/100→C
If K>300
.5+(K-300)/100→C
If K>400
.75+(K-400)/100→C
If K>500
1→C
"PERCENT"
"1PAIR10"
"2PAIR25"
"THREE50"
"FLUSH75"
"FULLANDABOVE100"
"DOESNT ANTICIPATE HANDS YET"
(B/(sum(int(⌊BET))+100sum(fPart(⌊BET)→K
If K>C
0→⌊WIN(M)
Disp K
Disp C
If 0=⌊WIN(M)
Disp "FOLDED"
```

```
FLUSH
"NOT COMPLETE"
"DOESNT LOOK FOR STRAIGHT OR ROYAL"
{6}→⌊V
```

```
FOUR
For(A,2,14)
If 4=L₂(A
{8,A}→⌊V
End
For(A,2,14)
If L₂(A) and A≠⌊V(2
A→⌊V(3
End
```

```
FULLHOUS
For(A,14,2,1)
If L₂(A)=3
Then
{4,A→⌊V
2→A
End
End
For(A,14,2,1
If L₂(A)>1 and A≠⌊V(2
Then
{7,⌊V(2),A→⌊V
2→A
End
End
```

```
HANDS
"IS THIS NEEDED, CAN DO DIM(LH"
S+2→H
For(θ,1+(S≠5),N
Text(51,0,"CALCULATING
Text(57,0,.92θ/(N)," PERCENT
If ⌊WIN(θ)
Then
{1→⌊V
"CURRENT PLAYERS CARDS"
augment({L₆(2θ-1),L₆(2θ)},seq(L₆(2N-2+A),A,3,S+2→⌊H
"IS THIS NEEDED"
SortD(⌊H
"MATRIX"
DelVar [A]
{14,4}→dim([A]
For(A,1,H
1→[A](int(⌊H(A)),1+4fPart(⌊H(A
End
"FLUSH LIST"
Matrlist((cumSum([A])),14,L₁
"PAIR, TRIP, QUAD LIST"
Matrlist((cumSum([A])),4,L₂
"LOOK FOR FLUSH ROYAL AND REGULAR FLUSH(10, 9, and 6)"
If max(L₁)>4
prgmFLUSH
If ⌊V(1)>8:Goto F
If max(L₂)=4
prgmFOUR
If ⌊V(1)>7:Goto F
If max(L₂)=3
prgmFULLHOUS
If ⌊V(1)>6:Goto F
If H>4:prgmSTRAIGHT
If ⌊V(1)>4:Goto F
If ⌊V(1)>3:prgmTHREE
If ⌊V(1)>3:Goto F
If max(L₂)=2
prgmPAIR
If ⌊V(1)>1:Goto F
prgmHIGHCARD
Lbl F
6→dim(⌊V
2⌊V(1)+⌊V(2)+⌊V(3)/2+⌊V(4)/4+⌊V(5)/6+⌊V(6)/8→⌊WIN(θ
End
End
```

```
HIGHCARD
augment({1},int(⌊H→⌊V
```

```
PAIR
"ONE-PAIR"
For(A,14,2,1)
If L₂(A)=2
Then
{2,A→⌊V
"TWO-PAIRS"
For(B,A,2,1)
If L₂(B)=2 and B≠A
Then
{3,A,B→⌊V
2→B
End
End
2→A
End
End
"FINISH 1"
If 2=⌊V(1
Then
For(A,14,2,1)
If L₂(A) and A≠⌊V(2
A→⌊V(1+dim(⌊V
If 5=dim(⌊V
2→A
End
End
"FINISH 2"
If 3=⌊V(1
Then
For(A,14,2,1)
If L₂(A) and A≠⌊V(2 and A≠⌊V(3
Then
A→⌊V(4
2→A
End
End
End
```

```
STRAIGHT
"ACE"
L₂(14→L₂(1
For(A,1,10
If prod(L₂,A,A+4
{5,A,A+1,A+2,A+3,A+4→⌊V
End
```

```
THREE
"FINISHES THREE"
3→B
For(A,14,2,1)
If A≠⌊V(2) and L₂(A
Then
A→⌊V(B
B+1→B
If dim(⌊V)=5
2→A
End
End
```

```
WINNER
For(A,2,N)
If ⌊WIN(A
Then
Text(6A+15,70,sub("A23456789TJQKA",int(L₆(2(A-1)+1)),1),sub("SHCD",1+4fPart(L₆(2(A-1)+1)),1),",
Text(6A+15,81,sub("A23456789TJQKA",int(L₆(2(A-1)+2)),1),sub("SHCD",1+4fPart(L₆(2(A-1)+2)),1)
End
End
Pause
100⌊BET→⌊BET
Disp ⌊WIN
Disp ⌊BET
While sum(⌊BET)>0
0→dim(L₅
For(A,1,5
If ⌊WIN(A)=max(⌊WIN)
⌊BET(A)→L₅(dim(L₅)+1
End
min(L₅→X
Disp X
⌊BET-X→⌊BET
5X→X
For(A,1,5
If ⌊BET(A)≤0
Then
X+⌊BET(A)→X
0→⌊BET(A)
End
End
max(⌊WIN→B
For(A,1,5
If ⌊WIN(A)=B
Then
⌊PSAVE(A)+X/dim(L₅)→⌊PSAVE(A)
If ⌊BET(A)=0
0→⌊WIN(A)
End
End
End
Disp "PAYING WINNER"
```

Well I must say that is quite the lengthy program. Though I haven't had the time to review the whole thing, here are just a couple of little optimization things I've noticed:

Simplify math expressions:

```
:If B=62-26-26
can be
:If B=10
```

Try to use piecewise functions where possible:

```
:If B=10
:B+8→B
can be
:B+8(B=10→B
```

Certain conditional tests can be shortened:

```
:If L₂(A) and L₂(A+1) and L₂(A+2) and L₂(A+3) and L₂(A+4)
can be
:If L₂(A)L₂(A+1)L₂(A+2)L₂(A+3)L₂(A+4)
can even be
:If prod(L₂,A,A+4)
```

Re-order expressions to remove closing parentheses and brackets

```
:If L₂(A)=2
can be
:If 2=L₂(A
```

Simplify powers of ten using the E operator ([2ND][,]) or 10^x ([2ND][LOG]):

```
:.25+(K-200)/100→C
can be
:.25+E-2(K-200→C
can be
:.25+10^(-2)(K-200→C
```

There are other little bits and pieces that can be shortened, and I haven't able to study to entire game just yet to look for bugs. Otherwise, I'd say you have a nice program here.

The solution to a complex problem is often a simple answer.

Thank you for your input. I really like those optimizations. I understand its a little messy right now, and that's because I have been focused on functionality. I'm not very focused on making it smaller just yet. I welcome any criticism and I'll do my best to incorporate any ideas you guys have.