GameCaro Pascal- Trí tuệ nhân tạo

trà nguyễn hữu nghĩa

Cựu Mod Vật Lí |Cây bút Thơ|Thần tượng VH
Thành viên
14 Tháng năm 2017
3,974
7,623
744
22
Phú Yên
Trường THPT Lương Văn Chánh
[TẶNG BẠN] TRỌN BỘ Bí kíp học tốt 08 môn
Chắc suất Đại học top - Giữ chỗ ngay!!

ĐĂNG BÀI NGAY để cùng trao đổi với các thành viên siêu nhiệt tình & dễ thương trên diễn đàn.

Đây là Code Game, chúng ta chơi với máy. Bạn nào có ý kiến gì để bổ sung cho Game của mình thì bình luận ở dưới nha.

Mã:
program Game_Co_Caro;
 uses crt,dos,graph;
 const
 KichThuoc = 30;
 KhoangCachCot = 170;
 KhoangCachHang = 15;
 SoDong = 15;
 SoCot = 15;

 Trong = 0;
 NguoiChoi = 1;
 May = 2;

 type
 Banco = object
 Procedure VeBanCo;
 Procedure VeBangThongTin;
 Procedure KhoiTaoMangOco;
 Procedure VeQuanCo(X, Y :integer);
 end;
 ThangThua = object
 Function KiemTraDoc(donght, cotht, giatri : integer) : Boolean;
 Function KiemTraNgang(donght, cotht, giatri : integer) : Boolean;
 Function KiemTraCheoXuoi(donght, cotht, giatri : integer) : Boolean;
 Function KiemTraCheoNguoc(donght, cotht, giatri : integer) : Boolean;
 Function KiemTraThang(donght, cotht, giatri : integer) : Boolean;
 Procedure XuLiThangThua;
 end;
 AI = object
 MangDiemTanCong : array[0..10] of longint;
 MangDiemPhongNgu : array[0..10] of longint;

 Function KiemTraDocTC(donght, cotht, giatri : integer) : integer;
 Function KiemTraNgangTC(donght, cotht, giatri : integer) : integer;
 Function KiemTraCheoXuoiTC(donght, cotht, giatri : integer) : integer;
 Function KiemTraCheoNguocTC(donght, cotht, giatri : integer) : integer;
 Function KiemTraDocPN(donght, cotht, giatri : integer) : integer;
 Function KiemTraNgangPN(donght, cotht, giatri : integer) : integer;
 Function KiemTraCheoXuoiPN(donght, cotht, giatri : integer) : integer;
 Function KiemTraCheoNguocPN(donght, cotht, giatri : integer) : integer;
 Procedure DanhCo;
 end;

 var
     Gd,Gm : integer;
     MangOco : array[1..SoDong,1..SoCot] of integer;
     VitriX : array[1..SoCot * SoDong] of integer;
     LuuCot : array[0..800] of integer;
     LuuDong: array[0..800] of integer;
     VitriY : array[1..SoDong * Sodong] of integer;
     SanSang : Boolean;
     LuotDi: integer;
     bc : BanCo;
     tt: ThangThua;
     ttnt : AI;

 {===========S Su Kien==================}

 function mousex:word;assembler;asm
 mov ax,3; int 33h; mov ax,cx end;

 function mousey:word;assembler;asm
 mov ax,3; int 33h; mov ax,dx end;

 function leftclick:boolean;assembler;asm
 mov ax,3; int 33h; and bx,1; mov ax,bx end;

 function MouseArea(x1,y1,x2,y2:word):boolean;
 begin
 if     (LeftClick)
        and (mousex >=x1)
        and (mousex <=x2)
        and (mousey >=y1)
        and (mousey <=y2)
 then mousearea:=true
 else mousearea:=false;
 end;

 Function InitMouse : boolean;
 var r: registers;
 Begin
 r.ax:=$00;intr($33,r);
 if r.ax<>0 then InitMouse:=true
 else InitMouse:=false;
 End;

 Procedure ShowMouse;
 Var r: registers;
 begin
 r.ax:=$01;intr($33,r);
 End;

 Procedure HideMouse;
 Var r:registers;
 Begin
 r.ax:=$002;
 intr($33,r);
 End;

 {=============E Su Kien=======================}

 {============S Ban Co===========}

 Procedure BanCo.VeBangThongTin;
 begin
     SetColor(Blue);
     SetFillStyle(1,Blue);
     Bar(10,KhoangCachHang,KhoangCachCot-20,
     KhoangCachHang+KichThuoc*SoCot); { Ve Bang Chinh}

     SetColor(Black);
     SetFillStyle(3,Red);
     Bar(25,KhoangCachHang + 400,KhoangCachCot-35,
     KhoangCachHang+KichThuoc*SoCot - 20);
     SetColor(Yellow);
     SetTextStyle(0, horizDir,2);
     OutTextXy(50,KhoangCachHang + 408,'EXIT');{ Ve Nut EXIT}

     SetColor(Green);
     SetFillStyle(1,Yellow);
     Bar(25,KhoangCachHang + 300,KhoangCachCot-35,
     KhoangCachHang+KichThuoc*SoCot - 90);
     SetColor(Black);
     SetTextStyle(0, horizDir,2);
     OutTextXy(50,KhoangCachHang + 308,'New');
     OutTextXy(50,KhoangCachHang + 332,'Game');{ Ve Nut New Game}

     SetTextStyle(0,horizDir,4);
     Setcolor(LightGreen);
     OutTextXy(10+10,KhoangCachHang + 40,'Game');
     SetColor(LightRed);
     SetFillStyle(1,Cyan);
     OutTextXy(25,KhoangcachHang + 100,'Caro');{ Ghi chu 'Game Caro'}

     Bar(25,KhoangCachHang + 170,KhoangCachCot-35,
     KhoangCachHang+270);
     SetFillStyle(1,Black);
     SetColor(Black);
     FillEllipse(54,KhoangCachHang + 195,20,20);
     FillEllipse(104,KhoangCachHang + 245,20,20);
     SetColor(white);
     SetFillStyle(1,white);
     FillEllipse(104,KhoangCachHang + 195,20,20);
     FillEllipse(54,KhoangCachHang + 245,20,20);
     SetColor(Yellow);
     Line(79,KhoangCachHang + 170,
     79,KhoangCachHang+270);
     Line(25,KhoangCachHang + 219,KhoangCachCot-35,
     KhoangCachHang + 219);
     RecTangle(24,KhoangCachHang + 169,KhoangCachCot-34,
     KhoangCachHang+271);
     SetColor(Black);{ Ve Hinh Ban Co CaRo }

 end;

 Procedure BanCo.KhoiTaoMangOCo;
 var dong, cot : integer;
 begin
    for dong := 1 to SoDong do
        for cot := 1 to SoCot do
           begin
              MangOco[dong, cot] := 0;
           end;
 end;

 Procedure BanCo.VeQuanCo(X, Y: integer);
 var vtX, vtY, kt, donght, cotht : integer;
     tam : string;
 begin
      HideMouse;
      vtX := KhoangCachCot + (X - KhoangCachCot) div KichThuoc * KichThuoc
      + KichThuoc div 2;
      vtY := KhoangCachHang + (Y - KhoangCachHang) div KichThuoc * KichThuoc
      + KichThuoc div 2;
      kt := KichThuoc div 2 - 4;
      donght := (Y - KhoangCachHang) div KichThuoc + 1;
      cotht  := (X - KhoangCachCot) div KichThuoc + 1;
      if (MangOco[donght, cotht] = Trong) then
      begin
                if LuotDi = NguoiChoi then
                SetFillStyle(1,White)
                else if LuotDi = May then
                SetFillStyle(1,Blue)
                else if LuotDi = Trong then
                SetFillStyle(1,Black);
                FillEllipse(vtX, vtY, kt, kt);
                MangOco[donght, cotht] := LuotDi;
                with tt do
                begin
                    if (KiemTrathang(donght, cotht, MangOco[donght,cotht]))
                    then
                    XuLiThangThua;
                end;
                if Luotdi = Nguoichoi then
                begin LuotDi := May;
                end
                else begin
                LuotDi := NguoiChoi;
                end;
      end;
      ShowMouse;
 end;
 Procedure BanCo.VeBanCo;
 var dong,cot : integer;
 begin
 HideMouse;
 ClearDevice;
 SetColor(Green);
 Luotdi := May;
 for dong:=0 to SoDong do
     begin
        Line(KhoangCachCot,KhoangCachHang+dong*KichThuoc,
        KhoangCachCot+SoDong*KichThuoc,KhoangCachHang+dong*KichThuoc);
     end;
 for cot:=0 to SoCot do
     begin
        Line(KhoangCachCot+cot*KichThuoc,KhoangCachHang,
        KhoangCachCot+cot*KichThuoc,KhoangCachHang+KichThuoc*SoCot);
     end;
     VeBangThongTin;
     KhoiTaoMangOco;
 ShowMouse;
 end;

 {============E Ban Co===========}

 {=============S Thang Thua==========================}
 Function ThangThua.KiemTraDoc(donght, cotht, giatri : integer) : Boolean;
 var dong,kt,soquandich: integer;
 begin
      kt := 0;
      soquandich := 0;
      for dong:= donght - 1 downto 1 do
          if (MangOco[dong, cotht] = giatri) then
              kt:=kt+1
          else if (MangOco[dong, cotht] = trong) then
               break
          else
               begin
                  soquandich := soquandich+1;
                  break;
               end;
      for dong:= donght to SoDong do
          if (MangOco[dong, cotht] = giatri) then
              kt:=kt+1
          else if (MangOco[dong, cotht] = trong) then
               break
          else
          begin
                  soquandich := soquandich+1;
                  break;

               end;

       if (SoquanDich >= 2) then
       KiemTraDoc := False
       else if (kt >= 5) then
       KiemTraDoc := True
       else if (kt < 5) then
       KiemTraDoc := False;

 end;

Function ThangThua.KiemTraNgang(donght, cotht, giatri : integer) : Boolean;
 var cot,kt,soquandich: integer;
 begin
      kt := 0;
      soquandich := 0;
      for cot:= cotht - 1 downto 1 do
          if (MangOco[donght, cot] = giatri) then
              kt:=kt+1
          else if (MangOco[donght, cot] = trong) then
               break
          else
               begin
                  soquandich := soquandich+1;
                  break;
               end;
      for cot:= cotht to SoCot do
          if (MangOco[donght, cot] = giatri) then
              kt:=kt+1
          else if (MangOco[donght, cot] = trong) then
               break
          else
          begin
                  soquandich := soquandich+1;
                  break;

               end;

       if (SoquanDich >= 2) then
       KiemTraNgang := False
       else if (kt >= 5) then
       KiemTraNgang := True
       else if (kt < 5) then
       KiemTraNgang := False;
 end;

 Function ThangThua.KiemTraCheoXuoi(donght, cotht, giatri : integer) : Boolean;
 var thaythe,kt,soquandich,gt,gtm: integer;
 begin
      kt := 0;
      soquandich := 0;
      if (donght < cotht) then
         gt := donght
      else
         gt := cotht;
      for thaythe:= 1 to gt-1 do
          if (MangOco[donght - thaythe, cotht - thaythe] = giatri) then
              kt:=kt+1
          else if (MangOco[donght - thaythe, cotht - thaythe] = trong) then
               break
          else
               begin
                  soquandich := soquandich+1;
                  break;
               end;
          if (donght > cotht) then
          begin
              gt := donght;
              gtm := SoDong;
          end
          else
          begin
              gt := cotht;
              gtm := SoCot;
          end;
      for thaythe := 0 to gtm-gt do
          if (MangOco[donght + thaythe, cotht + thaythe] = giatri) then
              kt:=kt+1
          else if (MangOco[donght + thaythe, cotht + thaythe] = trong) then
               break
          else
          begin
                  soquandich := soquandich+1;
                  break;

               end;

       if (SoquanDich >= 2) then
       KiemTraCheoXuoi := False
       else if (kt >= 5) then
       KiemTraCheoXuoi := True
       else if (kt < 5) then
       KiemTraCheoXuoi := False;

 end;

 Function ThangThua.KiemTraCheoNguoc(donght, cotht, giatri : integer) : Boolean;
 var thaythe,kt,soquandich,gt: integer;
 begin
      kt := 0;
      soquandich := 0;
      if (donght < SoCot-cotht+1) then
         gt := donght
      else
         gt := SoCot-cotht+1;
      for thaythe:= 1 to gt-1 do
          if (MangOco[donght - thaythe, cotht + thaythe] = giatri) then
              kt:=kt+1
          else if (MangOco[donght - thaythe, cotht + thaythe] = trong) then
               break
          else
               begin
                  soquandich := soquandich+1;
                  break;
               end;

          if (SoDong-donght+1 < cotht) then
          begin
              gt := SoDong-donght+1;
          end
          else
          begin
              gt := cotht;
          end;
      for thaythe := 0 to gt-1 do
          if (MangOco[donght + thaythe, cotht - thaythe] = giatri) then
              kt:=kt+1
          else if (MangOco[donght + thaythe, cotht - thaythe] = trong) then
               break
          else
          begin
                  soquandich := soquandich+1;
                  break;

               end;

       if (SoquanDich >= 2) then
       KiemTraCheoNguoc := False
       else if (kt >= 5) then
       KiemTraCheoNguoc := True
       else if (kt < 5) then
       KiemTraCheoNguoc := False;

 end;

 Function ThangThua.KiemTraThang(donght, cotht, giatri : integer) : Boolean;
 begin
       if  not KiemTraDoc(donght, cotht, giatri) and
           not KiemTraNgang(donght, cotht, giatri) and
           not KiemTraCheoXuoi(donght, cotht, giatri) and
           not KiemTraCheoNguoc(donght, cotht, giatri)
       then KiemTraThang := False
       else KiemTraThang := True;
 end;

 Procedure ThangThua.XuLiThangThua;
 begin
      SetColor(Red);
      SetTextStyle(0,horizDir,5);
      if LuotDi = Nguoichoi then
      OuttextXy(200,200,'You Win')
      else
      OutTextXy(200,200,'You Lose');
      SanSang := False;
 end;
 {=============E Thang Thua==========================}
 {=============S AI==================================}
 Function AI.KiemTraDocTC(donght, cotht, giatri : integer) : integer;
 var dong: integer;
     soquanta, soquandich,trave : integer;
 begin
      soquanta := 0;
      soquandich := 0;
      for dong:= donght - 1 downto 1 do
      if (MangOco[dong, cotht] = giatri) then
      soquanta:=soquanta+1
      else if (MangOco[dong, cotht] = trong) then
      break
      else
      begin
      soquandich := soquandich+1;
      break;
      end;
      for dong:= donght+1 to SoDong do
      if (MangOco[dong, cotht] = giatri) then
      soquanta:=soquanta+1
      else if (MangOco[dong, cotht] = trong) then
      break
      else
      begin
      soquandich := soquandich+1;
      break;
      end;
      trave := MangDiemTanCong[soquanta] - MangDiemPhongNgu[soquandich];
      if trave < 0 then trave := 0;
      if Soquandich = 2 then
      KiemTraDocTC := 0
      else
      KiemTraDocTC := trave;
 end;

 Function AI.KiemTraNgangTC(donght, cotht, giatri : integer) : integer;
 var cot: integer;
     soquanta, soquandich,trave : integer;
 begin
      soquanta := 0;
      soquandich := 0;
      for cot:= cotht - 1 downto 1 do
      if (MangOco[donght, cot] = giatri) then
      soquanta:=soquanta+1
      else if (MangOco[donght, cot] = trong) then
      break
      else
      begin
      soquandich := soquandich+1;
      break;
      end;
      for cot:= cotht+1 to SoDong do
      if (MangOco[donght, cot] = giatri) then
      soquanta:=soquanta+1
      else if (MangOco[donght, cot] = trong) then
      break
      else
      begin
      soquandich := soquandich+1;
      break;
      end;
      trave := MangDiemTanCong[soquanta] - MangDiemPhongNgu[soquandich];
      if trave < 0 then trave := 0;
      if Soquandich = 2 then
      KiemTraNgangTC := 0
      else
      KiemTraNgangTC := trave;
 end;

 Function AI.KiemTraCheoXuoiTC(donght, cotht, giatri : integer) : integer;
  var gt, gtm, thaythe: integer;
     soquanta, soquandich,trave : integer;
 begin
      soquanta := 0;
      soquandich := 0;
      if (donght < cotht) then
         gt := donght
      else
         gt := cotht;
      for thaythe:= 1 to gt-1 do
          if (MangOco[donght - thaythe, cotht - thaythe] = giatri) then
              soquanta:=soquanta+1
          else if (MangOco[donght - thaythe, cotht - thaythe] = trong) then
               break
          else
               begin
                  soquandich := soquandich+1;
                  break;
               end;
          if (donght > cotht) then
          begin
              gt := donght;
              gtm := SoDong;
          end
          else
          begin
              gt := cotht;
              gtm := SoCot;
          end;
      for thaythe := 1 to gtm-gt do
          if (MangOco[donght + thaythe, cotht + thaythe] = giatri) then
              soquanta:=soquanta+1
          else if (MangOco[donght + thaythe, cotht + thaythe] = trong) then
               break
          else
          begin
                  soquandich := soquandich+1;
                  break;
          end;

      trave := Mangdiemtancong[soquanta] - mangdiemphongngu[soquandich];
      if (trave < 0) then trave := 0;

      if (soquandich = 2) then
      KiemTraCheoXuoiTC := 0
      else
      KiemTraCheoXuoiTC := trave;
 end;

 Function AI.KiemTraCheoNguocTC(donght, cotht, giatri : integer) : integer;
 var thaythe,gt: integer;
     soquanta, soquandich,trave : integer;
 begin
      soquanta := 0;
      soquandich := 0;
      if (donght < SoCot-cotht+1) then
         gt := donght
      else
         gt := SoCot-cotht+1;
      for thaythe:= 1 to gt-1 do
          if (MangOco[donght - thaythe, cotht + thaythe] = giatri) then
              soquanta:=soquanta+1
          else if (MangOco[donght - thaythe, cotht + thaythe] = trong) then
               break
          else
               begin
                  soquandich := soquandich+1;
                  break;
               end;

          if (SoDong-donght+1 < cotht) then
          begin
              gt := SoDong-donght+1;
          end
          else
          begin
              gt := cotht;
          end;
      for thaythe := 1 to gt-1 do
          if (MangOco[donght + thaythe, cotht - thaythe] = giatri) then
              soquanta:=soquanta+1
          else if (MangOco[donght + thaythe, cotht - thaythe] = trong) then
               break
          else
          begin
                  soquandich := soquandich+1;
                  break;

          end;
      trave := MangDiemTanCong[soquanta] - MangDiemPhongNgu[soquandich];
      if trave < 0 then trave := 0;
      if Soquandich = 2 then
      KiemTraCheoNguocTC := 0
      else
      KiemTraCheoNguocTC := trave;
 end;

 Function AI.KiemTraDocPN(donght, cotht, giatri : integer) : integer;
 var dong: integer;
     soquanta, soquandich,trave : integer;
 begin
      soquanta := 0;
      soquandich := 0;
      for dong:= donght - 1 downto 1 do
      if (MangOco[dong, cotht] = giatri) then
      begin
      soquanta:=soquanta+1;
      break;
      end
      else if (MangOco[dong, cotht] = trong) then
      break
      else
      begin
      soquandich := soquandich+1;
      end;

      for dong:= donght+1 to SoDong do
      if (MangOco[dong, cotht] = giatri) then
      begin
      soquanta:=soquanta+1;
      break;
      end
      else if (MangOco[dong, cotht] = trong) then
      break
      else
      begin
      soquandich := soquandich+1;
      end;
      if (soquandich >= 4) and (soquanta <= 1) then
      soquandich := soquandich + 2
      else if (soquandich = 3) and (soquanta = 0) then
      soquandich := soquandich+1;
      trave := MangDiemPhongNgu[soquandich] - MangDiemTanCong[soquanta];
      if trave < 0 then trave := 0;
      if Soquanta = 2 then
      KiemTraDocPN := 0
      else
      KiemTraDocPN := trave;
 end;

 Function AI.KiemTraNgangPN(donght, cotht, giatri : integer) : integer;
 var cot: integer;
     soquanta, soquandich,trave : integer;
 begin
      soquanta := 0;
      soquandich := 0;
      for cot:= cotht - 1 downto 1 do
      if (MangOco[donght, cot] = giatri) then
      begin
      soquanta:=soquanta+1;
      break;
      end
      else if (MangOco[donght, cot] = trong) then
      break
      else
      begin
      soquandich := soquandich+1;
      end;
      for cot:= cotht+1 to SoCot do
      if (MangOco[donght, cot] = giatri) then
      begin
      soquanta:=soquanta+1;
      break;
      end
      else if (MangOco[donght, cot] = trong) then
      break
      else
      begin
      soquandich := soquandich+1;
      end;
      if (soquandich >= 4) and (soquanta <= 1) then
      soquandich := soquandich + 2
      else if (soquandich = 3) and (soquanta = 0) then
      soquandich := soquandich+1;
      trave := MangDiemPhongNgu[soquandich] - MangDiemTanCong[soquanta];
      if trave < 0 then trave := 0;
      if Soquanta = 2 then
      KiemTraNgangPN := 0
      else
      KiemTraNgangPN := trave;
 end;

 Function AI.KiemTraCheoXuoiPN(donght, cotht, giatri : integer) : integer;
  var gt, gtm, thaythe: integer;
     soquanta, soquandich,trave : integer;
 begin
      soquanta := 0;
      soquandich := 0;
      if (donght < cotht) then
         gt := donght
      else
         gt := cotht;
      for thaythe:= 1 to gt-1 do
          if (MangOco[donght - thaythe, cotht - thaythe] = giatri) then
          begin
              soquanta:=soquanta+1;
              break;
          end
          else if (MangOco[donght - thaythe, cotht - thaythe] = trong) then
               break
          else
               begin
                  soquandich := soquandich+1;
               end;
          if (donght > cotht) then
          begin
              gt := donght;
              gtm := SoDong;
          end
          else
          begin
              gt := cotht;
              gtm := SoCot;
          end;
      for thaythe := 1 to gtm-gt do
          if (MangOco[donght + thaythe, cotht + thaythe] = giatri) then
          begin
              soquanta:=soquanta+1;
              break;
          end
          else if (MangOco[donght + thaythe, cotht + thaythe] = trong) then
               break
          else
          begin
                  soquandich := soquandich+1;
          end;
      if (soquandich >= 4) and (soquanta <= 1) then
      soquandich := soquandich + 2
      else if (soquandich = 3) and (soquanta = 0) then
      soquandich := soquandich+1;
      trave := Mangdiemphongngu[soquandich] - MangDiemTanCong[soquanta];
      if (trave < 0) then trave := 0;

      if (soquanta = 2) then
      KiemTraCheoXuoiPN := 0
      else
      KiemTraCheoXuoiPN := trave;
 end;

 Function AI.KiemTraCheoNguocPN(donght, cotht, giatri : integer) : integer;
 var thaythe,gt: integer;
     soquanta, soquandich,trave : integer;
 begin
      soquanta := 0;
      soquandich := 0;
      if (donght < SoCot-cotht+1) then
         gt := donght
      else
         gt := SoCot-cotht+1;
      for thaythe:= 1 to gt-1 do
          if (MangOco[donght - thaythe, cotht + thaythe] = giatri) then
          begin
              soquanta:=soquanta+1;
              break;
          end
          else if (MangOco[donght - thaythe, cotht + thaythe] = trong) then
               break
          else
               begin
                  soquandich := soquandich+1;
               end;

          if (SoDong-donght+1 < cotht) then
          begin
              gt := SoDong-donght+1;
          end
          else
          begin
              gt := cotht;
          end;
      for thaythe := 1 to gt-1 do
          if (MangOco[donght + thaythe, cotht - thaythe] = giatri) then
          begin
              soquanta:=soquanta+1;
              break;
          end
          else if (MangOco[donght + thaythe, cotht - thaythe] = trong) then
               break
          else
          begin
                  soquandich := soquandich+1;
          end;
      if (soquandich >= 4) and (soquanta <= 1) then
      soquandich := soquandich + 2
      else if (soquandich = 3) and (soquanta = 0) then
      soquandich := soquandich+1;
      trave := MangDiemPhongNgu[soquandich] - MangDiemTanCong[soquanta];
      if trave < 0 then trave := 0;
      if Soquanta = 2 then
      KiemTraCheoNguocPN := 0
      else
      KiemTraCheoNguocPN := trave;
 end;

 Procedure AI.DanhCo;
 var diem, diemTC, diemPN, diemtam,diemMax: integer;
     dong, cot, luudong, luucot,donght,cotht : integer;
     tam : string;
     kt : integer;
 begin
 if SanSang then
 begin
      for diem := 0 to 10 do begin
         MangDiemTanCong[diem] := diem * 6;
         if diem <> 0 then
         MangDiemPhongNgu[diem] := diem * 5 + 1
         else
         MangDiemPhongNgu[diem] := diem * 5;
                             end;
      diemtam := 0;
      diemMax := 0;
      luudong := 0;
      luucot := 0;
      for dong := 1 to SoDong do
      begin
           for cot := 1 to SoCot do
           begin
                if MangOco[dong, cot] = Trong then
                begin
                    diemTC := KiemTraDocTC(dong, cot, May) +
                    KiemTraNgangTC(dong, cot, May) +
                    KiemTraCheoXuoiTC(dong, cot, May) +
                    KiemTraCheoNguocTC(dong, cot, May);

                    diemPN := KiemTraDocPN(dong, cot, May) +
                    KiemTraNgangPN(dong, cot, May) +
                    KiemTraCheoXuoiPN(dong, cot, May) +
                    KiemTraCheoNguocPN(dong, cot, May);

                    if (diemTC > diemPN) then
                    diemtam := diemTC
                    else
                    diemtam := diemPN;
                    if (diemMax <= diemtam) then
                    begin
                         diemMax := diemtam;
                         donght := dong;
                         cotht := cot;
                         Luucot := (cot - 1) * KichThuoc + KhoangCachCot;
                         Luudong := (dong - 1) * KichThuoc + KhoangCachHang;
                    end;
                end;
           end;
      end;
      bc.VeQuanCo(luucot,luudong);

 end;
 end;
 {=============E AI==================================}


 BEGIN
 Gd := VGA;
 Gm := VgaHi;
 InitGraph(Gd,Gm,'');
 InitMouse;
 SanSang := False;
 with bc do
 begin
    VeBanCo;
    ShowMouse;
      Repeat
        if (MouseArea(KhoangCachCot,KhoangCachHang,
        KhoangCachCot+SoCot*KichThuoc,KhoangCachHang+SoDong*KichThuoc)
        and SanSang) then
        begin
          VeQuanCo(mousex, mousey);
          ttnt.DanhCo;
        end
        else
        if (MouseArea(10+15,KhoangCachHang + 300,KhoangCachCot-20-15,
     KhoangCachHang+KichThuoc*SoCot - 90)) then
        begin
           VeBanCo;
           VequanCo(KichThuoc*Socot div 2 + KhoangCachCot,
           KichThuoc * Sodong div 2 + KhoangCachHang);
           SanSang := true;
        end;
      Until MouseArea(10+15,KhoangCachHang + 400,KhoangCachCot-20-15,
     KhoangCachHang+KichThuoc*SoCot - 20);
 end;
 CloseGraph;
 ENd.
 

kingsman(lht 2k2)

Mùa hè Hóa học|Ngày hè tuyệt diệu
Thành viên
TV BQT tích cực 2017
Đây là Code Game, chúng ta chơi với máy. Bạn nào có ý kiến gì để bổ sung cho Game của mình thì bình luận ở dưới nha.


program Game_Co_Caro;
uses crt,dos,graph;
const
KichThuoc = 30;
KhoangCachCot = 170;
KhoangCachHang = 15;
SoDong = 15;
SoCot = 15;

Trong = 0;
NguoiChoi = 1;
May = 2;

type
Banco = object
Procedure VeBanCo;
Procedure VeBangThongTin;
Procedure KhoiTaoMangOco;
Procedure VeQuanCo(X, Y :integer);
end;
ThangThua = object
Function KiemTraDoc(donght, cotht, giatri : integer) : Boolean;
Function KiemTraNgang(donght, cotht, giatri : integer) : Boolean;
Function KiemTraCheoXuoi(donght, cotht, giatri : integer) : Boolean;
Function KiemTraCheoNguoc(donght, cotht, giatri : integer) : Boolean;
Function KiemTraThang(donght, cotht, giatri : integer) : Boolean;
Procedure XuLiThangThua;
end;
AI = object
MangDiemTanCong : array[0..10] of longint;
MangDiemPhongNgu : array[0..10] of longint;

Function KiemTraDocTC(donght, cotht, giatri : integer) : integer;
Function KiemTraNgangTC(donght, cotht, giatri : integer) : integer;
Function KiemTraCheoXuoiTC(donght, cotht, giatri : integer) : integer;
Function KiemTraCheoNguocTC(donght, cotht, giatri : integer) : integer;
Function KiemTraDocPN(donght, cotht, giatri : integer) : integer;
Function KiemTraNgangPN(donght, cotht, giatri : integer) : integer;
Function KiemTraCheoXuoiPN(donght, cotht, giatri : integer) : integer;
Function KiemTraCheoNguocPN(donght, cotht, giatri : integer) : integer;
Procedure DanhCo;
end;

var
Gd,Gm : integer;
MangOco : array[1..SoDong,1..SoCot] of integer;
VitriX : array[1..SoCot * SoDong] of integer;
LuuCot : array[0..800] of integer;
LuuDong: array[0..800] of integer;
VitriY : array[1..SoDong * Sodong] of integer;
SanSang : Boolean;
LuotDi: integer;
bc : BanCo;
tt: ThangThua;
ttnt : AI;

{===========S Su Kien==================}

function mousex:word;assembler;asm
mov ax,3; int 33h; mov ax,cx end;

function mousey:word;assembler;asm
mov ax,3; int 33h; mov ax,dx end;

function leftclick:boolean;assembler;asm
mov ax,3; int 33h; and bx,1; mov ax,bx end;

function MouseArea(x1,y1,x2,y2:word):boolean;
begin
if (LeftClick)
and (mousex >=x1)
and (mousex <=x2)
and (mousey >=y1)
and (mousey <=y2)
then mousearea:=true
else mousearea:=false;
end;

Function InitMouse : boolean;
var r: registers;
Begin
r.ax:=$00;intr($33,r);
if r.ax<>0 then InitMouse:=true
else InitMouse:=false;
End;

Procedure ShowMouse;
Var r: registers;
begin
r.ax:=$01;intr($33,r);
End;

Procedure HideMouse;
Var r:registers;
Begin
r.ax:=$002;
intr($33,r);
End;

{=============E Su Kien=======================}

{============S Ban Co===========}

Procedure BanCo.VeBangThongTin;
begin
SetColor(Blue);
SetFillStyle(1,Blue);
Bar(10,KhoangCachHang,KhoangCachCot-20,
KhoangCachHang+KichThuoc*SoCot); { Ve Bang Chinh}

SetColor(Black);
SetFillStyle(3,Red);
Bar(25,KhoangCachHang + 400,KhoangCachCot-35,
KhoangCachHang+KichThuoc*SoCot - 20);
SetColor(Yellow);
SetTextStyle(0, horizDir,2);
OutTextXy(50,KhoangCachHang + 408,'EXIT');{ Ve Nut EXIT}

SetColor(Green);
SetFillStyle(1,Yellow);
Bar(25,KhoangCachHang + 300,KhoangCachCot-35,
KhoangCachHang+KichThuoc*SoCot - 90);
SetColor(Black);
SetTextStyle(0, horizDir,2);
OutTextXy(50,KhoangCachHang + 308,'New');
OutTextXy(50,KhoangCachHang + 332,'Game');{ Ve Nut New Game}

SetTextStyle(0,horizDir,4);
Setcolor(LightGreen);
OutTextXy(10+10,KhoangCachHang + 40,'Game');
SetColor(LightRed);
SetFillStyle(1,Cyan);
OutTextXy(25,KhoangcachHang + 100,'Caro');{ Ghi chu 'Game Caro'}

Bar(25,KhoangCachHang + 170,KhoangCachCot-35,
KhoangCachHang+270);
SetFillStyle(1,Black);
SetColor(Black);
FillEllipse(54,KhoangCachHang + 195,20,20);
FillEllipse(104,KhoangCachHang + 245,20,20);
SetColor(white);
SetFillStyle(1,white);
FillEllipse(104,KhoangCachHang + 195,20,20);
FillEllipse(54,KhoangCachHang + 245,20,20);
SetColor(Yellow);
Line(79,KhoangCachHang + 170,
79,KhoangCachHang+270);
Line(25,KhoangCachHang + 219,KhoangCachCot-35,
KhoangCachHang + 219);
RecTangle(24,KhoangCachHang + 169,KhoangCachCot-34,
KhoangCachHang+271);
SetColor(Black);{ Ve Hinh Ban Co CaRo }

end;

Procedure BanCo.KhoiTaoMangOCo;
var dong, cot : integer;
begin
for dong := 1 to SoDong do
for cot := 1 to SoCot do
begin
MangOco[dong, cot] := 0;
end;
end;

Procedure BanCo.VeQuanCo(X, Y: integer);
var vtX, vtY, kt, donght, cotht : integer;
tam : string;
begin
HideMouse;
vtX := KhoangCachCot + (X - KhoangCachCot) div KichThuoc * KichThuoc
+ KichThuoc div 2;
vtY := KhoangCachHang + (Y - KhoangCachHang) div KichThuoc * KichThuoc
+ KichThuoc div 2;
kt := KichThuoc div 2 - 4;
donght := (Y - KhoangCachHang) div KichThuoc + 1;
cotht := (X - KhoangCachCot) div KichThuoc + 1;
if (MangOco[donght, cotht] = Trong) then
begin
if LuotDi = NguoiChoi then
SetFillStyle(1,White)
else if LuotDi = May then
SetFillStyle(1,Blue)
else if LuotDi = Trong then
SetFillStyle(1,Black);
FillEllipse(vtX, vtY, kt, kt);
MangOco[donght, cotht] := LuotDi;
with tt do
begin
if (KiemTrathang(donght, cotht, MangOco[donght,cotht]))
then
XuLiThangThua;
end;
if Luotdi = Nguoichoi then
begin LuotDi := May;
end
else begin
LuotDi := NguoiChoi;
end;
end;
ShowMouse;
end;
Procedure BanCo.VeBanCo;
var dong,cot : integer;
begin
HideMouse;
ClearDevice;
SetColor(Green);
Luotdi := May;
for dong:=0 to SoDong do
begin
Line(KhoangCachCot,KhoangCachHang+dong*KichThuoc,
KhoangCachCot+SoDong*KichThuoc,KhoangCachHang+dong*KichThuoc);
end;
for cot:=0 to SoCot do
begin
Line(KhoangCachCot+cot*KichThuoc,KhoangCachHang,
KhoangCachCot+cot*KichThuoc,KhoangCachHang+KichThuoc*SoCot);
end;
VeBangThongTin;
KhoiTaoMangOco;
ShowMouse;
end;

{============E Ban Co===========}

{=============S Thang Thua==========================}
Function ThangThua.KiemTraDoc(donght, cotht, giatri : integer) : Boolean;
var dong,kt,soquandich: integer;
begin
kt := 0;
soquandich := 0;
for dong:= donght - 1 downto 1 do
if (MangOco[dong, cotht] = giatri) then
kt:=kt+1
else if (MangOco[dong, cotht] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;
for dong:= donght to SoDong do
if (MangOco[dong, cotht] = giatri) then
kt:=kt+1
else if (MangOco[dong, cotht] = trong) then
break
else
begin
soquandich := soquandich+1;
break;

end;

if (SoquanDich >= 2) then
KiemTraDoc := False
else if (kt >= 5) then
KiemTraDoc := True
else if (kt < 5) then
KiemTraDoc := False;

end;

Function ThangThua.KiemTraNgang(donght, cotht, giatri : integer) : Boolean;
var cot,kt,soquandich: integer;
begin
kt := 0;
soquandich := 0;
for cot:= cotht - 1 downto 1 do
if (MangOco[donght, cot] = giatri) then
kt:=kt+1
else if (MangOco[donght, cot] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;
for cot:= cotht to SoCot do
if (MangOco[donght, cot] = giatri) then
kt:=kt+1
else if (MangOco[donght, cot] = trong) then
break
else
begin
soquandich := soquandich+1;
break;

end;

if (SoquanDich >= 2) then
KiemTraNgang := False
else if (kt >= 5) then
KiemTraNgang := True
else if (kt < 5) then
KiemTraNgang := False;
end;

Function ThangThua.KiemTraCheoXuoi(donght, cotht, giatri : integer) : Boolean;
var thaythe,kt,soquandich,gt,gtm: integer;
begin
kt := 0;
soquandich := 0;
if (donght < cotht) then
gt := donght
else
gt := cotht;
for thaythe:= 1 to gt-1 do
if (MangOco[donght - thaythe, cotht - thaythe] = giatri) then
kt:=kt+1
else if (MangOco[donght - thaythe, cotht - thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;
if (donght > cotht) then
begin
gt := donght;
gtm := SoDong;
end
else
begin
gt := cotht;
gtm := SoCot;
end;
for thaythe := 0 to gtm-gt do
if (MangOco[donght + thaythe, cotht + thaythe] = giatri) then
kt:=kt+1
else if (MangOco[donght + thaythe, cotht + thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
break;

end;

if (SoquanDich >= 2) then
KiemTraCheoXuoi := False
else if (kt >= 5) then
KiemTraCheoXuoi := True
else if (kt < 5) then
KiemTraCheoXuoi := False;

end;

Function ThangThua.KiemTraCheoNguoc(donght, cotht, giatri : integer) : Boolean;
var thaythe,kt,soquandich,gt: integer;
begin
kt := 0;
soquandich := 0;
if (donght < SoCot-cotht+1) then
gt := donght
else
gt := SoCot-cotht+1;
for thaythe:= 1 to gt-1 do
if (MangOco[donght - thaythe, cotht + thaythe] = giatri) then
kt:=kt+1
else if (MangOco[donght - thaythe, cotht + thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;

if (SoDong-donght+1 < cotht) then
begin
gt := SoDong-donght+1;
end
else
begin
gt := cotht;
end;
for thaythe := 0 to gt-1 do
if (MangOco[donght + thaythe, cotht - thaythe] = giatri) then
kt:=kt+1
else if (MangOco[donght + thaythe, cotht - thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
break;

end;

if (SoquanDich >= 2) then
KiemTraCheoNguoc := False
else if (kt >= 5) then
KiemTraCheoNguoc := True
else if (kt < 5) then
KiemTraCheoNguoc := False;

end;

Function ThangThua.KiemTraThang(donght, cotht, giatri : integer) : Boolean;
begin
if not KiemTraDoc(donght, cotht, giatri) and
not KiemTraNgang(donght, cotht, giatri) and
not KiemTraCheoXuoi(donght, cotht, giatri) and
not KiemTraCheoNguoc(donght, cotht, giatri)
then KiemTraThang := False
else KiemTraThang := True;
end;

Procedure ThangThua.XuLiThangThua;
begin
SetColor(Red);
SetTextStyle(0,horizDir,5);
if LuotDi = Nguoichoi then
OuttextXy(200,200,'You Win')
else
OutTextXy(200,200,'You Lose');
SanSang := False;
end;
{=============E Thang Thua==========================}
{=============S AI==================================}
Function AI.KiemTraDocTC(donght, cotht, giatri : integer) : integer;
var dong: integer;
soquanta, soquandich,trave : integer;
begin
soquanta := 0;
soquandich := 0;
for dong:= donght - 1 downto 1 do
if (MangOco[dong, cotht] = giatri) then
soquanta:=soquanta+1
else if (MangOco[dong, cotht] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;
for dong:= donght+1 to SoDong do
if (MangOco[dong, cotht] = giatri) then
soquanta:=soquanta+1
else if (MangOco[dong, cotht] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;
trave := MangDiemTanCong[soquanta] - MangDiemPhongNgu[soquandich];
if trave < 0 then trave := 0;
if Soquandich = 2 then
KiemTraDocTC := 0
else
KiemTraDocTC := trave;
end;

Function AI.KiemTraNgangTC(donght, cotht, giatri : integer) : integer;
var cot: integer;
soquanta, soquandich,trave : integer;
begin
soquanta := 0;
soquandich := 0;
for cot:= cotht - 1 downto 1 do
if (MangOco[donght, cot] = giatri) then
soquanta:=soquanta+1
else if (MangOco[donght, cot] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;
for cot:= cotht+1 to SoDong do
if (MangOco[donght, cot] = giatri) then
soquanta:=soquanta+1
else if (MangOco[donght, cot] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;
trave := MangDiemTanCong[soquanta] - MangDiemPhongNgu[soquandich];
if trave < 0 then trave := 0;
if Soquandich = 2 then
KiemTraNgangTC := 0
else
KiemTraNgangTC := trave;
end;

Function AI.KiemTraCheoXuoiTC(donght, cotht, giatri : integer) : integer;
var gt, gtm, thaythe: integer;
soquanta, soquandich,trave : integer;
begin
soquanta := 0;
soquandich := 0;
if (donght < cotht) then
gt := donght
else
gt := cotht;
for thaythe:= 1 to gt-1 do
if (MangOco[donght - thaythe, cotht - thaythe] = giatri) then
soquanta:=soquanta+1
else if (MangOco[donght - thaythe, cotht - thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;
if (donght > cotht) then
begin
gt := donght;
gtm := SoDong;
end
else
begin
gt := cotht;
gtm := SoCot;
end;
for thaythe := 1 to gtm-gt do
if (MangOco[donght + thaythe, cotht + thaythe] = giatri) then
soquanta:=soquanta+1
else if (MangOco[donght + thaythe, cotht + thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;

trave := Mangdiemtancong[soquanta] - mangdiemphongngu[soquandich];
if (trave < 0) then trave := 0;

if (soquandich = 2) then
KiemTraCheoXuoiTC := 0
else
KiemTraCheoXuoiTC := trave;
end;

Function AI.KiemTraCheoNguocTC(donght, cotht, giatri : integer) : integer;
var thaythe,gt: integer;
soquanta, soquandich,trave : integer;
begin
soquanta := 0;
soquandich := 0;
if (donght < SoCot-cotht+1) then
gt := donght
else
gt := SoCot-cotht+1;
for thaythe:= 1 to gt-1 do
if (MangOco[donght - thaythe, cotht + thaythe] = giatri) then
soquanta:=soquanta+1
else if (MangOco[donght - thaythe, cotht + thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;

if (SoDong-donght+1 < cotht) then
begin
gt := SoDong-donght+1;
end
else
begin
gt := cotht;
end;
for thaythe := 1 to gt-1 do
if (MangOco[donght + thaythe, cotht - thaythe] = giatri) then
soquanta:=soquanta+1
else if (MangOco[donght + thaythe, cotht - thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
break;

end;
trave := MangDiemTanCong[soquanta] - MangDiemPhongNgu[soquandich];
if trave < 0 then trave := 0;
if Soquandich = 2 then
KiemTraCheoNguocTC := 0
else
KiemTraCheoNguocTC := trave;
end;

Function AI.KiemTraDocPN(donght, cotht, giatri : integer) : integer;
var dong: integer;
soquanta, soquandich,trave : integer;
begin
soquanta := 0;
soquandich := 0;
for dong:= donght - 1 downto 1 do
if (MangOco[dong, cotht] = giatri) then
begin
soquanta:=soquanta+1;
break;
end
else if (MangOco[dong, cotht] = trong) then
break
else
begin
soquandich := soquandich+1;
end;

for dong:= donght+1 to SoDong do
if (MangOco[dong, cotht] = giatri) then
begin
soquanta:=soquanta+1;
break;
end
else if (MangOco[dong, cotht] = trong) then
break
else
begin
soquandich := soquandich+1;
end;
if (soquandich >= 4) and (soquanta <= 1) then
soquandich := soquandich + 2
else if (soquandich = 3) and (soquanta = 0) then
soquandich := soquandich+1;
trave := MangDiemPhongNgu[soquandich] - MangDiemTanCong[soquanta];
if trave < 0 then trave := 0;
if Soquanta = 2 then
KiemTraDocPN := 0
else
KiemTraDocPN := trave;
end;

Function AI.KiemTraNgangPN(donght, cotht, giatri : integer) : integer;
var cot: integer;
soquanta, soquandich,trave : integer;
begin
soquanta := 0;
soquandich := 0;
for cot:= cotht - 1 downto 1 do
if (MangOco[donght, cot] = giatri) then
begin
soquanta:=soquanta+1;
break;
end
else if (MangOco[donght, cot] = trong) then
break
else
begin
soquandich := soquandich+1;
end;
for cot:= cotht+1 to SoCot do
if (MangOco[donght, cot] = giatri) then
begin
soquanta:=soquanta+1;
break;
end
else if (MangOco[donght, cot] = trong) then
break
else
begin
soquandich := soquandich+1;
end;
if (soquandich >= 4) and (soquanta <= 1) then
soquandich := soquandich + 2
else if (soquandich = 3) and (soquanta = 0) then
soquandich := soquandich+1;
trave := MangDiemPhongNgu[soquandich] - MangDiemTanCong[soquanta];
if trave < 0 then trave := 0;
if Soquanta = 2 then
KiemTraNgangPN := 0
else
KiemTraNgangPN := trave;
end;

Function AI.KiemTraCheoXuoiPN(donght, cotht, giatri : integer) : integer;
var gt, gtm, thaythe: integer;
soquanta, soquandich,trave : integer;
begin
soquanta := 0;
soquandich := 0;
if (donght < cotht) then
gt := donght
else
gt := cotht;
for thaythe:= 1 to gt-1 do
if (MangOco[donght - thaythe, cotht - thaythe] = giatri) then
begin
soquanta:=soquanta+1;
break;
end
else if (MangOco[donght - thaythe, cotht - thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
end;
if (donght > cotht) then
begin
gt := donght;
gtm := SoDong;
end
else
begin
gt := cotht;
gtm := SoCot;
end;
for thaythe := 1 to gtm-gt do
if (MangOco[donght + thaythe, cotht + thaythe] = giatri) then
begin
soquanta:=soquanta+1;
break;
end
else if (MangOco[donght + thaythe, cotht + thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
end;
if (soquandich >= 4) and (soquanta <= 1) then
soquandich := soquandich + 2
else if (soquandich = 3) and (soquanta = 0) then
soquandich := soquandich+1;
trave := Mangdiemphongngu[soquandich] - MangDiemTanCong[soquanta];
if (trave < 0) then trave := 0;

if (soquanta = 2) then
KiemTraCheoXuoiPN := 0
else
KiemTraCheoXuoiPN := trave;
end;

Function AI.KiemTraCheoNguocPN(donght, cotht, giatri : integer) : integer;
var thaythe,gt: integer;
soquanta, soquandich,trave : integer;
begin
soquanta := 0;
soquandich := 0;
if (donght < SoCot-cotht+1) then
gt := donght
else
gt := SoCot-cotht+1;
for thaythe:= 1 to gt-1 do
if (MangOco[donght - thaythe, cotht + thaythe] = giatri) then
begin
soquanta:=soquanta+1;
break;
end
else if (MangOco[donght - thaythe, cotht + thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
end;

if (SoDong-donght+1 < cotht) then
begin
gt := SoDong-donght+1;
end
else
begin
gt := cotht;
end;
for thaythe := 1 to gt-1 do
if (MangOco[donght + thaythe, cotht - thaythe] = giatri) then
begin
soquanta:=soquanta+1;
break;
end
else if (MangOco[donght + thaythe, cotht - thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
end;
if (soquandich >= 4) and (soquanta <= 1) then
soquandich := soquandich + 2
else if (soquandich = 3) and (soquanta = 0) then
soquandich := soquandich+1;
trave := MangDiemPhongNgu[soquandich] - MangDiemTanCong[soquanta];
if trave < 0 then trave := 0;
if Soquanta = 2 then
KiemTraCheoNguocPN := 0
else
KiemTraCheoNguocPN := trave;
end;

Procedure AI.DanhCo;
var diem, diemTC, diemPN, diemtam,diemMax: integer;
dong, cot, luudong, luucot,donght,cotht : integer;
tam : string;
kt : integer;
begin
if SanSang then
begin
for diem := 0 to 10 do begin
MangDiemTanCong[diem] := diem * 6;
if diem <> 0 then
MangDiemPhongNgu[diem] := diem * 5 + 1
else
MangDiemPhongNgu[diem] := diem * 5;
end;
diemtam := 0;
diemMax := 0;
luudong := 0;
luucot := 0;
for dong := 1 to SoDong do
begin
for cot := 1 to SoCot do
begin
if MangOco[dong, cot] = Trong then
begin
diemTC := KiemTraDocTC(dong, cot, May) +
KiemTraNgangTC(dong, cot, May) +
KiemTraCheoXuoiTC(dong, cot, May) +
KiemTraCheoNguocTC(dong, cot, May);

diemPN := KiemTraDocPN(dong, cot, May) +
KiemTraNgangPN(dong, cot, May) +
KiemTraCheoXuoiPN(dong, cot, May) +
KiemTraCheoNguocPN(dong, cot, May);

if (diemTC > diemPN) then
diemtam := diemTC
else
diemtam := diemPN;
if (diemMax <= diemtam) then
begin
diemMax := diemtam;
donght := dong;
cotht := cot;
Luucot := (cot - 1) * KichThuoc + KhoangCachCot;
Luudong := (dong - 1) * KichThuoc + KhoangCachHang;
end;
end;
end;
end;
bc.VeQuanCo(luucot,luudong);

end;
end;
{=============E AI==================================}


BEGIN
Gd := VGA;
Gm := VgaHi;
InitGraph(Gd,Gm,'');
InitMouse;
SanSang := False;
with bc do
begin
VeBanCo;
ShowMouse;
Repeat
if (MouseArea(KhoangCachCot,KhoangCachHang,
KhoangCachCot+SoCot*KichThuoc,KhoangCachHang+SoDong*KichThuoc)
and SanSang) then
begin
VeQuanCo(mousex, mousey);
ttnt.DanhCo;
end
else
if (MouseArea(10+15,KhoangCachHang + 300,KhoangCachCot-20-15,
KhoangCachHang+KichThuoc*SoCot - 90)) then
begin
VeBanCo;
VequanCo(KichThuoc*Socot div 2 + KhoangCachCot,
KichThuoc * Sodong div 2 + KhoangCachHang);
SanSang := true;
end;
Until MouseArea(10+15,KhoangCachHang + 400,KhoangCachCot-20-15,
KhoangCachHang+KichThuoc*SoCot - 20);
end;
CloseGraph;
ENd.
làm sao để nhập cái này vào pascal hả bạn .......mình thử bằng mấy cách chuyển code mà ko dc
 

trà nguyễn hữu nghĩa

Cựu Mod Vật Lí |Cây bút Thơ|Thần tượng VH
Thành viên
14 Tháng năm 2017
3,974
7,623
744
22
Phú Yên
Trường THPT Lương Văn Chánh
làm sao để nhập cái này vào pascal hả bạn .......mình thử bằng mấy cách chuyển code mà ko dc
Bạn thử làm cách này xem sao:
- Tạo một thư mục rỗng trong Turbo Pascal với tên GameCaro rồi tắt Turbo Pascal đi.
- Bạn vào thư mục BIN của Pascal mở file GameCaro lên bằng NotePad (phải là NotPad)
- Copy đoạn code trên vào notePad và Lưu lại.
- Mở Turbo Pascal lên và chạy chương trình.
 

Blue Plus

Cựu TMod Toán|Quán quân WC18
Thành viên
TV ấn tượng nhất 2017
7 Tháng tám 2017
4,506
10,437
1,114
Khánh Hòa
$\color{Blue}{\text{Bỏ học}}$
Đây là Code Game, chúng ta chơi với máy. Bạn nào có ý kiến gì để bổ sung cho Game của mình thì bình luận ở dưới nha.


program Game_Co_Caro;
uses crt,dos,graph;
const
KichThuoc = 30;
KhoangCachCot = 170;
KhoangCachHang = 15;
SoDong = 15;
SoCot = 15;

Trong = 0;
NguoiChoi = 1;
May = 2;

type
Banco = object
Procedure VeBanCo;
Procedure VeBangThongTin;
Procedure KhoiTaoMangOco;
Procedure VeQuanCo(X, Y :integer);
end;
ThangThua = object
Function KiemTraDoc(donght, cotht, giatri : integer) : Boolean;
Function KiemTraNgang(donght, cotht, giatri : integer) : Boolean;
Function KiemTraCheoXuoi(donght, cotht, giatri : integer) : Boolean;
Function KiemTraCheoNguoc(donght, cotht, giatri : integer) : Boolean;
Function KiemTraThang(donght, cotht, giatri : integer) : Boolean;
Procedure XuLiThangThua;
end;
AI = object
MangDiemTanCong : array[0..10] of longint;
MangDiemPhongNgu : array[0..10] of longint;

Function KiemTraDocTC(donght, cotht, giatri : integer) : integer;
Function KiemTraNgangTC(donght, cotht, giatri : integer) : integer;
Function KiemTraCheoXuoiTC(donght, cotht, giatri : integer) : integer;
Function KiemTraCheoNguocTC(donght, cotht, giatri : integer) : integer;
Function KiemTraDocPN(donght, cotht, giatri : integer) : integer;
Function KiemTraNgangPN(donght, cotht, giatri : integer) : integer;
Function KiemTraCheoXuoiPN(donght, cotht, giatri : integer) : integer;
Function KiemTraCheoNguocPN(donght, cotht, giatri : integer) : integer;
Procedure DanhCo;
end;

var
Gd,Gm : integer;
MangOco : array[1..SoDong,1..SoCot] of integer;
VitriX : array[1..SoCot * SoDong] of integer;
LuuCot : array[0..800] of integer;
LuuDong: array[0..800] of integer;
VitriY : array[1..SoDong * Sodong] of integer;
SanSang : Boolean;
LuotDi: integer;
bc : BanCo;
tt: ThangThua;
ttnt : AI;

{===========S Su Kien==================}

function mousex:word;assembler;asm
mov ax,3; int 33h; mov ax,cx end;

function mousey:word;assembler;asm
mov ax,3; int 33h; mov ax,dx end;

function leftclick:boolean;assembler;asm
mov ax,3; int 33h; and bx,1; mov ax,bx end;

function MouseArea(x1,y1,x2,y2:word):boolean;
begin
if (LeftClick)
and (mousex >=x1)
and (mousex <=x2)
and (mousey >=y1)
and (mousey <=y2)
then mousearea:=true
else mousearea:=false;
end;

Function InitMouse : boolean;
var r: registers;
Begin
r.ax:=$00;intr($33,r);
if r.ax<>0 then InitMouse:=true
else InitMouse:=false;
End;

Procedure ShowMouse;
Var r: registers;
begin
r.ax:=$01;intr($33,r);
End;

Procedure HideMouse;
Var r:registers;
Begin
r.ax:=$002;
intr($33,r);
End;

{=============E Su Kien=======================}

{============S Ban Co===========}

Procedure BanCo.VeBangThongTin;
begin
SetColor(Blue);
SetFillStyle(1,Blue);
Bar(10,KhoangCachHang,KhoangCachCot-20,
KhoangCachHang+KichThuoc*SoCot); { Ve Bang Chinh}

SetColor(Black);
SetFillStyle(3,Red);
Bar(25,KhoangCachHang + 400,KhoangCachCot-35,
KhoangCachHang+KichThuoc*SoCot - 20);
SetColor(Yellow);
SetTextStyle(0, horizDir,2);
OutTextXy(50,KhoangCachHang + 408,'EXIT');{ Ve Nut EXIT}

SetColor(Green);
SetFillStyle(1,Yellow);
Bar(25,KhoangCachHang + 300,KhoangCachCot-35,
KhoangCachHang+KichThuoc*SoCot - 90);
SetColor(Black);
SetTextStyle(0, horizDir,2);
OutTextXy(50,KhoangCachHang + 308,'New');
OutTextXy(50,KhoangCachHang + 332,'Game');{ Ve Nut New Game}

SetTextStyle(0,horizDir,4);
Setcolor(LightGreen);
OutTextXy(10+10,KhoangCachHang + 40,'Game');
SetColor(LightRed);
SetFillStyle(1,Cyan);
OutTextXy(25,KhoangcachHang + 100,'Caro');{ Ghi chu 'Game Caro'}

Bar(25,KhoangCachHang + 170,KhoangCachCot-35,
KhoangCachHang+270);
SetFillStyle(1,Black);
SetColor(Black);
FillEllipse(54,KhoangCachHang + 195,20,20);
FillEllipse(104,KhoangCachHang + 245,20,20);
SetColor(white);
SetFillStyle(1,white);
FillEllipse(104,KhoangCachHang + 195,20,20);
FillEllipse(54,KhoangCachHang + 245,20,20);
SetColor(Yellow);
Line(79,KhoangCachHang + 170,
79,KhoangCachHang+270);
Line(25,KhoangCachHang + 219,KhoangCachCot-35,
KhoangCachHang + 219);
RecTangle(24,KhoangCachHang + 169,KhoangCachCot-34,
KhoangCachHang+271);
SetColor(Black);{ Ve Hinh Ban Co CaRo }

end;

Procedure BanCo.KhoiTaoMangOCo;
var dong, cot : integer;
begin
for dong := 1 to SoDong do
for cot := 1 to SoCot do
begin
MangOco[dong, cot] := 0;
end;
end;

Procedure BanCo.VeQuanCo(X, Y: integer);
var vtX, vtY, kt, donght, cotht : integer;
tam : string;
begin
HideMouse;
vtX := KhoangCachCot + (X - KhoangCachCot) div KichThuoc * KichThuoc
+ KichThuoc div 2;
vtY := KhoangCachHang + (Y - KhoangCachHang) div KichThuoc * KichThuoc
+ KichThuoc div 2;
kt := KichThuoc div 2 - 4;
donght := (Y - KhoangCachHang) div KichThuoc + 1;
cotht := (X - KhoangCachCot) div KichThuoc + 1;
if (MangOco[donght, cotht] = Trong) then
begin
if LuotDi = NguoiChoi then
SetFillStyle(1,White)
else if LuotDi = May then
SetFillStyle(1,Blue)
else if LuotDi = Trong then
SetFillStyle(1,Black);
FillEllipse(vtX, vtY, kt, kt);
MangOco[donght, cotht] := LuotDi;
with tt do
begin
if (KiemTrathang(donght, cotht, MangOco[donght,cotht]))
then
XuLiThangThua;
end;
if Luotdi = Nguoichoi then
begin LuotDi := May;
end
else begin
LuotDi := NguoiChoi;
end;
end;
ShowMouse;
end;
Procedure BanCo.VeBanCo;
var dong,cot : integer;
begin
HideMouse;
ClearDevice;
SetColor(Green);
Luotdi := May;
for dong:=0 to SoDong do
begin
Line(KhoangCachCot,KhoangCachHang+dong*KichThuoc,
KhoangCachCot+SoDong*KichThuoc,KhoangCachHang+dong*KichThuoc);
end;
for cot:=0 to SoCot do
begin
Line(KhoangCachCot+cot*KichThuoc,KhoangCachHang,
KhoangCachCot+cot*KichThuoc,KhoangCachHang+KichThuoc*SoCot);
end;
VeBangThongTin;
KhoiTaoMangOco;
ShowMouse;
end;

{============E Ban Co===========}

{=============S Thang Thua==========================}
Function ThangThua.KiemTraDoc(donght, cotht, giatri : integer) : Boolean;
var dong,kt,soquandich: integer;
begin
kt := 0;
soquandich := 0;
for dong:= donght - 1 downto 1 do
if (MangOco[dong, cotht] = giatri) then
kt:=kt+1
else if (MangOco[dong, cotht] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;
for dong:= donght to SoDong do
if (MangOco[dong, cotht] = giatri) then
kt:=kt+1
else if (MangOco[dong, cotht] = trong) then
break
else
begin
soquandich := soquandich+1;
break;

end;

if (SoquanDich >= 2) then
KiemTraDoc := False
else if (kt >= 5) then
KiemTraDoc := True
else if (kt < 5) then
KiemTraDoc := False;

end;

Function ThangThua.KiemTraNgang(donght, cotht, giatri : integer) : Boolean;
var cot,kt,soquandich: integer;
begin
kt := 0;
soquandich := 0;
for cot:= cotht - 1 downto 1 do
if (MangOco[donght, cot] = giatri) then
kt:=kt+1
else if (MangOco[donght, cot] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;
for cot:= cotht to SoCot do
if (MangOco[donght, cot] = giatri) then
kt:=kt+1
else if (MangOco[donght, cot] = trong) then
break
else
begin
soquandich := soquandich+1;
break;

end;

if (SoquanDich >= 2) then
KiemTraNgang := False
else if (kt >= 5) then
KiemTraNgang := True
else if (kt < 5) then
KiemTraNgang := False;
end;

Function ThangThua.KiemTraCheoXuoi(donght, cotht, giatri : integer) : Boolean;
var thaythe,kt,soquandich,gt,gtm: integer;
begin
kt := 0;
soquandich := 0;
if (donght < cotht) then
gt := donght
else
gt := cotht;
for thaythe:= 1 to gt-1 do
if (MangOco[donght - thaythe, cotht - thaythe] = giatri) then
kt:=kt+1
else if (MangOco[donght - thaythe, cotht - thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;
if (donght > cotht) then
begin
gt := donght;
gtm := SoDong;
end
else
begin
gt := cotht;
gtm := SoCot;
end;
for thaythe := 0 to gtm-gt do
if (MangOco[donght + thaythe, cotht + thaythe] = giatri) then
kt:=kt+1
else if (MangOco[donght + thaythe, cotht + thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
break;

end;

if (SoquanDich >= 2) then
KiemTraCheoXuoi := False
else if (kt >= 5) then
KiemTraCheoXuoi := True
else if (kt < 5) then
KiemTraCheoXuoi := False;

end;

Function ThangThua.KiemTraCheoNguoc(donght, cotht, giatri : integer) : Boolean;
var thaythe,kt,soquandich,gt: integer;
begin
kt := 0;
soquandich := 0;
if (donght < SoCot-cotht+1) then
gt := donght
else
gt := SoCot-cotht+1;
for thaythe:= 1 to gt-1 do
if (MangOco[donght - thaythe, cotht + thaythe] = giatri) then
kt:=kt+1
else if (MangOco[donght - thaythe, cotht + thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;

if (SoDong-donght+1 < cotht) then
begin
gt := SoDong-donght+1;
end
else
begin
gt := cotht;
end;
for thaythe := 0 to gt-1 do
if (MangOco[donght + thaythe, cotht - thaythe] = giatri) then
kt:=kt+1
else if (MangOco[donght + thaythe, cotht - thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
break;

end;

if (SoquanDich >= 2) then
KiemTraCheoNguoc := False
else if (kt >= 5) then
KiemTraCheoNguoc := True
else if (kt < 5) then
KiemTraCheoNguoc := False;

end;

Function ThangThua.KiemTraThang(donght, cotht, giatri : integer) : Boolean;
begin
if not KiemTraDoc(donght, cotht, giatri) and
not KiemTraNgang(donght, cotht, giatri) and
not KiemTraCheoXuoi(donght, cotht, giatri) and
not KiemTraCheoNguoc(donght, cotht, giatri)
then KiemTraThang := False
else KiemTraThang := True;
end;

Procedure ThangThua.XuLiThangThua;
begin
SetColor(Red);
SetTextStyle(0,horizDir,5);
if LuotDi = Nguoichoi then
OuttextXy(200,200,'You Win')
else
OutTextXy(200,200,'You Lose');
SanSang := False;
end;
{=============E Thang Thua==========================}
{=============S AI==================================}
Function AI.KiemTraDocTC(donght, cotht, giatri : integer) : integer;
var dong: integer;
soquanta, soquandich,trave : integer;
begin
soquanta := 0;
soquandich := 0;
for dong:= donght - 1 downto 1 do
if (MangOco[dong, cotht] = giatri) then
soquanta:=soquanta+1
else if (MangOco[dong, cotht] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;
for dong:= donght+1 to SoDong do
if (MangOco[dong, cotht] = giatri) then
soquanta:=soquanta+1
else if (MangOco[dong, cotht] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;
trave := MangDiemTanCong[soquanta] - MangDiemPhongNgu[soquandich];
if trave < 0 then trave := 0;
if Soquandich = 2 then
KiemTraDocTC := 0
else
KiemTraDocTC := trave;
end;

Function AI.KiemTraNgangTC(donght, cotht, giatri : integer) : integer;
var cot: integer;
soquanta, soquandich,trave : integer;
begin
soquanta := 0;
soquandich := 0;
for cot:= cotht - 1 downto 1 do
if (MangOco[donght, cot] = giatri) then
soquanta:=soquanta+1
else if (MangOco[donght, cot] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;
for cot:= cotht+1 to SoDong do
if (MangOco[donght, cot] = giatri) then
soquanta:=soquanta+1
else if (MangOco[donght, cot] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;
trave := MangDiemTanCong[soquanta] - MangDiemPhongNgu[soquandich];
if trave < 0 then trave := 0;
if Soquandich = 2 then
KiemTraNgangTC := 0
else
KiemTraNgangTC := trave;
end;

Function AI.KiemTraCheoXuoiTC(donght, cotht, giatri : integer) : integer;
var gt, gtm, thaythe: integer;
soquanta, soquandich,trave : integer;
begin
soquanta := 0;
soquandich := 0;
if (donght < cotht) then
gt := donght
else
gt := cotht;
for thaythe:= 1 to gt-1 do
if (MangOco[donght - thaythe, cotht - thaythe] = giatri) then
soquanta:=soquanta+1
else if (MangOco[donght - thaythe, cotht - thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;
if (donght > cotht) then
begin
gt := donght;
gtm := SoDong;
end
else
begin
gt := cotht;
gtm := SoCot;
end;
for thaythe := 1 to gtm-gt do
if (MangOco[donght + thaythe, cotht + thaythe] = giatri) then
soquanta:=soquanta+1
else if (MangOco[donght + thaythe, cotht + thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;

trave := Mangdiemtancong[soquanta] - mangdiemphongngu[soquandich];
if (trave < 0) then trave := 0;

if (soquandich = 2) then
KiemTraCheoXuoiTC := 0
else
KiemTraCheoXuoiTC := trave;
end;

Function AI.KiemTraCheoNguocTC(donght, cotht, giatri : integer) : integer;
var thaythe,gt: integer;
soquanta, soquandich,trave : integer;
begin
soquanta := 0;
soquandich := 0;
if (donght < SoCot-cotht+1) then
gt := donght
else
gt := SoCot-cotht+1;
for thaythe:= 1 to gt-1 do
if (MangOco[donght - thaythe, cotht + thaythe] = giatri) then
soquanta:=soquanta+1
else if (MangOco[donght - thaythe, cotht + thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
break;
end;

if (SoDong-donght+1 < cotht) then
begin
gt := SoDong-donght+1;
end
else
begin
gt := cotht;
end;
for thaythe := 1 to gt-1 do
if (MangOco[donght + thaythe, cotht - thaythe] = giatri) then
soquanta:=soquanta+1
else if (MangOco[donght + thaythe, cotht - thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
break;

end;
trave := MangDiemTanCong[soquanta] - MangDiemPhongNgu[soquandich];
if trave < 0 then trave := 0;
if Soquandich = 2 then
KiemTraCheoNguocTC := 0
else
KiemTraCheoNguocTC := trave;
end;

Function AI.KiemTraDocPN(donght, cotht, giatri : integer) : integer;
var dong: integer;
soquanta, soquandich,trave : integer;
begin
soquanta := 0;
soquandich := 0;
for dong:= donght - 1 downto 1 do
if (MangOco[dong, cotht] = giatri) then
begin
soquanta:=soquanta+1;
break;
end
else if (MangOco[dong, cotht] = trong) then
break
else
begin
soquandich := soquandich+1;
end;

for dong:= donght+1 to SoDong do
if (MangOco[dong, cotht] = giatri) then
begin
soquanta:=soquanta+1;
break;
end
else if (MangOco[dong, cotht] = trong) then
break
else
begin
soquandich := soquandich+1;
end;
if (soquandich >= 4) and (soquanta <= 1) then
soquandich := soquandich + 2
else if (soquandich = 3) and (soquanta = 0) then
soquandich := soquandich+1;
trave := MangDiemPhongNgu[soquandich] - MangDiemTanCong[soquanta];
if trave < 0 then trave := 0;
if Soquanta = 2 then
KiemTraDocPN := 0
else
KiemTraDocPN := trave;
end;

Function AI.KiemTraNgangPN(donght, cotht, giatri : integer) : integer;
var cot: integer;
soquanta, soquandich,trave : integer;
begin
soquanta := 0;
soquandich := 0;
for cot:= cotht - 1 downto 1 do
if (MangOco[donght, cot] = giatri) then
begin
soquanta:=soquanta+1;
break;
end
else if (MangOco[donght, cot] = trong) then
break
else
begin
soquandich := soquandich+1;
end;
for cot:= cotht+1 to SoCot do
if (MangOco[donght, cot] = giatri) then
begin
soquanta:=soquanta+1;
break;
end
else if (MangOco[donght, cot] = trong) then
break
else
begin
soquandich := soquandich+1;
end;
if (soquandich >= 4) and (soquanta <= 1) then
soquandich := soquandich + 2
else if (soquandich = 3) and (soquanta = 0) then
soquandich := soquandich+1;
trave := MangDiemPhongNgu[soquandich] - MangDiemTanCong[soquanta];
if trave < 0 then trave := 0;
if Soquanta = 2 then
KiemTraNgangPN := 0
else
KiemTraNgangPN := trave;
end;

Function AI.KiemTraCheoXuoiPN(donght, cotht, giatri : integer) : integer;
var gt, gtm, thaythe: integer;
soquanta, soquandich,trave : integer;
begin
soquanta := 0;
soquandich := 0;
if (donght < cotht) then
gt := donght
else
gt := cotht;
for thaythe:= 1 to gt-1 do
if (MangOco[donght - thaythe, cotht - thaythe] = giatri) then
begin
soquanta:=soquanta+1;
break;
end
else if (MangOco[donght - thaythe, cotht - thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
end;
if (donght > cotht) then
begin
gt := donght;
gtm := SoDong;
end
else
begin
gt := cotht;
gtm := SoCot;
end;
for thaythe := 1 to gtm-gt do
if (MangOco[donght + thaythe, cotht + thaythe] = giatri) then
begin
soquanta:=soquanta+1;
break;
end
else if (MangOco[donght + thaythe, cotht + thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
end;
if (soquandich >= 4) and (soquanta <= 1) then
soquandich := soquandich + 2
else if (soquandich = 3) and (soquanta = 0) then
soquandich := soquandich+1;
trave := Mangdiemphongngu[soquandich] - MangDiemTanCong[soquanta];
if (trave < 0) then trave := 0;

if (soquanta = 2) then
KiemTraCheoXuoiPN := 0
else
KiemTraCheoXuoiPN := trave;
end;

Function AI.KiemTraCheoNguocPN(donght, cotht, giatri : integer) : integer;
var thaythe,gt: integer;
soquanta, soquandich,trave : integer;
begin
soquanta := 0;
soquandich := 0;
if (donght < SoCot-cotht+1) then
gt := donght
else
gt := SoCot-cotht+1;
for thaythe:= 1 to gt-1 do
if (MangOco[donght - thaythe, cotht + thaythe] = giatri) then
begin
soquanta:=soquanta+1;
break;
end
else if (MangOco[donght - thaythe, cotht + thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
end;

if (SoDong-donght+1 < cotht) then
begin
gt := SoDong-donght+1;
end
else
begin
gt := cotht;
end;
for thaythe := 1 to gt-1 do
if (MangOco[donght + thaythe, cotht - thaythe] = giatri) then
begin
soquanta:=soquanta+1;
break;
end
else if (MangOco[donght + thaythe, cotht - thaythe] = trong) then
break
else
begin
soquandich := soquandich+1;
end;
if (soquandich >= 4) and (soquanta <= 1) then
soquandich := soquandich + 2
else if (soquandich = 3) and (soquanta = 0) then
soquandich := soquandich+1;
trave := MangDiemPhongNgu[soquandich] - MangDiemTanCong[soquanta];
if trave < 0 then trave := 0;
if Soquanta = 2 then
KiemTraCheoNguocPN := 0
else
KiemTraCheoNguocPN := trave;
end;

Procedure AI.DanhCo;
var diem, diemTC, diemPN, diemtam,diemMax: integer;
dong, cot, luudong, luucot,donght,cotht : integer;
tam : string;
kt : integer;
begin
if SanSang then
begin
for diem := 0 to 10 do begin
MangDiemTanCong[diem] := diem * 6;
if diem <> 0 then
MangDiemPhongNgu[diem] := diem * 5 + 1
else
MangDiemPhongNgu[diem] := diem * 5;
end;
diemtam := 0;
diemMax := 0;
luudong := 0;
luucot := 0;
for dong := 1 to SoDong do
begin
for cot := 1 to SoCot do
begin
if MangOco[dong, cot] = Trong then
begin
diemTC := KiemTraDocTC(dong, cot, May) +
KiemTraNgangTC(dong, cot, May) +
KiemTraCheoXuoiTC(dong, cot, May) +
KiemTraCheoNguocTC(dong, cot, May);

diemPN := KiemTraDocPN(dong, cot, May) +
KiemTraNgangPN(dong, cot, May) +
KiemTraCheoXuoiPN(dong, cot, May) +
KiemTraCheoNguocPN(dong, cot, May);

if (diemTC > diemPN) then
diemtam := diemTC
else
diemtam := diemPN;
if (diemMax <= diemtam) then
begin
diemMax := diemtam;
donght := dong;
cotht := cot;
Luucot := (cot - 1) * KichThuoc + KhoangCachCot;
Luudong := (dong - 1) * KichThuoc + KhoangCachHang;
end;
end;
end;
end;
bc.VeQuanCo(luucot,luudong);

end;
end;
{=============E AI==================================}


BEGIN
Gd := VGA;
Gm := VgaHi;
InitGraph(Gd,Gm,'');
InitMouse;
SanSang := False;
with bc do
begin
VeBanCo;
ShowMouse;
Repeat
if (MouseArea(KhoangCachCot,KhoangCachHang,
KhoangCachCot+SoCot*KichThuoc,KhoangCachHang+SoDong*KichThuoc)
and SanSang) then
begin
VeQuanCo(mousex, mousey);
ttnt.DanhCo;
end
else
if (MouseArea(10+15,KhoangCachHang + 300,KhoangCachCot-20-15,
KhoangCachHang+KichThuoc*SoCot - 90)) then
begin
VeBanCo;
VequanCo(KichThuoc*Socot div 2 + KhoangCachCot,
KichThuoc * Sodong div 2 + KhoangCachHang);
SanSang := true;
end;
Until MouseArea(10+15,KhoangCachHang + 400,KhoangCachCot-20-15,
KhoangCachHang+KichThuoc*SoCot - 20);
end;
CloseGraph;
ENd.
Mk bị gặp mấy lỗi về intr, mk ms lp 7 k bt nhiều về pascal
Có cách nào sửa k
 
  • Like
Reactions: BhofA

trà nguyễn hữu nghĩa

Cựu Mod Vật Lí |Cây bút Thơ|Thần tượng VH
Thành viên
14 Tháng năm 2017
3,974
7,623
744
22
Phú Yên
Trường THPT Lương Văn Chánh

trà nguyễn hữu nghĩa

Cựu Mod Vật Lí |Cây bút Thơ|Thần tượng VH
Thành viên
14 Tháng năm 2017
3,974
7,623
744
22
Phú Yên
Trường THPT Lương Văn Chánh

BhofA

Học sinh chăm học
Thành viên
7 Tháng năm 2017
374
281
56
21
Nghệ An
tưởng bạn viết đc code này thì mình phục tật, mình viết code ko giỏi lắm. với lại tubo mình ko quen dùng :V
 

trà nguyễn hữu nghĩa

Cựu Mod Vật Lí |Cây bút Thơ|Thần tượng VH
Thành viên
14 Tháng năm 2017
3,974
7,623
744
22
Phú Yên
Trường THPT Lương Văn Chánh
tưởng bạn viết đc code này thì mình phục tật, mình viết code ko giỏi lắm. với lại tubo mình ko quen dùng :V
Thật sự thì cái này là do mình viết nhưng phần sự kiện chuột thì mình coppy trên mạng, còn phần trí tuệ nhân tạo thì mình dựa vào một đoạn code trên C# mà mình cũng học được từ trên youtube. Trước kia mình hay dùng TP nhưng nay mình chuyễn sang dùng C# rồi.
 

BhofA

Học sinh chăm học
Thành viên
7 Tháng năm 2017
374
281
56
21
Nghệ An
Thật sự thì cái này là do mình viết nhưng phần sự kiện chuột thì mình coppy trên mạng, còn phần trí tuệ nhân tạo thì mình dựa vào một đoạn code trên C# mà mình cũng học được từ trên youtube. Trước kia mình hay dùng TP nhưng nay mình chuyễn sang dùng C# rồi.
wow thế bạn giỏi thật, khâm phục luôn đó @@
 
Top Bottom