谁能给我一个算法(200分)

  • 主题发起人 wr960204
  • 开始时间
W

wr960204

Unregistered / Unconfirmed
GUEST, unregistred user!
谁能给我一个Pascal/delphi的五子棋算法
代码:
 
object mainform: Tmainform
Left = 346
Top = 222
BorderIcons = [biSystemMenu, biMinimize]
BorderStyle = bsSingle
Caption = '五子棋'
ClientHeight = 436
ClientWidth = 435
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 16
object DrawGrid1: TDrawGrid
Left = 16
Top = 16
Width = 402
Height = 402
ColCount = 19
DefaultColWidth = 20
DefaultRowHeight = 20
DefaultDrawing = False
FixedCols = 0
RowCount = 19
FixedRows = 0
ScrollBars = ssNone
TabOrder = 0
OnDrawCell = DrawGrid1DrawCell
OnMouseDown = DrawGrid1MouseDown
end
end

unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, ScktComp, Grids, Menus, StdCtrls;
type
Tmainform = class(TForm)
DrawGrid1: TDrawGrid;
procedure FormCreate(Sender: TObject);
procedure DrawGrid1DrawCell(Sender: TObject;
ACol, ARow: Integer;
Rect: TRect;
State: TGridDrawState);
procedure DrawGrid1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
private
{ Private declarations }
Tag:array[0..18,0..18]of integer;
{0 for none,1 for black,2 for white}
IsBlack:boolean;
public
{ Public declarations }
function IsWin(IsBlack:boolean):boolean;
//whether win
end;

var
mainform: Tmainform;
implementation
{$R *.DFM}
function Tmainform.IsWin(IsBlack:boolean):boolean;
label exit1;
var
i,j:integer;
wtag:integer;
begin
IsWin:=false;
if IsBlack then
wtag:=1 else
wtag:=2;
for i:=0 to 18do
for j:=0 to 14do
begin
{是否有行连成}
if (i<15)
and(Tag[i,j]=wtag)
and(Tag[i+1,j]=wtag)
and(Tag[i+2,j]=wtag)
and(Tag[i+3,j]=wtag)
and(Tag[i+4,j]=wtag)
then
begin
IsWin:=True;
goto exit1;
end;
{是否有列连成}
if (Tag[i,j]=wtag)
and(Tag[i,j+1]=wtag)
and(Tag[i,j+2]=wtag)
and(Tag[i,j+3]=wtag)
and(Tag[i,j+4]=wtag)
then
begin
IsWin:=True;
goto exit1;
end;
{是否有主对角线连成}
if (i<15)
and(Tag[i,j]=wtag)
and(Tag[i+1,j+1]=wtag)
and(Tag[i+2,j+2]=wtag)
and(Tag[i+3,j+3]=wtag)
and(Tag[i+4,j+4]=wtag)
then
begin
IsWin:=True;
goto exit1;
end;
{是否有副对角线连成}
if (Tag[i,j]=wtag)
and(Tag[i-1,j+1]=wtag)
and(Tag[i-2,j+2]=wtag)
and(Tag[i-3,j+3]=wtag)
and(Tag[i-4,j+4]=wtag)
then
begin
IsWin:=True;
goto exit1;
end;
end;
exit1:
end;

procedure Tmainform.FormCreate(Sender: TObject);
var
i,j:integer;
begin
for i:=0 to 18do
for j:=0 to 18do
begin
Tag[i,j]:=0;
end;
IsBlack:=true;
DrawGrid1.Canvas.Pen.Color :=clBlack;
DrawGrid1.Canvas.Brush.Color :=clBlack;
end;

procedure Tmainform.DrawGrid1DrawCell(Sender: TObject;
ACol, ARow: Integer;
Rect: TRect;
State: TGridDrawState);
begin
DrawGrid1.Canvas.Pen.Color :=clBlack;
DrawGrid1.Canvas.Brush.Color :=clBlack;
if tag[acol,arow]=1 then
DrawGrid1.Canvas.Ellipse(acol*21,arow*21,(acol+1)*21,(arow+1)*21)
else
if tag[acol,arow]=2 then
DrawGrid1.Canvas.Arc(acol*21,arow*21,(acol+1)*21,(arow+1)*21,acol*21,arow*21,acol*21,arow*21)
else
begin
DrawGrid1.Canvas.Pen.Color :=clWhite;
DrawGrid1.Canvas.Brush.Color :=clWhite;
DrawGrid1.Canvas.Ellipse(acol*21,arow*21,(acol+1)*21,(arow+1)*21);
end;
end;

procedure Tmainform.DrawGrid1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
var
col,row:integer;
i,j:integer;
begin
DrawGrid1.Canvas.Pen.Color :=clBlack;
DrawGrid1.Canvas.Brush.Color :=clBlack;
DrawGrid1.MouseToCell(x,y,col,row);
if tag[col,row]=0 then
begin
if IsBlack then
begin
DrawGrid1.Canvas.Ellipse(col*21,row*21,(col+1)*21,(row+1)*21);
tag[col,row]:=1;
end else
begin
DrawGrid1.Canvas.Arc(col*21,row*21,(col+1)*21,(row+1)*21,col*21,row*21,col*21,row*21);
tag[col,row]:=2;
end;
if IsWin(IsBlack) then
begin
if IsBlack then
if MessageDlg('黑不垃圾的赢了',mtInformation,[mbOK],0)=mrOK then
begin
for i:=0 to 18do
for j:=0 to 18do
begin
tag[i,j]:=0;
end;
DrawGrid1.Invalidate;
end;
if not IsBlack then
if MessageDlg('白猪赢了',mtInformation,[mbOK],0)=mrOK then
begin
for i:=0 to 18do
for j:=0 to 18do
begin
tag[i,j]:=0;
end;
DrawGrid1.Invalidate;
end;
end;
IsBlack:=not IsBlack;
end;
end;

end.


program five;
uses
Forms,
main in 'main.pas' {mainform};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(Tmainform, mainform);
Application.Run;
end.



我从别处考来的,希望作者不要告我



 
看看这里有没有
http://delphi.mychangshu.com/dispdoc.asp?id=530
 
我有很多类似的代码!你要的话给我信箱
 
看看这里,尽管是C的,可是参考价值…………
http://www2.cs.uestc.edu.cn/~vcclub/download.htm
 
www.vchelp.net,也是c语言的。
 
我有,要吗?
 
有带人工智能的么
 
wr960204@163.net
 
我的主页上有一个带人工智能的(Delphi,单机板),你先看一看满不满意。
http://zhangyi1980.home.chinaren.com ( 最近经常上不去 :( )
 
wr960204:算了,还是不给你发了,我看了一下,我的跟free_knight的一样
 
多人接受答案了。
 
顶部