|
发表于 2011-5-20 09:33:48
|
显示全部楼层
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
typearray= array[1..3,1..3] of integer;
var
Form1: TForm1; abc:typearray; total:integer;
implementation
{$R *.dfm}
procedure foundnext(user1,user2:string;index:integer;abc0:typearray;var s :string);
var i,j,k,index1,index2,jdex1,jdex2,nextindex,nextj:integer; isfound:boolean;
nextuser,winuser:string; abc:typearray; s1:string;
begin
for I := 1 to 3 do
for j := 1 to 3 do
abc[i,j]:=abc0[i,j];
index1:=ord(user1[1])- ord('a')+1;
index2:=ord(user2[1])- ord('a')+1;
jdex1:=strtoint(user1[2]);
jdex2:=strtoint(user2[2]);
case index of
0: begin
abc[index1,jdex1]:=-1;
abc[index2,jdex2]:=1;
winuser:= user2;
s1:=s+ user1 ;
end;
1: begin
abc[index1,jdex1]:=1;
abc[index2,jdex2]:=-1;
winuser:= user1;
s1:=s+ user2 ;
end;
end;
nextindex :=6- index1-index2 ;
isfound:=false;
for I := 1 to 3 do
if abc[nextindex,i]=0 then begin
nextj:=i;
isfound :=true;
break;
end;
if not isfound then begin
if index=0then nextindex := index1 else nextindex := index2;
for I := 1 to 3 do
if abc[nextindex,i]=0 then begin
nextj:=i;
isfound :=true;
break;
end;
end;
if isfound then begin
nextuser:=chr(ord('a')+ nextindex-1)+inttostr( nextj);
foundnext(winuser,nextuser,0,abc,s1);
foundnext(winuser,nextuser,1,abc,s1);
end else begin
if winuser[1]='a' then begin
inc(total);
form1.Memo1.Lines.Add(s1);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var user1,user2,s:string;
begin
total:=0;
user1:='b1';
user2:='c1';
s:='';
foundnext(user1,user2,1,abc,s);
showmessage(inttostr(total));
end;
end. |
|