网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
11月03日漏签0天
pascal吧 关注:14,948贴子:132,321
  • 看贴

  • 图片

  • 吧主推荐

  • 视频

  • 游戏

  • 3回复贴,共1页
<<返回pascal吧
>0< 加载中...

五子棋程序

  • 取消只看楼主
  • 收藏

  • 回复
  • overture_wy
  • Dijkstra
    6
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
我编了个两人对战的五子棋程序,但判断胜负的子程序除了些问题,请大家帮忙看看。注:此程序必需用FreePascal编译。


uses crt,dos;
type ty=array[1..30,1..79]of char;
var i,j,k,x,y:integer;
    ch,c:char;
    a:ty;
    f:boolean;
    t:text;
procedure go(var ch:char;a:ty);
var a2,b,c,k,i,j:shortint;
begin
     ch:='+';
     for i:=1 to 30 do
     for j:=1 to 79 do
     begin
          a2:=0;
          for k:=1 to 4 do
          begin
               if (a[i,j+k*2]=a[i,j])and not (a[i,j] in ['+','-']) then inc(a2);
               if (a[i+k,j]=a[i,j])and not(a[i,j] in ['+','-']) then inc(b);
               if (a[i+k,j+k*2]=a[i,j])and not(a[i,j] in ['+','-']) then inc©;
          end;
          if a2=4 then begin ch:=a[i,j];{write(t,' ',ch,' ');}exit;end;
          if b=4 then begin ch:=a[i,j];{write(t,' ',ch,' ');}exit;end;
          if c=4 then begin ch:=a[i,j];{write(t,' ',ch,' ');}exit;end;
     end;
end;
procedure b1; {*,B}
begin
     textcolor(black);
     ch:=readkey;
     while not((ch='h')and(a[x,y]='+')) do
     begin
          if ch='q' then begin f:=false;exit;end;
          if ch='l' then inc(y,2)
          else if ch='k' then inc(x)
          else if ch='j' then dec(y,2)
          else if ch='i' then dec(x);
          gotoxy(y,x);
          ch:=readkey;
     end;
     write('*');
     write(t,'B ',x,' ',y,'  ');
     a[x,y]:='B';
     gotoxy(y,x);
end;
procedure b2; {o,W}
begin
     textcolor(white);
     ch:=readkey;
     while not((ch='0')and(a[x,y]='+')) do
     begin
          if ch='q' then begin f:=false;exit;end;
          if ch='6' then inc(y,2)
          else if ch='5' then inc(x)
          else if ch='4' then dec(y,2)
          else if ch='8' then dec(x);
          gotoxy(y,x);
          ch:=readkey;
     end;
     write('o');
     writeln(t,'W ',x,' ',y,';');
     a[x,y]:='W';
     gotoxy(y,x);
end;
begin
     fillchar(a,sizeof(a),' ');
     textbackground(lightgreen);
     textcolor(lightred);
     assign(t,'five.txt');
     rewrite(t);
     for i:=1 to 30 do
     begin
          write('+');
          for j:=1 to 39 do write('-+');
          writeln;
     end;
     for i:=1 to 30 do
         for j:=1 to 79 do
             if odd(j) then a[i,j]:='+'
                else a[i,j]:='-';
     gotoxy(1,1);
     x:=1;
     y:=1;
     f:=true;
     while f do
     begin
          b1;
          go(c,a);
          if c='*' then
          begin
               writeln('Black win!!!');
               readln;
               writeln(t);
               writeln(t,'Black win');
               break
          end
          else if c='o' then
          begin
               writeln('White win!!!');
               readln;
               writeln(t);
               writeln(t,'White win');
               break;
          end;
          if not f then break;
          b2;
          go(c,a);
          if c='*' then
          begin
               writeln('Black win!!!');
               readln;
               writeln(t,'Black win');
               break;
          end
          else if c='o' then
          begin
               writeln('White win!!!');
               readln;
               writeln(t,'White win');
               break;
          end;
     end;
     close(t);
     close(output);
     assign(output,'five.txt');
     append(output);
     writeln;
     writeln;
     for i:=1 to 30 do
     begin
        for j:=1 to 79 do
            write(a[i,j],' ');
        writeln;
     end;
     close(output);
end.


  • overture_wy
  • Dijkstra
    6
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
请大家帮忙看看,急用


2025-11-03 10:54:52
广告
不感兴趣
开通SVIP免广告
  • overture_wy
  • Dijkstra
    6
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
哈哈!还知道本人的大名。阁下一定也是猪中1或11班的吧!


  • overture_wy
  • Dijkstra
    6
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
你说吧!


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 3回复贴,共1页
<<返回pascal吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示