圈叉棋。pascal
bxbian9511222011/03/10软件综合 IP:江苏
我怎么一直觉得有问题。= =。。。
mouse单元貌似没用。
我用lazarus编译的。。用fp的童鞋把前两个单元和编译开关去掉就好了。。。。

program Tic;
{$mode objfpc}{$H+}
uses
  Classes, SysUtils, Dos, Graph, CRT, mouse
  { you can add units after this };
label Ex;
const
  version='Version 1.0.1073 Beta For Lazarus  [2010/08/05]';
  ChessWidth=3;
  BlankWidth=180;
  EGAMode=16;
  VGAMode=18;
  CGAMode=6;
  IconWidth=300;
  Pri='Neoix Organization';
  WebSite='XXXXXXXXXXXXXXXXXXXX/';
var
  Chess:array[1..3,1..3]of char;
  BeginX,BeginY,CurrentX,CurrentY:Word;
  chose:integer;
  ch:char;
  i,s,n,flag,j:0..10;
  max:byte;
  b:array[1..3,1..3]of byte;
  ME:TMouseEvent;
  R:Registers;
  step:integer;
  computer1,player1,computer2,player2:char;
  GraphDriver,GraphMode,HiMode,LoMode:smallint;
  ErrCode:integer;
  x0,k:integer;
  i0,j0,ix,jx,iy,jy:integer;
  IconX,IconY,IconWidth0:integer;
  Point:array[1..1024,1..768]of integer;

procedure Load;
var
  grDriver: smallint;
  grMode: smallint;
  //ErrCode: Integer;
  HalfX,HalfY,H:Word;
  ex,ey,i,j:Word;
  k:integer;
  strtemp:string;
begin
  DirectVideo:=False;
  Randomize;
//  JustBegin:=True;
//  XXXXX:=0;
//  V0.V:=0;V0.D:=25;
//  V0.LD:=5;V0.RD:=5;
//  XXXXX:=False;
//  V0.RB:=False;
  CurrentX:=ChessWidth div 2;CurrentY:=ChessWidth div 2;
  grDriver := Detect;
  InitGraph(grDriver, grMode,'C:\TP\BGI');
  ErrCode := GraphResult;
  if ErrCode = grOk then
  begin
  {*
  SetFillStyle(1,White);
  FloodFill(1,1,White);

  IconWidth0:=IconWidth div 5;
  IconX:=(GetMaxX-IconWidth) div 2;
  IconY:=(GetMaxY-IconWidth) div 2;
  SetColor(LightGray);
  SetFillStyle(1,LightGray);
  Circle(IconX+IconWidth0*1+IconWidth0 div 2,IconY+IconWidth0*1+IconWidth0 div 2,IconWidth0*1+IconWidth0 div 2);
  FloodFill(IconX+IconWidth0*1+IconWidth0 div 2,IconY+IconWidth0*1+IconWidth0 div 2,LightGray);
  Circle(IconX+IconWidth-IconWidth0-IconWidth0 div 2,IconY+IconWidth-IconWidth0-IconWidth0 div 2,IconWidth0*1+IconWidth0 div 2);
  FloodFill(IconX+IconWidth-IconWidth0-IconWidth0 div 2,IconY+IconWidth-IconWidth0-IconWidth0 div 2,LightGray);
  SetColor(White);
  SetFillStyle(1,White);
  Circle(IconX+IconWidth-IconWidth0-IconWidth0 div 2,IconY+IconWidth-IconWidth0-IconWidth0 div 2,IconWidth0 div 2);
  FloodFill(IconX+IconWidth-IconWidth0-IconWidth0 div 2,IconY+IconWidth-IconWidth0-IconWidth0 div 2,White);
  Circle(IconX+IconWidth0*1+IconWidth0 div 2,IconY+IconWidth0*1+IconWidth0 div 2,IconWidth0 div 2);
  FloodFill(IconX+IconWidth0*1+IconWidth0 div 2,IconY+IconWidth0*1+IconWidth0 div 2,White);
  for i:=IconY to IconY+IconWidth0 do
    for j:=IconX+IconWidth0*1+IconWidth0 div 2 to IconX+IconWidth do
      PutPixel(j,i,LightGray);
  for i:=IconY+IconWidth0*2 to IconY+IconWidth0*3 do
    for j:=IconX+IconWidth0*1+IconWidth0 div 2 to IconX+IconWidth-(IconWidth0*1+IconWidth0 div 2) do
      PutPixel(j,i,LightGray);
  for i:=IconY+IconWidth0*4 to IconY+IconWidth0*5 do
    for j:=IconX to IconX+IconWidth-(IconWidth0*1+IconWidth0 div 2) do
      PutPixel(j,i,LightGray);
  for i:=IconY+IconWidth0 to IconY+IconWidth0*2 do
    for j:=IconX+IconWidth0*1+IconWidth0 div 2 to IconX+IconWidth-IconWidth0 do
      PutPixel(j,i,White);
  for i:=IconY+IconWidth0*3 to IconY+IconWidth0*4 do
    for j:=IconX+IconWidth0 to IconX+IconWidth-(IconWidth0*1+IconWidth0 div 2) do
      PutPixel(j,i,White);
  for i:=IconX+IconWidth0 to IconX+IconWidth0*2 do
    for j:=IconY+IconWidth0*1+IconWidth0 div 2 to IconY+IconWidth-IconWidth0 do
      if GetPixel(i,j)=LightGray then Point[i,j]:=1;
  for i:=IconX+IconWidth0*3 to IconX+IconWidth0*4 do
    for j:=IconY+IconWidth0 to IconY+IconWidth-(IconWidth0*1+IconWidth0 div 2) do
      if GetPixel(i,j)=LightGray then Point[i,j]:=1;
  SetColor(DarkGray);
  SetFillStyle(1,DarkGray);
  Circle(IconX+IconWidth0*1+IconWidth0 div 2,IconY+IconWidth0*1+IconWidth0 div 2,IconWidth0*1+IconWidth0 div 2);
  FloodFill(IconX+IconWidth0*1+IconWidth0 div 2,IconY+IconWidth0*1+IconWidth0 div 2,DarkGray);
  Circle(IconX+IconWidth-IconWidth0-IconWidth0 div 2,IconY+IconWidth-IconWidth0-IconWidth0 div 2,IconWidth0*1+IconWidth0 div 2);
  FloodFill(IconX+IconWidth-IconWidth0-IconWidth0 div 2,IconY+IconWidth-IconWidth0-IconWidth0 div 2,DarkGray);
  SetColor(White);
  SetFillStyle(1,White);
  Circle(IconX+IconWidth-IconWidth0-IconWidth0 div 2,IconY+IconWidth-IconWidth0-IconWidth0 div 2,IconWidth0 div 2);
  FloodFill(IconX+IconWidth-IconWidth0-IconWidth0 div 2,IconY+IconWidth-IconWidth0-IconWidth0 div 2,White);
  Circle(IconX+IconWidth0*1+IconWidth0 div 2,IconY+IconWidth0*1+IconWidth0 div 2,IconWidth0 div 2);
  FloodFill(IconX+IconWidth0*1+IconWidth0 div 2,IconY+IconWidth0*1+IconWidth0 div 2,White);

  for i:=IconX to IconX+IconWidth0 do
    for j:=IconY+IconWidth0*1+IconWidth0 div 2 to IconY+IconWidth do
      PutPixel(i,j,DarkGray);
  for i:=IconX+IconWidth0*2 to IconX+IconWidth0*3 do
    for j:=IconY+IconWidth0*1+IconWidth0 div 2 to IconY+IconWidth-(IconWidth0*1+IconWidth0 div 2) do
      PutPixel(i,j,DarkGray);
  for i:=IconX+IconWidth0*4 to IconX+IconWidth0*5 do
    for j:=IconY to IconY+IconWidth-(IconWidth0*1+IconWidth0 div 2) do
      PutPixel(i,j,DarkGray);
  for i:=IconX+IconWidth0 to IconX+IconWidth0*2 do
    for j:=IconY+IconWidth0*1+IconWidth0 div 2 to IconY+IconWidth-IconWidth0 do
      if Point[i,j]=1 then PutPixel(i,j,LightGray) else PutPixel(i,j,White);
  for i:=IconX+IconWidth0*3 to IconX+IconWidth0*4 do
    for j:=IconY+IconWidth0 to IconY+IconWidth-(IconWidth0*1+IconWidth0 div 2) do
      if Point[i,j]=1 then PutPixel(i,j,LightGray) else PutPixel(i,j,White);
  for i:=IconX-IconWidth0+IconWidth to IconX+IconWidth do
    for j:=IconY to IconY+IconWidth0 do
      PutPixel(i,j,Yellow);

  for i:=IconX to IconX+IconWidth do
    for j:=IconY to IconY+IconWidth do
      if GetPixel(i,j)<>White then Point[i,j]:=GetPixel(i,j) else Point[i,j]:=0;
  for i:=IconX to IconX+IconWidth do
    for j:=IconY to IconY+IconWidth do
      if Point[i,j]<>0 then PutPixel(i+5,j+5,Black);
  for i:=IconX to IconX+IconWidth do
    for j:=IconY to IconY+IconWidth do
      if Point[i,j]<>0 then PutPixel(i,j,Point[i,j]);

  //SetUserCharSize(IconWidth,TextWidth(pri),TextHeight(pri)*IconWidth div TextWidth(pri),TextHeight(pri));
  SetTextStyle(DefaultFont,HorizDir,2);
  for i:=1 to length(pri) do
  begin
    Delay(70);
    SetColor(LightGray);
    OutTextXY((GetMaxX-TextWidth(pri)) div 2+2,IconY+IconWidth+20+2,Copy(pri,1,i));
    SetColor(DarkGray);
    OutTextXY((GetMaxX-TextWidth(pri)) div 2+1,IconY+IconWidth+20+1,Copy(pri,1,i));
    SetColor(Black);
    OutTextXY((GetMaxX-TextWidth(pri)) div 2,IconY+IconWidth+20,Copy(pri,1,i));
  end;
  x0:=IconY+IconWidth+25+TextHeight(pri);
  SetTextStyle(DefaultFont,HorizDir,1);
  for i:=1 to length(website) do
  begin
    Delay(50);
    SetColor(LightGray);
    OutTextXY((GetMaxX-TextWidth(website)) div 2+2,x0,Copy(website,1,i));
    SetColor(DarkGray);
    OutTextXY((GetMaxX-TextWidth(website)) div 2+1,x0,Copy(website,1,i));
    SetColor(Black);
    OutTextXY((GetMaxX-TextWidth(website)) div 2,x0,Copy(website,1,i));
  end;
  //Exec('C:\Program Files\Internet Explorer\iexplore.exe','XXXXXXXXXXXXXXXXXXXX/');
  {*for i:=(GetMaxX-TextWidth(pri)) div 2-5 to (GetMaxX+TextWidth(pri)) div 2+5 do
    for j:=IconY+IconWidth+20-5 to IconY+IconWidth+TextHeight(pri)+30 do
      point[i,j]:=GetPixel(i,j);
  x0:=IconY+IconWidth+20+TextHeight(pri);
  SetTextStyle(DefaultFont,HorizDir,1);
  SetColor(Black);
  x0:=x0-TextHeight(website);
  for k:=0 to TextHeight(website)+10 do
  begin
    for i:=(GetMaxX-TextWidth(pri)) div 2-5 to (GetMaxX+TextWidth(pri)) div 2+5 do
      for j:=IconY+IconWidth+20-5 to IconY+IconWidth+TextHeight(pri)+30 do
        PutPixel(i,j,point[i,j]);
    SetColor(Black);
    OutTextXY((GetMaxX-TextWidth(website)) div 2,x0+i,website);
    Delay(1000);
  end;  *}
  //OutTextXY((GetMaxX-TextWidth(pri)) div 2,IconY+IconWidth+20,Pri);
  Delay(1000);
  {*SetColor(Black);
  for i:=0 to GetMaxY do
  begin
    Line(0,i,GetMaxX,GetMaxY-i);
    //Delay(20);
  end;
  for i:=0 to GetMaxX do
  begin
    Line(GetMaxX-i,0,i,GetMaxY);
    //Delay(20);
  end; *}
  {*
  Delay(3000);
  SetColor(Black);
  for i:=0 to GetMaxY do
  begin
    Line(0,i,GetMaxX,i);
    Delay(30);
  end; *}
  Delay(1000);
    CloseGraph;
    InitGraph(grDriver, grMode,'C:\TP\BGI');
    *}
    BeginX:=GetMaxX div 2-(ChessWidth*BlankWidth div 2);
    BeginY:=GetMaxY div 2-(ChessWidth*BlankWidth div 2);
    ex:=GetMaxX div 2+(ChessWidth*BlankWidth div 2);
    ey:=GetMaxY div 2+(ChessWidth*BlankWidth div 2);
    //SetFillStyle(1,BLUE);
    Bar(BeginX,BeginY,ex,ey);
    SetColor(White);
    for i:=1 to ChessWidth+1 do
    begin
      Line(BeginX+(i-1)*BlankWidth,BeginY,BeginX+(i-1)*BlankWidth,ey);
      Line(BeginX,BeginY+(i-1)*BlankWidth,ex,BeginY+(i-1)*BlankWidth);
    end;
    for i:=1 to ChessWidth do
      for j:=1 to ChessWidth do
    begin
      str((i-1)*3+j,strtemp);
      if (i-1)*3+j<10 then strtemp:='0'+strtemp;
      outtextxy(BeginX+(i-1)*BlankWidth+5,BeginY+(j-1)*BlankWidth+5,strtemp);
    end;
    //for k:=1 to ChessWidth do
    //  outtextxy(BeginX-15,BeginY+(k-1)*BlankWidth+5,chr(k+96));
    SetTextStyle(DefaultFont,HorizDir,3);
    OutTextXY(10,10,'Tic - Tac - Toe');
    k:=TextHeight('Tic - Tac - Toe');
    SetTextStyle(DefaultFont,HorizDir,1);
    OutTextXY(GetMaxX-TextWidth(version)-10,k+10-TextHeight(version),version);
    OutTextXY(BeginX-320,BeginY+100,'Record');
    OutTextXY(75,GetMaxY-23,'Steps');
    SetTextStyle(DefaultFont,HorizDir,2);
    OutTextXY(20,GetMaxY-30,'0');
    Line(0,k+20,GetMaxX,k+20);
    SetTextStyle(DefaultFont,HorizDir,1);
    OutTextXY(10,k+30,'[s:9]lease use the main window to control.');
    case chose of
    1:begin
        SetTextStyle(DefaultFont,HorizDir,2);
        OutTextXY(BeginX-330+32,BeginY,'[s:9]C');
        OutTextXY(BeginX-200,BeginY,'[s:9]layer');
      end;
    2:begin
        SetTextStyle(DefaultFont,HorizDir,2);
        OutTextXY(BeginX-330,BeginY,'[s:9]layer');
        OutTextXY(BeginX-200+32,BeginY,'[s:9]C');
      end;
    3:begin
        SetTextStyle(DefaultFont,HorizDir,2);
        OutTextXY(BeginX-330,BeginY,'[s:9]layer');
        OutTextXY(BeginX-200,BeginY,'[s:9]layer');
      end;
    4:begin
        SetTextStyle(DefaultFont,HorizDir,2);
        OutTextXY(BeginX-330+32,BeginY,'[s:9]C');
        OutTextXY(BeginX-200+32,BeginY,'[s:9]C');
      end;
    end;
  end
  else
    Halt;
end;
procedure ViewState0(sta:char);
begin
  setcolor(black);
  setlinestyle(SolidLn,0,ThickWidth);
  Line(BeginX-332,BeginY+50,BeginX-200+90,BeginY+50);
  setcolor(white);
  if sta='O' then Line(BeginX-330,BeginY+50,BeginX-330+90,BeginY+50)
  else Line(BeginX-200,BeginY+50,BeginX-200+90,BeginY+50);
  SetLineStyle(SolidLn,0,NormWidth);
end;
procedure ViewResult0(sta:char);
begin
  setcolor(White);
  SetTextStyle(DefaultFont,HorizDir,2);
  case sta of
  'O':OutTextXY(BeginX-330+24,BeginY+25,'Win');
  'X':OutTextXY(BeginX-200+24,BeginY+25,'Win');
  else
    OutTextXY(BeginX-200-40,BeginY+25,'Drew');
  end;
end;
procedure RecordChess(_x,_y:Word;sta:char);
var
  strtemp:string;
  i:integer;
begin
  SetColor(black);
  SetTextStyle(DefaultFont,HorizDir,1);
  for i:=GetMaxY-40 to GetMaxY do
    Line(10,i,74,i);
  Step:=Step+1;
  SetColor(white);
  str(Step,strTemp);
  //strTemp:=strTemp+' Steps';
  SetTextStyle(DefaultFont,HorizDir,2);
  OutTextXY(20,GetMaxY-30,strtemp);
  SetTextStyle(DefaultFont,HorizDir,1);
  OutTextXY(beginX-320,BeginY+110+step*10,sta+'  0'+chr((_x-1)*3+_y+48));
end;
procedure PutRect(_x,_y:Word;Erase:Boolean);
var
  r:Word;
begin
  r:=BlankWidth -2;
  if Erase then SetColor(Black) else SetColor(White);
  Rectangle(BeginX+_x*BlankWidth-r,BeginY+_y*BlankWidth-r,BeginX+_x*BlankWidth-1,BeginY+_y*BlankWidth-1);
  Rectangle(BeginX+_x*BlankWidth-r-1,BeginY+_y*BlankWidth-r-1,BeginX+_x*BlankWidth-2,BeginY+_y*BlankWidth-2);
end;
procedure PutChess(_x,_y:Word;player0:char);
var
  r:Word;
  color:Byte;
begin
  RecordChess(_x,_y,player0);
  r:=(BlankWidth div 2);
  if (_x>ChessWidth)or(_y>ChessWidth) then exit;
  if player0='X' then
  begin
    SetColor(White);
    setlinestyle(SolidLn,0,ThickWidth);
    Line(BeginX+(_x-1)*BlankWidth+50,BeginY+(_y-1)*BlankWidth+50,BeginX+_x*BlankWidth-50,BeginY+_y*BlankWidth-50);
    Line(BeginX+_x*BlankWidth-50,BeginY+(_y-1)*BlankWidth+50,BeginX+(_x-1)*BlankWidth+50,Beginy+_y*BlankWidth-50);
    SetLineStyle(SolidLn,0,NormWidth);
  end;
  if player0='O' then
  begin
    SetColor(White);
    Circle(BeginX+_x*BlankWidth-r,BeginY+_y*BlankWidth-r,r-50);
    SetFillStyle(1,White);
    FloodFill(BeginX+_x*BlankWidth-r,BeginY+_y*BlankWidth-r,White);
    SetColor(Black);
    Circle(BeginX+_x*BlankWidth-r,BeginY+_y*BlankWidth-r,r-53);
    SetFillStyle(1,Black);
    FloodFill(BeginX+_x*BlankWidth-r,BeginY+_y*BlankWidth-r,Black);
  end;
end;
procedure Player0(sta:char);
var
  ch:Char;
  Take:Boolean;
begin
  Take:=False;
  repeat
    ch:=#0;
    if KeyPressed then
    begin
      ch:=ReadKey;
      GotoXY(12,25);
      write('        ');
      GotoXY(12,25);
      write('#',ord(ch));
    end;
    case ch of
      #71:{UpLeft}
          begin
            PutRect(CurrentX,CurrentY,True);
            if CurrentX>1 then CurrentX:=CurrentX-1;
            if CurrentY>1 then CurrentY:=CurrentY-1;
            PutRect(CurrentX,CurrentY,False);
          end;
      #72:{Up}
          begin
            PutRect(CurrentX,CurrentY,True);
            if CurrentY>1 then CurrentY:=CurrentY-1;
            PutRect(CurrentX,CurrentY,False);
          end;
      #73:{UpRight}
          begin
            PutRect(CurrentX,CurrentY,True);
            if CurrentX<ChessWidth then CurrentX:=CurrentX+1;
            if CurrentY>1 then CurrentY:=CurrentY-1;
            PutRect(CurrentX,CurrentY,False);
          end;
      #75:{Left}
          begin
            PutRect(CurrentX,CurrentY,True);
            if CurrentX>1 then CurrentX:=CurrentX-1;
            PutRect(CurrentX,CurrentY,False);
          end;
      #77:{Right}
          begin
            PutRect(CurrentX,CurrentY,True);
            if CurrentX<ChessWidth then CurrentX:=CurrentX+1;
            PutRect(CurrentX,CurrentY,False);
            end;
      #79:{DownLeft}
          begin
            PutRect(CurrentX,CurrentY,True);
            if CurrentX>1 then CurrentX:=CurrentX-1;
            if CurrentY<ChessWidth then CurrentY:=CurrentY+1;
            PutRect(CurrentX,CurrentY,False);
          end;
      #80:{Down}
          begin
            PutRect(CurrentX,CurrentY,True);
            if CurrentY<ChessWidth then CurrentY:=CurrentY+1;
            PutRect(CurrentX,CurrentY,False);
          end;
      #81:{DownRight}
          begin
            PutRect(CurrentX,CurrentY,True);
            if CurrentX<ChessWidth then CurrentX:=CurrentX+1;
            if CurrentY<ChessWidth then CurrentY:=CurrentY+1;
            PutRect(CurrentX,CurrentY,False);
          end;
      #13:{For sure}
          begin
            //writeln(currentX,currentY);
            if Chess[currentX,currentY] in ['1'..'9'] then
            begin
              PutRect(CurrentX,CurrentY,False);
              //RecordChess(CurrentX,CurrentY,player);
              Take:=True;
              Chess[currentX,currentY]:=sta;
              PutChess(currentX,currentY,sta);
              s:=s+1;
            end;
          end;
      else;
      end;
  until Take;
{* repeat
    writeln;
    write(s,': please,play(1..9)');
    readln(n);
  until a[n] in ['1'..'9'];
  a[n]:='O';*}
end;
function f(a1x,a1y,a2x,a2y,a3x,a3y:byte):boolean;
begin
  f:=false;
  if (Chess[a1x, a1y]=Chess[a2x, a2y]) and
     (Chess[a2x, a2y]=Chess[a3x, a3y]) and
     (Chess[a1x, a1y]=Chess[a3x, a3y])
     and not(Chess[a1x, a1y] in ['1'..'9'])
     then
     begin
       f:=true;
     end;
end;
function checkall:boolean;
begin
  checkall:=false;
  if f(1,1,1,2,1,3) or f(2,1,2,2,2,3) or f(3,1,3,2,3,3) or
     f(1,1,2,1,3,1) or f(1,2,2,2,3,2) or f(1,3,2,3,3,3) or
     f(1,1,2,2,3,3) or f(1,3,2,2,3,1) then
  checkall:=true;
end;
function c(mx,my,nx,ny:integer):integer;
begin
  c:=0;
  if (Chess[mx,my]=Computer1) and (Chess[nx,ny]=Computer1) or (Chess[mx,my]=Computer2) and (Chess[nx,ny]=Computer2) then
  begin
    c:=50;
    flag:=2;
  end
  else
    if (Chess[mx,my]=Player1) and (Chess[nx,ny]=Player1) then
      c:=25
    else
      if ((Chess[mx,my]=Computer1) or (Chess[mx,my]=Computer2)) and (Chess[nx,ny] in ['1'..'9']) or
         ((Chess[nx,ny]=Computer1) or (Chess[nx,ny]=Computer2)) and (Chess[mx,my] in ['1'..'9']) then
        c:=10
      else
        if ((Chess[mx,my]=Player1) or (Chess[mx,my]=Player2)) and (Chess[nx,ny] in ['1'..'9']) or
           ((Chess[nx,ny]=Player1) or (Chess[nx,ny]=Player1)) and (Chess[mx,my] in ['1'..'9']) then
          c:=8
        else
          if (Chess[mx,my] in ['1'..'9']) and (Chess[nx,ny] in ['1'..'9']) then
            c:=4
end;
procedure Computer0(sta:char);
var
  x1,x2:integer;
begin
  max:=0;
  if (s=0) {*and (chose=1) or (chose=4))*} then
  begin
    i:=random(3)+1;
    j:=random(3)+1;
    Chess[i,j]:=sta;
    n:=(i-1)*3+j;
  end
  else
  begin
    for i:=1 to 3 do
      for j:=1 to 3 do
      begin
        if Chess[i,j] in ['1'..'9'] then
          case (i-1)*3+j of
            1:b[1,1]:=c(1,2,1,3)+c(2,1,3,1)+c(2,2,3,3);
            2:b[1,2]:=c(1,1,1,3)+c(2,2,3,2);
            3:b[1,3]:=c(1,1,1,2)+c(2,2,3,1)+c(2,3,3,3);
            4:b[2,1]:=c(1,1,3,1)+c(2,2,2,3);
            5:b[2,2]:=c(1,1,3,3)+c(1,2,3,2)+c(1,3,3,1)+c(2,1,2,3);
            6:b[2,3]:=c(1,3,3,3)+c(2,1,2,2);
            7:b[3,1]:=c(1,1,2,1)+c(1,3,2,2)+c(3,2,3,3);
            8:b[3,2]:=c(3,1,3,3)+c(1,2,2,2);
            9:b[3,3]:=c(1,1,2,2)+c(3,1,3,2)+c(1,3,2,3);
          end
        else
          b[i,j]:=0;
        if max<b[i,j] then
        begin
          max:=b[i,j];
          n:=(i-1)*3+j
        end;
      end;
    randomize;
    if (s=3) and ((Chess[1,1]=Chess[3,3]) or (Chess[1,3]=Chess[3,1])) then
      n:=(random(5)+1)*2;
    Chess[(n-1) div 3+1, (n-1) mod 3+1]:=sta;
  end;
  s:=s+1;
  if s=9 then
  for i:=1 to 3 do
    for j:=1 to 3 do
      if Chess[i,j] in ['1'..'9'] then
      begin
        Chess[i,j]:=sta;
        PutChess(i,j,sta);
        break;
      end;
  if s<>9 then
  begin
    Chess[(n-1)div 3+1,(n-1)mod 3+1]:=sta;
    PutChess((n-1)div 3+1,(n-1)mod 3+1,sta);
  end;
end;
procedure Pre;
var
  i:integer;
begin
  randomize;
  for i:=1 to 6 do
  begin
    delay(100+random(300));
    write('.');
  end;
  writeln('[s:9]reset Successfully');
  writeln;
  writeln('Use directiion keys and enter key to control');
  writeln;
  writeln('Click any key to start');
  writeln;
  writeln;
  TextColor(Black);
  TextBackground(White);
  write(' Command ');
  TextColor(White);
  TextBackground(Black);
  Load;
end;
procedure Wait;
var
  ch:Char;
begin
  repeat
  until KeyPressed;
  ch:=ReadKey;
end;
begin
  for i:=1 to 9 do
    Chess[(i-1) mod 3+1,(i-1) div 3+1]:=chr(i+48);
  writeln('Free Pascal IDE Version 1.0.8 [2006/08/21]');
  writeln('Compiler Version 2.0.4');
  writeln('GBD Version GDB 6.2.1');
  writeln;
  randomize;
  writeln('Detect Driver ');
  writeln('XXXXAMode');
  writeln('XXXXAMode');
  writeln('XXXXAMode');
  writeln('Choose graph mode (Auto choose VGA) ? ');
  i:=0;
  repeat
    i:=i+1;
    delay(1000);
    write('.');
  until (keypressed) or (i=7);
  if i<>7 then Ch:=ReadKey else ch:='1';
  writeln;
  R.AH:=0;
  case ch of
  '1':begin
        XXXX:=VGAMode;
        writeln('Chosen VGAMode');
      end;
  '2':begin
        XXXX:=EGAMode;
        writeln('Chosen EGAMode');
      end;
  '3':begin
        XXXX:=CGAMode;
        writeln('Chosen CGAMode');
      end;
  else
    begin
      writeln;
      repeat
        clrscr;
        TextColor(Yellow+blink);
        TextBackground(Red);
        Write('Error');
        delay(1000);
        clrscr;
        TextColor(White);
        TextBackground(Black);
        Write('Error');
        delay(1000);
      until keypressed;
      halt;
    end;
  end;
  Intr(16,R);
  DirectVideo:=False;
  writeln;
  write('[s:9]reset Graph Window ');
  for i:=1 to 3 do
  begin
    delay(100+random(100));
    write('.');
  end;
  writeln;
  write('Loading 936-Chinese Page ');
  delay(200+random(1000));
  writeln;
  writeln;
  writeln('Tic - Tac - Toe');
  writeln;
  writeln(version);
  writeln('By Rijn - Neoix');
  writeln;
  delay(200+random(200));
  writeln;
  writeln('1.PC(First) Player');
  writeln('XXXXayer(First) PC');
  writeln('XXXXayer Player');
  //writeln('4.PC PC (Test)');
  write('Choose a mode ? ');
  repeat until KeyPressed;
  Ch:=ReadKey;
  chose:=ord(ch)-48;
  s:=0;
  case chose of
  1:begin
      computer1:='O';
      Player1:='X';
      Pre;
      wait;
      repeat
        ViewState0('O');
        Computer0('O');
        if checkall then
        begin
          flag:=1;
          goto Ex;
        end;
        if s>=9 then goto Ex;
        ViewState0('X');
        Player0('X');
        if checkall then
        begin
          flag:=2;
          goto Ex;
        end;
        if s>=9 then goto Ex;
      until (s=9) or (flag>0);
    end;
  2:begin
      computer1:='X';
      Player1:='O';
      Pre;
      repeat
        ViewState0('O');
        Player0('O');
        if checkall then
        begin
          flag:=1;
          goto Ex;
        end;
        if s>=9 then break;
        ViewState0('X');
        Computer0('X');
        if checkall then
        begin
          flag:=2;
          goto Ex;
        end;
        if s>=9 then break;
      until (s=9) or (flag>0);
    end;
  3:begin
      Pre;
      repeat
        ViewState0('O');
        Player0('O');
        if checkall then
        begin
          flag:=1;
          goto Ex;
        end;
        if s>=9 then break;
        ViewState0('X');
        Player0('X');
        if checkall then
        begin
          flag:=2;
          goto Ex;
        end;
        if s>=9 then break;
      until (s=9) or (flag>0);
    end;
  {4:begin
      Computer1:='O';
      Computer1:='X';
      Pre;
      wait;
      repeat
        ViewState0('O');
        Computer0('O');
        if checkall then
        begin
          flag:=1;
          goto Ex;
        end;
        if s>=9 then break;
        ViewState0('X');
        Computer0('X');
        if checkall then
        begin
          flag:=2;
          goto Ex;
        end;
        if s>=9 then break;
      until (s=9) or (flag>0);
    end;    }
  end;
Ex:
  if flag=0 then ViewResult0('D')
  else if flag=1 then ViewResult0('O')
  else ViewResult0('X');
  TextColor(LightGray);
  TextBackground(Black);
  writeln;
  writeln;
  writeln('Game Over');
  writeln;
  writeln('Thank you for playing');
  writeln('Made by Rijn');
  writeln('Copyright <c> Neoix Org, 2009-2010');
  writeln;
  writeln('Click enter to exit');
  readln
end.
+400  科创币    科创网    2011/04/27 希望有创作思路的描述,代码中适当添加注释。
-5000  科创币    科创网    2011/04/27 兑换学术分。
+1  学术分    科创网    2011/04/27 兑为学术分。
来自:计算机科学 / 软件综合
2
已屏蔽 原因:{{ notice.reason }}已屏蔽
{{notice.noticeContent}}
~~空空如也
凡尔派狼
13年7个月前 IP:未同步
302967
圈叉棋?是不是井字过三关?

代码看不懂。

不过如果是井字过三关的话。我给你一个点子。

九宫图听过没有?没听过自己上网搜搜。就是把一到九个数字填入井字格里(每个数字只能用一次),最后横排坚排斜排,每行三个数之和都是十五。

如果用九宫图来算井字过三关,对方点了两个格就等于选了两个数字,十五减这两个数字就等于知道应该抢哪个格了。
引用
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论
4king
13年7个月前 IP:未同步
302991
。。。怎么这么复杂

看了丹尼尔·希利斯 (《通灵芯片》作者)的圈叉棋思路,它用了150个开关做的……
引用
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论

想参与大家的讨论?现在就 登录 或者 注册

所属专业
上级专业
同级专业
bxbian951122
学者 笔友
文章
53
回复
138
学术分
1
2010/06/12注册,5年4个月前活动
暂无简介
主体类型:个人
所属领域:无
认证方式:邮箱
IP归属地:未同步
文件下载
加载中...
{{errorInfo}}
{{downloadWarning}}
你在 {{downloadTime}} 下载过当前文件。
文件名称:{{resource.defaultFile.name}}
下载次数:{{resource.hits}}
上传用户:{{uploader.username}}
所需积分:{{costScores}},{{holdScores}}下载当前附件免费{{description}}
积分不足,去充值
文件已丢失

当前账号的附件下载数量限制如下:
时段 个数
{{f.startingTime}}点 - {{f.endTime}}点 {{f.fileCount}}
视频暂不能访问,请登录试试
仅供内部学术交流或培训使用,请先保存到本地。本内容不代表科创观点,未经原作者同意,请勿转载。
音频暂不能访问,请登录试试
支持的图片格式:jpg, jpeg, png
插入公式
评论控制
加载中...
文号:{{pid}}
投诉或举报
加载中...
{{tip}}
请选择违规类型:
{{reason.type}}

空空如也

加载中...
详情
详情
推送到专栏从专栏移除
设为匿名取消匿名
查看作者
回复
只看作者
加入收藏取消收藏
收藏
取消收藏
折叠回复
置顶取消置顶
评学术分
鼓励
设为精选取消精选
管理提醒
编辑
通过审核
评论控制
退修或删除
历史版本
违规记录
投诉或举报
加入黑名单移除黑名单
查看IP
{{format('YYYY/MM/DD HH:mm:ss', toc)}}