kitchenrange
12-27-2010, 06:57 AM
So I have a function that returns an array of an array of integers. I want to do things based off of those integers, but I'm having a hard time.
I have tried declaring a multidimensional array of the correct size and setting it equal to the function(we'll say Values). Then accessed the parts through the variable name (Values[0][0] etc.) but that didn't work. This does, however, compile.
I have tried
if FunctionName[0][0] then
but that doesn't work either. It returns a compilation error.
Has anyone ever done something similar to this?
I'm guessing I'll need the code up here for simplicity.
This is the function that returns the multidimensional array.
function CheckCopies : array[0..2] of array[0..1] of Integer;
var
i, p, y, u, s, SetOne, SetTwo, SetThree : integer;
Copies, CopiesTwo, CopiesThree : array of integer;
HandRanks : array[1..7] of Integer;
x : longint;
begin
for i := 1 to 7 do HandRanks[i] := MyHand[i].rank;
for i := 1 to 7 do
begin
if HandRanks[i] = 0 then
begin
x := i - 1;
exit;
end;
i := i + 1;
end;
SetLength(HandRanks, x);
for i := low(HandRanks) to high(HandRanks) do
begin
for p := low(HandRanks) to high(HandRanks) do
begin
if p = i then continue;
if HandRanks[i] = HandRanks[p] then
begin
if SetOne = 0 then
begin
SetOne := HandRanks[i];
SetLength(Copies, 1);
Copies[y] := HandRanks[i];
y := y + 1;
SetLength(Copies, Length(Copies) + 1);
Copies[y] := HandRanks[p];
y := y + 1;
p := p + 1;
Continue;
end else
begin
if SetOne = HandRanks[i] then
begin
Copies[y] := HandRanks[i];
y := y + 1;
p := p + 1;
Continue;
end else
begin
if SetTwo = 0 then
begin
SetTwo := HandRanks[i];
SetLength(CopiesTwo, 1);
CopiesTwo[u] := HandRanks[i];
u := u + 1;
SetLength(CopiesTwo, Length(CopiesTwo) + 1);
CopiesTwo[u] := HandRanks[p];
u := u + 1;
p := p + 1;
Continue;
end else
begin
if SetTwo = HandRanks[i] then
begin
SetLength(CopiesTwo, Length(CopiesTwo) + 1);
CopiesTwo[u] := HandRanks[i];
u := u + 1;
p := p + 1;
Continue;
end else
begin
if SetThree = 0 then
begin
SetThree := HandRanks[i];
SetLength(CopiesThree, 1);
CopiesThree[s] := HandRanks[i];
SetLength(CopiesThree, Length(CopiesThree) + 1);
s := s + 1;
CopiesThree[s] := HandRanks[p];
s := s + 1;
p := p + 1;
Continue;
end else
begin
WriteLn('What the fuck four pairs with seven cards.');
TerminateScript;
end;
end;
end;
end;
end;
end;
p := p + 1;
end;
i := i + 1;
end;
Result[0][0] := SetOne;
Result[0][1] := Length(Copies);
Result[1][0] := SetTwo;
Result[1][1] := Length(CopiesTwo);
Result[2][0] := SetThree;
Result[2][1] := Length(CopiesThree);
end;
This is the functionthat needs to use the results. This is after trying to use the FunctionName[0][0] method.
function RankHand : boolean;
begin
Result := False;
if (CheckFlush = 2) and (FlopCards[1].rank = 0) then
begin
Result := True;
WriteLn('Hand is good because of chance of flush');
end;
if (CheckFlush = 4) and (FlopCards[5].rank = 0) then
begin
Result := True;
WriteLn('Hand is good because of chance of flush');
end;
if (CheckStraight = 4) and (FlopCards[5].rank = 0) then
begin
Result := True;
WriteLn('Hand is good because of chance of straight');
end;
if (CheckCopies[0][0] > 0) and (FlopCards[1].rank = 0) then
begin
Result := True;
WriteLn('Hand is good because I have at least a pair with no flop yet');
end;
if (CheckCopies[1][0] > 0) then
begin
Result := True;
WriteLn('I have two pairs');
end;
if (CheckCopies[0][1] > 2) then
begin
Result := True;
WriteLn('I have three of a kind');
end;
if (CheckFlush = 5) then
begin
Result := True;
WriteLn('I have a flush');
end;
if (CheckStraight = 5) then
begin
Result := True;
WriteLn('I have a straight');
end;
end;
I have tried declaring a multidimensional array of the correct size and setting it equal to the function(we'll say Values). Then accessed the parts through the variable name (Values[0][0] etc.) but that didn't work. This does, however, compile.
I have tried
if FunctionName[0][0] then
but that doesn't work either. It returns a compilation error.
Has anyone ever done something similar to this?
I'm guessing I'll need the code up here for simplicity.
This is the function that returns the multidimensional array.
function CheckCopies : array[0..2] of array[0..1] of Integer;
var
i, p, y, u, s, SetOne, SetTwo, SetThree : integer;
Copies, CopiesTwo, CopiesThree : array of integer;
HandRanks : array[1..7] of Integer;
x : longint;
begin
for i := 1 to 7 do HandRanks[i] := MyHand[i].rank;
for i := 1 to 7 do
begin
if HandRanks[i] = 0 then
begin
x := i - 1;
exit;
end;
i := i + 1;
end;
SetLength(HandRanks, x);
for i := low(HandRanks) to high(HandRanks) do
begin
for p := low(HandRanks) to high(HandRanks) do
begin
if p = i then continue;
if HandRanks[i] = HandRanks[p] then
begin
if SetOne = 0 then
begin
SetOne := HandRanks[i];
SetLength(Copies, 1);
Copies[y] := HandRanks[i];
y := y + 1;
SetLength(Copies, Length(Copies) + 1);
Copies[y] := HandRanks[p];
y := y + 1;
p := p + 1;
Continue;
end else
begin
if SetOne = HandRanks[i] then
begin
Copies[y] := HandRanks[i];
y := y + 1;
p := p + 1;
Continue;
end else
begin
if SetTwo = 0 then
begin
SetTwo := HandRanks[i];
SetLength(CopiesTwo, 1);
CopiesTwo[u] := HandRanks[i];
u := u + 1;
SetLength(CopiesTwo, Length(CopiesTwo) + 1);
CopiesTwo[u] := HandRanks[p];
u := u + 1;
p := p + 1;
Continue;
end else
begin
if SetTwo = HandRanks[i] then
begin
SetLength(CopiesTwo, Length(CopiesTwo) + 1);
CopiesTwo[u] := HandRanks[i];
u := u + 1;
p := p + 1;
Continue;
end else
begin
if SetThree = 0 then
begin
SetThree := HandRanks[i];
SetLength(CopiesThree, 1);
CopiesThree[s] := HandRanks[i];
SetLength(CopiesThree, Length(CopiesThree) + 1);
s := s + 1;
CopiesThree[s] := HandRanks[p];
s := s + 1;
p := p + 1;
Continue;
end else
begin
WriteLn('What the fuck four pairs with seven cards.');
TerminateScript;
end;
end;
end;
end;
end;
end;
p := p + 1;
end;
i := i + 1;
end;
Result[0][0] := SetOne;
Result[0][1] := Length(Copies);
Result[1][0] := SetTwo;
Result[1][1] := Length(CopiesTwo);
Result[2][0] := SetThree;
Result[2][1] := Length(CopiesThree);
end;
This is the functionthat needs to use the results. This is after trying to use the FunctionName[0][0] method.
function RankHand : boolean;
begin
Result := False;
if (CheckFlush = 2) and (FlopCards[1].rank = 0) then
begin
Result := True;
WriteLn('Hand is good because of chance of flush');
end;
if (CheckFlush = 4) and (FlopCards[5].rank = 0) then
begin
Result := True;
WriteLn('Hand is good because of chance of flush');
end;
if (CheckStraight = 4) and (FlopCards[5].rank = 0) then
begin
Result := True;
WriteLn('Hand is good because of chance of straight');
end;
if (CheckCopies[0][0] > 0) and (FlopCards[1].rank = 0) then
begin
Result := True;
WriteLn('Hand is good because I have at least a pair with no flop yet');
end;
if (CheckCopies[1][0] > 0) then
begin
Result := True;
WriteLn('I have two pairs');
end;
if (CheckCopies[0][1] > 2) then
begin
Result := True;
WriteLn('I have three of a kind');
end;
if (CheckFlush = 5) then
begin
Result := True;
WriteLn('I have a flush');
end;
if (CheckStraight = 5) then
begin
Result := True;
WriteLn('I have a straight');
end;
end;