Lập trình trò chơi tính điểm quân đôminô trong Pascal

Chủ nhật - 09/08/2020 10:05
Cho 1 quân đôminô trên bàn và một số quân đôminô. Một người chơi một trò chơi sau đây:
- Người đó lần lượt gắn các quân đôminô vào quân đã có sẵn ban đầu.
- Người đó được gọi là thắng cuộc nếu tổng các số điểm của các quân còn lại là nhỏ nhất trong tất cả cách lắp.
- Hãy lập trình để máy chơi được trò chơi trên và luôn thắng cuộc.
■ Hướng dẫn:
- Đây là trò chơi một người, thuật toán chủ yếu là vét cạn các cách đi có thể để tổng số điểm còn lại đạt giá trị nhỏ nhất.
- Ta dùng thủ tục đệ qui Find (trai, phai: byte) để có thể quay lui khi vét cạn.
Thủ tục này thể hiện bằng PASCAL như sau:
{$M65520,0,0}
PROGRAM BAILAM3;
USES CRT;
TYPE Conco=Record
           x,y: Byte;
           co: set of byte;
           End;
VAR i,j,m,1m,1maxphai,1maxtrai,1minphai,lmintrai: Integer;
sigma,max,min: longint;
domino: array[1..100 of conco;
luutrai,luuphai,kqmaxtrai,kqmaxphai,kqmintrai,kqminphai: array[1.. 100] og byte;
          flag: set of byte;
          ch:char;
          tarn: set of byte;
          trai,phai,demtrai,demphai: Byte;
          oknhap: boolean;
PROCEDURE KEU;
BEGIN
      Sound(1305);
      Delay(300);
      Nosound;
END;
PROCEDURE FIND (trai,phai: Byte);
VAR j : integer;
         found: boolean;
BEGIN
         found : = false;
         For j : = 1 to 1m do
               If j in flag then
                  With domino[j] do
                       Begin
                            If (trai in co) then
                                Begin
                                    found : = true;
                                    sigma : = sigma-x-y;
                                    flag: = flag-[j]
                                    demtrai : = demtrai+1;
                                    luutrai[demtrai] : = j;
                                    If (trai=x) then Find(y,phai)
                                    Else Find(x,phai);
                                    demtrai: = demtrai-1;
                                    sigma: = sigma+x+y;
                                    flag: = flag+[j];
                               End;
                               If (phai in co) then
                               Begin
                                     found: = true;
                                     flag : = flag-[j];
                                     sigma: = sigma-x-y;
                                     demphai: = demphai+1;
                                     luuphai[demphai] : = j;
                                     If (phai=x) then find (trai,y);
                                     Else find(trai,x);
                                     demphai : = demphai-1;
                                     sigma : = sigma+x+y;
                                     flag : = flag+[j];
                                End;
                        End;
                  If (not found) then
                  Begin
                       If (sigma>max) then
                       begin
                            max: = sigma;
                            1maxphai : = demphai;
                            1maxtrai : = demtrai
                            kqmaxtrai : = luutrai;
                            kqmaxphai : = luuphai;
                       end;
                       If (sigmacmin) then
                       begin
                           min : = sigma;
                           1minphai : = demphai;
                           1mintrai : = demtrai;
                           kqmintrai : = luutrai
                           kqminphai : = luuphai;
                      end;
                 End;
END;
PROCEDURE XUAT;
BEGIN
      Repeat
           clrscr;
           writeln(’Menu’);
           Writeln(‘1. Xem dap so cau 2');
           Writeln('2. Xem dap so cau 3');
           Writeln('3. quit');
           Repeat
               ch : = readkey;
           Until ch in; [‘1’..’3’]
           Case ch of
               '1' : begin
                    For i : = 1mintrai down to 1 do
                   With domino[kqmintrai[i] do
                    begin
                       write(x',’,y,'->');
                    end;
                    For i : = 1 to 1minphai do
                    With domino[kqminphai[i]] do
                     begin
                         write(x,',',y,'->');
                    end;
                    Gotoxy(where-2,wherey);Writeln(' ');
                    Writeln(‘So diem con lai la',min) ;
                    readln;
               end;
               '2' : begin
                    For i: = 1maxtrai down to 1 do
                    With domino[kqmaxphai[i]] do
                    begin
                        write(x,',',y,’->');
                    end;
                    Gotoxy(where-2,wherey);Writeln(' ');
                    Writeln(‘So diem con lai la',max);
                    readln;
                    end;
               end;
          Until ch=’3';
END;
PROCEDURE DOING;
BEGIN
      clrscr;
      Writeln(Nhap vao cap i0 j0');
      Readln(trai phai);
      If (((trai-m)*(trai)>0) or ((phai-m)*(phai)>0)) then
      begin
          keu;
              Writeln(‘Nhap bay ba');
              Readin;
              exit;
       end;
       tam : = [trai,phai];
       i: = 0;
       Repeat
            i : = i + 1;
       Until (domino[i].co=tam);
       demphai : = 1;
       demtrai : = 0;
       flag : = flag-[i];
       luuphai[1]: = i;
       sigma: = sigma-domino[i].x-domino[i].y;
       Writeln(‘Wait me a few minutes long’);
       max : = 0;
      min : = 2147483647;
      Find(trai,phai);
      xuat;
      readln
END;
PROCEDURE NHAP;
VAR s : string;
         error : integer;
BEGIN
        Writeln(‘Nhap m');
        Readln(s);
       Val(s,m,error);
        If (error< >0) then
        begin
             Writeln(‘Kieu so sai.Nhap lai');
             Readin;
             exit;
         end;
         Writeln(‘Cong thuc tinh so hinh chu nhat la To hop C(m+1), 2+m+1=(m+1)*(m+2)/2');
         1m : = (m+1)*(m+2) div 2;
         Writeln(‘Va so do bang',1m);
         oknhap : = true;
         flag : = [1..1m];
         1m : = 0;
         sigma : = 0;
         For i : = 0 to m do
             For j : = i to m do
                 begin
                     1m: = lin+1;
                     sigma: = sigma+i+j;
                     domino[1m].x : = i;
                     domino[1m].y: = j;
                     domino[1m].co: = [i,j];
                 end;
          Oknhap : = true;
          readln;
END;
BEGIN
      oknhap : = false;
      Repeat
      clrscr;
      writeln(’Menu’);
      Writeln(1. Cau 1');
      Writeln('2. Can 2 & 3');
      Writeln('3. quit');
      Repeat
          ch: = readkey;
      Until ch in ['1'..'3'];
      Case ch of
           '1' : Nhap;
           '2' : If oknhap then Doing
                Else.
                keu;
           end;
      Until ch='3';
END.

  Ý kiến bạn đọc

THÀNH VIÊN

Hãy đăng nhập thành viên để trải nghiệm đầy đủ các tiện ích trên site
Kênh Bóng đá trực tiếp hôm nay miễn phí
Kênh
90Phut TV full HD ⇔ 32win
RR88 ⇔ YO88 ⇔ bk8 ⇔ 123b

Vmax ⇔ SV388 ⇔ cakhiatv ⇔ bet88
789f ⇔ Cakhia TV ⇔ rikvip ⇔ 8x bet
https://qq887p.com/ ⇔ v9bet ⇔ okvip
b52club ⇔ Kkwin ⇔  ⇔ Link MB66
https://88betcom.pro/ ⇔ 8x bet ⇔ 33win
789BET ⇔ shbet ⇔ 32 win ⇔ RR88
MB66 ⇔ Nổ Hũ ⇔ BL555 ⇔ b52 club
https://789betcom0.com/ ⇔ https://hi88.baby/
HZ88 ⇔ đá gà ⇔ luongsontv ⇔ SHBET
hi88.biz ⇔ qq88 ⇔ i9 Bet ⇔ go88
f168 ⇔ 789F ⇔ j88 ⇔ 789win ⇔ 98win
88clb ⇔ 789win ⇔ HUBET ⇔ GK88
F168 ⇔ bet88 ⇔ QQ88 ⇔ bk8 ⇔ bk8
ee88 ⇔ iwinclub ⇔ MBET ⇔ net88
KING88 ⇔ soc88 ⇔ https://j88t3.com/
https://hi88.gives/ ⇔ 23win ⇔ 8kbet
789F ⇔ hi88 ⇔ https://fun88.social/
https://qq88z.net/ ⇔ I9BET ⇔ 7Club
https://qq88.fun/ ⇔ f168 ⇔ HUBET
daga ⇔ SHBET ⇔ keo nha cai ⇔ bl-555.site
https://bshbet.com/ ⇔ https://uk88.rocks
MM88 ⇔ Au88 ⇔ 88AA ⇔ 8kbet
https://luongson117.tv/ ⇔ https://hello8880.net/
xin 88 ⇔ https://78win01.locker/ ⇔ uu88
NOHU ⇔ bj88 live ⇔ 32win ⇔ Kuwin
Bay789 ⇔ w388 ⇔ sv388 ⇔ 23win
WW88 ⇔ https://f168.com.co/
7m ⇔ kuwin ⇔ https://789club24.com/
https://33win103.com/ ⇔ https://f168.group/
https://33win102.com/ ⇔ https://789p.co.com/
https://33win100.com/ ⇔ https://hi88.tours/
https://myeat.net/ ⇔ https://hi88.report/
https://58win1.info/ ⇔ https://f168.giving/
https://new88c.co/ ⇔ https://hello880.net/
https://789club60.com/ ⇔ 789WIN
F168 ⇔ E2BET ⇔ f168 ⇔ f168
88Vv ⇔ https://789club24.com/ ⇔ hi88com
King 88 ⇔ 8xbet ⇔ Kubet ⇔ j88 ⇔ EV88
XX88 ⇔ KUBET ⇔ 99OK ⇔ RR88
88i ⇔ 33win ⇔ http://hi88.uno/
https://33win101.com/ ⇔ SHBET ⇔ Min88
hi88 ⇔ https://shbet.gg/ ⇔ SHBET
https://33winpro.me/ ⇔ https://23win.build
alo789 ⇔ hubet ⇔ UU88 ⇔ TG88
https://shbet.solar/ ⇔ https://daga.help/
https://pg88.ca/ ⇔ https://789win.voyage/
https://u888.prof/ ⇔ https://ww88i.club/
https://hi88.voyage/ ⇔ https://bk8co.net/
cakhiatv ⇔ https://23wincom.info
https://hi88o.com/ ⇔ https://f168.law/
https://88bett.vip/ ⇔ https://j88.ventures/
https://rcc.eu.com/ ⇔ https://j88com.limited/
New88 ⇔ https://j88.now/ ⇔ hi88
kubet ⇔ Okking ⇔ https://33win.software/
https://ww88star.com/ ⇔ vankhanhtv ⇔ ww88
https://88vvcom.net/ ⇔ https://okwin.technology/
bong88 ⇔ j88 ⇔ j88 ⇔ sunwin ⇔ sunwin
No hu ⇔ 888b ⇔ MM88 ⇔ go 88
kuwin ⇔ nhà cái uy tín ⇔ rwin ⇔ dt68
MM88 ⇔ Nh88 ⇔ RR88 ⇔ game sunwin
789win ⇔ https://ok365.fitness/
https://xx88.ink/ ⇔ https://79king.is/
S666 ⇔ xocdia88 ⇔ Sun Win ⇔ Vmax
tỷ lệ kèo nhà cái hôm nay ⇔ Vivu88
https://j88ss.com ⇔ https://qq88.studio/
https://mm88.blue/ ⇔ Link vào Kingfun
Hay 88 ⇔ https://rr882.net/ ⇔ King88
https://789winlem.com/ ⇔ https://cakhiatv88.net/
https://shbet.is/ ⇔ https://13win.london/
https://789win.fund/ ⇔ https://nhacaiuytinso1.net/
nohu ⇔ https://abcvip.ru.com/ ⇔ RR88
https://king88.international/ ⇔ 33win ⇔ 98WIN
https://qq88.racing/ ⇔ https://j88uk.com
https://hubest.co/ ⇔ https://ww88.engineer/
https://muranoglass-shop.cn.com/ ⇔ J88
soi kèo nhà cái ⇔ https://king88.giving/
https://bet88.ventures/ ⇔ trực tiếp bóng đá
https://king88clb.com ⇔ E2bet ⇔ KUBET
https://sh-bet.com/ ⇔ 8xbet app ⇔ King 88
https://32win.vc/ ⇔ 88bet ⇔ PG88 ⇔ PG88
EE88 ⇔ B52Club ⇔ B52 Club ⇔ HB88
HB88 ⇔ Vin777 ⇔ SV388 ⇔ QQ88 ⇔ 32win
https://vankhanhtvv.com/ ⇔ https://luck8.world/
23WIN ⇔ bubet ⇔ https://u888lm.com/
tỷ lệ kèo nhà cái ⇔ 78win ⇔ https://789win01.club/
https://32win.domains/ ⇔ https://sv388.engineering/
https://8kbetbh.com/ ⇔
Bạn đã không sử dụng Site, Bấm vào đây để duy trì trạng thái đăng nhập. Thời gian chờ: 60 giây