This is part of the Texas Holdem program I posted a little while back, but I think the huge amount of code I posted was daunting. I'm posting just the problem area.

So, this is the code I wrote for analyzing sets of 7 cards held by 5 players in Holdem Poker (2 cards in the player's hand, and 5 on the table). It analyzes all 7 cards and picks the best 5 of them. It then gives a value to each player's hand and stores those values to a list. I then use this for smart computer betting and to determine who actually won.

The problem I have is that its pretty slow. It used to be all lists and I found a way to use a matrix for half of the analysis and that improved the speed a bit. I'm hoping someone out there sees some other method I can use to improve speed. Any ideas?

H is the number of cards shown. I have it set to 7 for simplification.

N is the number of computer players.

⌊D is the deck of cards, with unneeded extras deleted.

⌊H is the current player's 7 cards.

⌊V Temporarily stores the player's hand value.

```
4→N
7→H
DelVar L₃
Disp "DEAL"
rand(52→L₂
seq(A/4,A,8,59→⌊D
SortA(L₂,⌊D
DelVar L₂
7+2N→dim(⌊D
For(θ,0,N
Disp "CALCULATING
Disp "PLAYER "
Disp θ
"MAKES LIST OF CARDS FOR PLAYER θ"
{1→⌊V
{⌊D(1+2θ),⌊D(2+2θ→⌊H
For(B,3,7)
⌊D(2(N+1)-2+B)→⌊H(B)
End
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₂
"ACE FOR STRAIGHT"
L₂(14)→L₂(1)
"FLUSH"
"ROYAL IS 10,STRAIGHT IS 9"
If max(L₁)>4
Then
"NOT COMPLETE"
"DOESNT LOOK FOR STRAIGHT OR ROYAL"
{6}→⌊V
End
If ⌊V(1)>8
Goto F
"FOUR"
If max(L₂)=4
Then
For(A,14,2,0-1)
If L₂(A)=4
Then
{8,A}→⌊V
2→A
End
End
For(A,14,2,0-1)
If L₂(A) and A≠⌊V(2)
Then
A→⌊V(3)
2→A
End
End
End
If ⌊V(1)>7
Goto F
"FULL HOUSE"
If max(L₂)=3
Then
For(A,14,2,1)
If L₂(A)=3
Then
{4,A}→⌊V
2→A
End
End
For(A,14,2,0-1)
If L₂(A)>1 and A≠⌊V(2)
Then
{7,⌊V(2),A}→⌊V
2→A
End
End
End
If ⌊V(1)>6
Goto F
"STRAIGHT"
If H>4
Then
For(A,1,10
If prod(L₂,A,A+4)
{5,A,A+1,A+2,A+3,A+4}→⌊V
End
End
If ⌊V(1)>4
Goto F
"THREE"
If ⌊V(1)>3
Then
"FINISHES THREE"
3→B
For(A,14,2,1)
If A≠⌊V(2
Then
A→⌊V(B
B+1→B
If dim(⌊V)=5
2→A
End
End
End
If ⌊V(1)>3
Goto F
"PAIR"
If max(L₂)=2
Then
"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
End
If ⌊V(1)>1
Goto F
"HIGH CARD"
augment({1},int(⌊H→⌊V
Lbl F
6→dim(⌊V
2⌊V(1)+⌊V(2)+⌊V(3)/2+⌊V(4)/4+⌊V(5)/6+⌊V(6)/8→L₃(θ+1)
End
"IGNORE THIS PART"
ClrDraw
Line(1,49,1,63
Line(1,63,21,63
Line(11,63,11,49
Line(21,49,1,49
Line(21,49,21,63
Line(95,63,45,63
Line(95,63,95,49
Line(95,49,45,49
Line(45,49,45,63
For(A,55,95,10
Line(A,50,A,62
End
Text(1,2,sub("A23456789TJQKA",int(⌊D(1)),1
Text(7,2,sub("SHCD",1+4fPart(⌊D(1)),1
Text(1,12,sub("A23456789TJQKA",int(⌊D(2)),1
Text(7,12,sub("SHCD",1+4fPart(⌊D(2)),1
For(A,0,4)
Text(1,46+10A,sub("A23456789TJQKA",int(⌊D(2(N+1)+(A+1))),1
Text(7,46+10A,sub("SHCD",1+4fPart(⌊D(2(N+1)+(A+1))),1
End
For(A,2,N+1
Text(19,19A+2-19,"AI",A-1
Text(27,19A+2-19,sub("A23456789TJQKA",int(⌊D(2(A-1)+1)),1),sub("SHCD",1+4fPart(⌊D(2(A-1)+1)),1)
Text(35,19A+2-19,sub("A23456789TJQKA",int(⌊D(2(A-1)+2)),1),sub("SHCD",1+4fPart(⌊D(2(A-1)+2)),1)
End
```