Novembre 2024 | Lun | Mar | Mer | Jeu | Ven | Sam | Dim |
---|
| | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | | Calendrier |
|
|
| Un petit jeu d'échec sans IA | |
| | Auteur | Message |
---|
bignono
Nombre de messages : 1127 Age : 67 Localisation : Val de Marne Date d'inscription : 13/11/2011
| Sujet: Un petit jeu d'échec sans IA Jeu 1 Aoû 2013 - 20:13 | |
| Bonjour à tous! Avant de partir en vacances, je vous ai fait un petit jeu d'échec. Pas d'intelligence artificielle dedans, donc pas de jeu contre l'ordinateur. Non, j'ai fait cela dans l'intention d'apprendre le déplacement des pièces à ma grande fille. Donc, vous allez sur mon web dav, vous télécharger la police Alpha.ttf, et vous l'installez dans les fontes de Windows. C'est une police à pas fixe avec les figures en noir et blanc des pièces du jeu d'échec. Le programme ne sait pas reconnaître l'échec et le mat, cela me parait très difficile à programmer. Peut-être que dans l'avenir, j'essayerai....qui sait? La prise en passant du pion n'est pas programmé non plus. Sinon, vous pouvez faire le petit ou le grand roque, et vous pouvez choisir les blancs ou les noirs au début. Si vous constatez un bug dans un déplacement d'une pièce, faites le moi savoir et je verrai si je peux corriger le problème. Voici le programme: - Code:
-
' Programme de jeu d'échec par J-L NAUDIN dit bignono ' Version 3 du 1er Août 2013
data 116,-4,106,-3,110,-2,119,-5,108,-6,110,-2,106,-3,116,-4 data 111,-1,111,-1,111,-1,111,-1,111,-1,111,-1,111,-1,111,-1 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 112,01,112,01,112,01,112,01,112,01,112,01,112,01,112,01 data 114,04,104,03,098,02,113,05,107,06,098,02,104,03,114,04
data 114,04,104,03,098,02,107,06,113,05,098,02,104,03,114,04 data 112,01,112,01,112,01,112,01,112,01,112,01,112,01,112,01 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 111,-1,111,-1,111,-1,111,-1,111,-1,111,-1,111,-1,111,-1 data 116,-4,106,-3,110,-2,108,-6,119,-5,110,-2,106,-3,116,-4
dim b,d,i,j,k,n,r1,r2,s,c(64),k1,k2,k3,k4,kc,k1r,k1v,k1b,k2r,k2v,k2b,ok label joue width 0,680:height 0,690:left 0,(screen_x-width(0))/2:top 0,20:s=1 if message_confirmation_yes_no("Voulez-vous les blancs?")=1 restore:n=0 else restore:for i=1 to 8:for j=1 to 8:read d:read c(k):next j:next i:n=1 end_if for i=1 to 8:for j=1 to 8 k=k+1:alpha k:left k,(j*75)-50:top k,(i*75)-50 if odd(i)=1 if even(k)=1:c(k)=2:color k,65,135,205:else:c(k)=1:color k,155,205,254:end_if else if even(k)=1:c(k)=1:color k,155,205,254:else:c(k)=2:color k,65,135,205:end_if end_if font_name k,"Chess Alpha":font_bold k:font_size k,56:read d:caption k,chr$(d):read c(k) on_click k,joue next j:next i font_name 0,"Lucida Console":font_bold 0:font_size 0,12:font_color 0,255,0,0 for i=97 to 104:print_locate left(i-40)+30,630:print chr$(i):next i for i=8 to 1 step -1:print_locate 5,((9-i)*75)-20:print i:next i end
joue: if kc=0 k1=number_click:if sgn(c(k1))<>s then return if c(k1)=0 then return kc=1:k1r=color_pixel_red(0,left(k1)+74,top(k1)+5):k1v=color_pixel_green(0,left(k1)+74,top(k1)+5):k1b=color_pixel_blue(0,left(k1)+74,top(k1)+5) 2d_pen_color 255,0,0:2d_poly_from left(k1),top(k1):2d_poly_to left(k1)+75,top(k1):2d_poly_to left(k1)+75,top(k1)+75:2d_poly_to left(k1),top(k1)+75:2d_poly_to left(k1),top(k1) return end_if k2=number_click if k2=k1 else ok=0 if c(k1)= 1 and n=0 then pion_blanc() if c(k1)=-1 and n=1 then pion_blanc2() if c(k1)= 2 then fou_blanc() if c(k1)= 3 then cava_blanc() if c(k1)= 4 then tour_blanc() if c(k1)= 5 then dame_blanc() if c(k1)= 6 then roi_blanc() if c(k1)=-1 and n=0 then pion_noir() if c(k1)= 1 and n=1 then pion_noir2() if c(k1)=-2 then fou_noir() if c(k1)=-3 then cava_noir() if c(k1)=-4 then tour_noir() if c(k1)=-5 then dame_noir() if c(k1)=-6 then roi_noir() if n=0 if k1=61 and abs(c(k1))=6 and k2=63 and c(63)=0 and c(62)=0 and abs(c(64))=4 if r1=0 caption 62,caption$(64):c(62)=c(64):caption 64,chr$(32):c(64)=0:ok=1:r1=1 end_if end_if if k1=5 and abs(c(k1))=6 and k2=7 and c(7)=0 and c(6)=0 and abs(c(8))=4 if r2=0 caption 6,caption$(8):c(6)=c(8):caption 8,chr$(32):c(8)=0:ok=1:r2=1 end_if end_if if k1=61 and abs(c(k1))=6 and k2=59 and c(58)=0 and c(59)=0 and c(60)=0 and abs(c(57))=4 if r1=0 caption 60,caption$(57):c(60)=c(57):caption 57,chr$(32):c(57)=0:ok=1:r1=1 end_if end_if if k1=5 and abs(c(k1))=6 and k2=3 and c(4)=0 and c(3)=0 and c(2)=0 and abs(c(1))=4 if r2=0 caption 4,caption$(1):c(4)=c(1):caption 1,chr$(32):c(1)=0:ok=1:r2=1 end_if end_if else if k1=60 and abs(c(k1))=6 and k2=58 and c(58)=0 and c(59)=0 and abs(c(57))=4 if r1=0 caption 59,caption$(57):c(59)=c(57):caption 57,chr$(32):c(57)=0:ok=1:r1=1 end_if end_if if k1=4 and abs(c(k1))=6 and k2=2 and c(2)=0 and c(3)=0 and abs(c(1))=4 if r2=0 caption 3,caption$(1):c(3)=c(1):caption 1,chr$(32):c(1)=0:ok=1:r2=1 end_if end_if if k1=60 and abs(c(k1))=6 and k2=62 and c(61)=0 and c(62)=0 and c(63)=0 and abs(c(64))=4 if r1=0 caption 61,caption$(64):c(61)=c(64):caption 64,chr$(32):c(64)=0:ok=1:r1=1 end_if end_if if k1=4 and abs(c(k1))=6 and k2=6 and c(5)=0 and c(6)=0 and c(7)=0 and abs(c(8))=4 if r2=0 caption 5,caption$(8):c(5)=c(8):caption 8,chr$(32):c(8)=0:ok=1:r2=1 end_if end_if end_if if ok=1 s=sgn(c(k1)):s=s*-1 caption k2,caption$(k1):c(k2)=c(k1) caption k1,chr$(32):c(k1)=0 end_if end_if kc=0:2d_pen_color k1r,k1v,k1b:2d_poly_from left(k1),top(k1):2d_poly_to left(k1)+75,top(k1) 2d_poly_to left(k1)+75,top(k1)+75:2d_poly_to left(k1),top(k1)+75:2d_poly_to left(k1),top(k1) return
sub pion_blanc() if k1>8 if k1>48 and c(k2)=0 and k2=(k1-16) and c(k1-8)=0 then ok=1:exit_sub if k2=(k1-8) and c(k2)=0 then ok=1:exit_sub if k2=(k1-9) or k2=(k1-7) and c(k2)<0 then ok=1 couleur_k2():if k2r<>k1r and k2v<>k1v and k2b<>k1b then ok=0 end_if end_sub
sub pion_noir() if k1<57 if k1<17 and c(k2)=0 and k2=(k1+16) and c(k1+8)=0 then ok=1:exit_sub if k2=(k1+8) and c(k2)=0 then ok=1:exit_sub if k2=(k1+9) or k2=(k1+7) and c(k2)>0 then ok=1 couleur_k2():if k2r<>k1r and k2v<>k1v and k2b<>k1b then ok=0 end_if end_sub
sub pion_blanc2() if k1>8 if k1>48 and c(k2)=0 and k2=(k1-16) and c(k1-8)=0 then ok=1:exit_sub if k2=(k1-8) and c(k2)=0 then ok=1:exit_sub if k2=(k1-9) or k2=(k1-7) and c(k2)>0 then ok=1 couleur_k2():if k2r<>k1r and k2v<>k1v and k2b<>k1b then ok=0 end_if end_sub
sub pion_noir2() if k1<57 if k1<17 and c(k2)=0 and k2=(k1+16) and c(k1+8)=0 then ok=1:exit_sub if k2=(k1+8) and c(k2)=0 then ok=1:exit_sub if k2=(k1+9) or k2=(k1+7) and c(k2)<0 then ok=1 couleur_k2():if k2r<>k1r and k2v<>k1v and k2b<>k1b then ok=0 end_if end_sub
sub roi_blanc() if abs(k2-k1)=1 or abs(k2-k1)=7 or abs(k2-k1)=8 or abs(k2-k1)=9 if k2=1 or k2=9 or k2=17 or k2=25 or k2=33 or k2=41 or k2=49 or k2=57 if mod(k1,8)=0 then ok=0:exit_sub end_if if k1=1 or k1=9 or k1=17 or k1=25 or k1=33 or k1=41 or k1=49 or k1=57 if mod(k2,8)=0 then ok=0:exit_sub end_if if c(k2)<1:ok=1:else:ok=0:end_if end_if end_sub
sub roi_noir() if abs(k2-k1)=1 or abs(k2-k1)=7 or abs(k2-k1)=8 or abs(k2-k1)=9 if k2=1 or k2=9 or k2=17 or k2=25 or k2=33 or k2=41 or k2=49 or k2=57 if mod(k1,8)=0 then ok=0:exit_sub end_if if k1=1 or k1=9 or k1=17 or k1=25 or k1=33 or k1=41 or k1=49 or k1=57 if mod(k2,8)=0 then ok=0:exit_sub end_if if c(k2)>-1:ok=1:else:ok=0:end_if end_if end_sub
sub dame_blanc() fou_blanc():if b=0 then tour_blanc() end_sub
sub dame_noir() fou_noir():if b=0 then tour_noir() end_sub
sub tour_blanc() dim_local bf,bg,bh b=0:bf=mod(k2-k1,8):if bf=0 then b=8 if b=0 bg=k1+(8-mod(k1,8)):if mod(k1,8)=0 then bg=k1 bh=k2+(8-mod(k2,8)):if mod(k2,8)=0 then bh=k2 if bg=bh then b=1 end_if if b=0 then exit_sub if k2<k1 then b=b*-1 for i=k1+b to k2 step b if c(i)>0 then ok=0:exit_for if c(i)=0 then ok=1 if c(i)<0 and i<>k2:ok=0:exit_for:else:ok=1:end_if next i end_sub
sub tour_noir() dim_local bf,bg,bh b=0:bf=mod(k2-k1,8):if bf=0 then b=8 if b=0 bg=k1+(8-mod(k1,8)):if mod(k1,8)=0 then bg=k1 bh=k2+(8-mod(k2,8)):if mod(k2,8)=0 then bh=k2 if bg=bh then b=1 end_if if b=0 then exit_sub if k2<k1 then b=b*-1 for i=k1+b to k2 step b if c(i)<0 then ok=0:exit_for if c(i)=0 then ok=1 if c(i)>0 and i<>k2:ok=0:exit_for:else:ok=1:end_if next i end_sub
sub fou_blanc() dim_local bf b=0:bf=mod((k2-k1),7):if bf=0 then b=7 if b=0 bf=mod((k2-k1),9):if bf=0 then b=9 end_if couleur_k2():if k2r<>k1r and k2v<>k1v and k2b<>k1b then b=0 if b=0 then exit_sub if k2<k1 then b=b*-1 for i=k1+b to k2 step b if c(i)>0 then ok=0:exit_for if c(i)=0 then ok=1 if c(i)<0 and i<>k2:ok=0:exit_for:else:ok=1:end_if next i end_sub
sub fou_noir() dim_local bf b=0:bf=mod((k2-k1),7):if bf=0 then b=7 if b=0 bf=mod((k2-k1),9):if bf=0 then b=9 end_if couleur_k2():if k2r<>k1r and k2v<>k1v and k2b<>k1b then b=0 if b=0 then exit_sub if k2<k1 then b=b*-1 for i=k1+b to k2 step b if c(i)<0 then ok=0:exit_for if c(i)=0 then ok=1 if c(i)>0 and i<>k2:ok=0:exit_for:else:ok=1:end_if next i end_sub
sub cava_blanc() couleur_k2():if k2r=k1r and k2v=k1v and k2b=k1b then exit_sub if k2=(k1-17) and c(k2)<1 then ok=1 if k2=(k1-15) and c(k2)<1 then ok=1 if k2=(k1-10) and c(k2)<1 then ok=1 if k2=(k1-06) and c(k2)<1 then ok=1 if k2=(k1+17) and c(k2)<1 then ok=1 if k2=(k1+15) and c(k2)<1 then ok=1 if k2=(k1+10) and c(k2)<1 then ok=1 if k2=(k1+06) and c(k2)<1 then ok=1 end_sub
sub cava_noir() couleur_k2():if k2r=k1r and k2v=k1v and k2b=k1b then exit_sub if k2=(k1-17) and c(k2)>-1 then ok=1 if k2=(k1-15) and c(k2)>-1 then ok=1 if k2=(k1-10) and c(k2)>-1 then ok=1 if k2=(k1-06) and c(k2)>-1 then ok=1 if k2=(k1+17) and c(k2)>-1 then ok=1 if k2=(k1+15) and c(k2)>-1 then ok=1 if k2=(k1+10) and c(k2)>-1 then ok=1 if k2=(k1+06) and c(k2)>-1 then ok=1 end_sub
sub couleur_k2() k2r=color_pixel_red(0,left(k2)+74,top(k2)+5) k2v=color_pixel_green(0,left(k2)+74,top(k2)+5) k2b=color_pixel_blue(0,left(k2)+74,top(k2)+5) end_sub
Attention aux migraines par ce temps là! A+ | |
| | | bignono
Nombre de messages : 1127 Age : 67 Localisation : Val de Marne Date d'inscription : 13/11/2011
| Sujet: Re: Un petit jeu d'échec sans IA Ven 2 Aoû 2013 - 7:46 | |
| Bonjour à tous J'avais oublié de programmer la promotion du pion lorsqu'il arrive à l'autre bout de l'échiquier. C'est chose faite maintenant avec 4 petites lignes supplémentaires. Je vous redonne le code corrigé et n'oubliez pas qu'il fonctionnera que si vous téléchargez sur mon web dav la police Alpha.ttf à installer dans Windows. Autrement vous aurez un affichage bizarre. Essayez de changer ligne 37 font_name k,"Chess Alpha" par une autre police! - Code:
-
' Programme de jeu d'échec par J-L NAUDIN dit bignono ' Version 3 du 1er Août 2013
data 116,-4,106,-3,110,-2,119,-5,108,-6,110,-2,106,-3,116,-4 data 111,-1,111,-1,111,-1,111,-1,111,-1,111,-1,111,-1,111,-1 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 112,01,112,01,112,01,112,01,112,01,112,01,112,01,112,01 data 114,04,104,03,098,02,113,05,107,06,098,02,104,03,114,04
data 114,04,104,03,098,02,107,06,113,05,098,02,104,03,114,04 data 112,01,112,01,112,01,112,01,112,01,112,01,112,01,112,01 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 111,-1,111,-1,111,-1,111,-1,111,-1,111,-1,111,-1,111,-1 data 116,-4,106,-3,110,-2,108,-6,119,-5,110,-2,106,-3,116,-4
dim b,d,i,j,k,n,r1,r2,s,c(64),k1,k2,k3,k4,kc,k1r,k1v,k1b,k2r,k2v,k2b,ok label joue width 0,680:height 0,690:left 0,(screen_x-width(0))/2:top 0,20:s=1 if message_confirmation_yes_no("Voulez-vous les blancs?")=1 restore:n=0 else restore:for i=1 to 8:for j=1 to 8:read d:read c(k):next j:next i:n=1 end_if for i=1 to 8:for j=1 to 8 k=k+1:alpha k:left k,(j*75)-50:top k,(i*75)-50 if odd(i)=1 if even(k)=1:c(k)=2:color k,65,135,205:else:c(k)=1:color k,155,205,254:end_if else if even(k)=1:c(k)=1:color k,155,205,254:else:c(k)=2:color k,65,135,205:end_if end_if font_name k,"Chess Alpha":font_bold k:font_size k,56:read d:caption k,chr$(d):read c(k) on_click k,joue next j:next i font_name 0,"Lucida Console":font_bold 0:font_size 0,12:font_color 0,255,0,0 for i=97 to 104:print_locate left(i-40)+30,630:print chr$(i):next i for i=8 to 1 step -1:print_locate 5,((9-i)*75)-20:print i:next i end
joue: if kc=0 k1=number_click:if sgn(c(k1))<>s then return if c(k1)=0 then return kc=1:k1r=color_pixel_red(0,left(k1)+74,top(k1)+5):k1v=color_pixel_green(0,left(k1)+74,top(k1)+5):k1b=color_pixel_blue(0,left(k1)+74,top(k1)+5) 2d_pen_color 255,0,0:2d_poly_from left(k1),top(k1):2d_poly_to left(k1)+75,top(k1):2d_poly_to left(k1)+75,top(k1)+75:2d_poly_to left(k1),top(k1)+75:2d_poly_to left(k1),top(k1) return end_if k2=number_click if k2=k1 else ok=0 if c(k1)= 1 and n=0 then pion_blanc() if c(k1)=-1 and n=1 then pion_blanc2() if c(k1)= 2 then fou_blanc() if c(k1)= 3 then cava_blanc() if c(k1)= 4 then tour_blanc() if c(k1)= 5 then dame_blanc() if c(k1)= 6 then roi_blanc() if c(k1)=-1 and n=0 then pion_noir() if c(k1)= 1 and n=1 then pion_noir2() if c(k1)=-2 then fou_noir() if c(k1)=-3 then cava_noir() if c(k1)=-4 then tour_noir() if c(k1)=-5 then dame_noir() if c(k1)=-6 then roi_noir() if n=0 if k1=61 and abs(c(k1))=6 and k2=63 and c(63)=0 and c(62)=0 and abs(c(64))=4 if r1=0 caption 62,caption$(64):c(62)=c(64):caption 64,chr$(32):c(64)=0:ok=1:r1=1 end_if end_if if k1=5 and abs(c(k1))=6 and k2=7 and c(7)=0 and c(6)=0 and abs(c(8))=4 if r2=0 caption 6,caption$(8):c(6)=c(8):caption 8,chr$(32):c(8)=0:ok=1:r2=1 end_if end_if if k1=61 and abs(c(k1))=6 and k2=59 and c(58)=0 and c(59)=0 and c(60)=0 and abs(c(57))=4 if r1=0 caption 60,caption$(57):c(60)=c(57):caption 57,chr$(32):c(57)=0:ok=1:r1=1 end_if end_if if k1=5 and abs(c(k1))=6 and k2=3 and c(4)=0 and c(3)=0 and c(2)=0 and abs(c(1))=4 if r2=0 caption 4,caption$(1):c(4)=c(1):caption 1,chr$(32):c(1)=0:ok=1:r2=1 end_if end_if else if k1=60 and abs(c(k1))=6 and k2=58 and c(58)=0 and c(59)=0 and abs(c(57))=4 if r1=0 caption 59,caption$(57):c(59)=c(57):caption 57,chr$(32):c(57)=0:ok=1:r1=1 end_if end_if if k1=4 and abs(c(k1))=6 and k2=2 and c(2)=0 and c(3)=0 and abs(c(1))=4 if r2=0 caption 3,caption$(1):c(3)=c(1):caption 1,chr$(32):c(1)=0:ok=1:r2=1 end_if end_if if k1=60 and abs(c(k1))=6 and k2=62 and c(61)=0 and c(62)=0 and c(63)=0 and abs(c(64))=4 if r1=0 caption 61,caption$(64):c(61)=c(64):caption 64,chr$(32):c(64)=0:ok=1:r1=1 end_if end_if if k1=4 and abs(c(k1))=6 and k2=6 and c(5)=0 and c(6)=0 and c(7)=0 and abs(c(8))=4 if r2=0 caption 5,caption$(8):c(5)=c(8):caption 8,chr$(32):c(8)=0:ok=1:r2=1 end_if end_if end_if if ok=1 s=sgn(c(k1)):s=s*-1 caption k2,caption$(k1):c(k2)=c(k1) caption k1,chr$(32):c(k1)=0 if c(k2)=1 and k2<9 and n=0 then caption k2,chr$(113):c(k2)=5 if c(k2)=-1 and k2>56 and n=0 then caption k2,chr$(119):c(k2)=-5 if c(k2)=1 and k2>56 and n=1 then caption k2,chr$(113):c(k2)=5 if c(k2)=-1 and k2<9 and n=1 then caption k2,chr$(119):c(k2)=-5 end_if end_if kc=0:2d_pen_color k1r,k1v,k1b:2d_poly_from left(k1),top(k1):2d_poly_to left(k1)+75,top(k1) 2d_poly_to left(k1)+75,top(k1)+75:2d_poly_to left(k1),top(k1)+75:2d_poly_to left(k1),top(k1) return
sub pion_blanc() if k1>8 if k1>48 and c(k2)=0 and k2=(k1-16) and c(k1-8)=0 then ok=1:exit_sub if k2=(k1-8) and c(k2)=0 then ok=1:exit_sub if k2=(k1-9) or k2=(k1-7) and c(k2)<0 then ok=1 couleur_k2():if k2r<>k1r and k2v<>k1v and k2b<>k1b then ok=0 end_if end_sub
sub pion_noir() if k1<57 if k1<17 and c(k2)=0 and k2=(k1+16) and c(k1+8)=0 then ok=1:exit_sub if k2=(k1+8) and c(k2)=0 then ok=1:exit_sub if k2=(k1+9) or k2=(k1+7) and c(k2)>0 then ok=1 couleur_k2():if k2r<>k1r and k2v<>k1v and k2b<>k1b then ok=0 end_if end_sub
sub pion_blanc2() if k1>8 if k1>48 and c(k2)=0 and k2=(k1-16) and c(k1-8)=0 then ok=1:exit_sub if k2=(k1-8) and c(k2)=0 then ok=1:exit_sub if k2=(k1-9) or k2=(k1-7) and c(k2)>0 then ok=1 couleur_k2():if k2r<>k1r and k2v<>k1v and k2b<>k1b then ok=0 end_if end_sub
sub pion_noir2() if k1<57 if k1<17 and c(k2)=0 and k2=(k1+16) and c(k1+8)=0 then ok=1:exit_sub if k2=(k1+8) and c(k2)=0 then ok=1:exit_sub if k2=(k1+9) or k2=(k1+7) and c(k2)<0 then ok=1 couleur_k2():if k2r<>k1r and k2v<>k1v and k2b<>k1b then ok=0 end_if end_sub
sub roi_blanc() if abs(k2-k1)=1 or abs(k2-k1)=7 or abs(k2-k1)=8 or abs(k2-k1)=9 if k2=1 or k2=9 or k2=17 or k2=25 or k2=33 or k2=41 or k2=49 or k2=57 if mod(k1,8)=0 then ok=0:exit_sub end_if if k1=1 or k1=9 or k1=17 or k1=25 or k1=33 or k1=41 or k1=49 or k1=57 if mod(k2,8)=0 then ok=0:exit_sub end_if if c(k2)<1:ok=1:else:ok=0:end_if end_if end_sub
sub roi_noir() if abs(k2-k1)=1 or abs(k2-k1)=7 or abs(k2-k1)=8 or abs(k2-k1)=9 if k2=1 or k2=9 or k2=17 or k2=25 or k2=33 or k2=41 or k2=49 or k2=57 if mod(k1,8)=0 then ok=0:exit_sub end_if if k1=1 or k1=9 or k1=17 or k1=25 or k1=33 or k1=41 or k1=49 or k1=57 if mod(k2,8)=0 then ok=0:exit_sub end_if if c(k2)>-1:ok=1:else:ok=0:end_if end_if end_sub
sub dame_blanc() fou_blanc():if b=0 then tour_blanc() end_sub
sub dame_noir() fou_noir():if b=0 then tour_noir() end_sub
sub tour_blanc() dim_local bf,bg,bh b=0:bf=mod(k2-k1,8):if bf=0 then b=8 if b=0 bg=k1+(8-mod(k1,8)):if mod(k1,8)=0 then bg=k1 bh=k2+(8-mod(k2,8)):if mod(k2,8)=0 then bh=k2 if bg=bh then b=1 end_if if b=0 then exit_sub if k2<k1 then b=b*-1 for i=k1+b to k2 step b if c(i)>0 then ok=0:exit_for if c(i)=0 then ok=1 if c(i)<0 and i<>k2:ok=0:exit_for:else:ok=1:end_if next i end_sub
sub tour_noir() dim_local bf,bg,bh b=0:bf=mod(k2-k1,8):if bf=0 then b=8 if b=0 bg=k1+(8-mod(k1,8)):if mod(k1,8)=0 then bg=k1 bh=k2+(8-mod(k2,8)):if mod(k2,8)=0 then bh=k2 if bg=bh then b=1 end_if if b=0 then exit_sub if k2<k1 then b=b*-1 for i=k1+b to k2 step b if c(i)<0 then ok=0:exit_for if c(i)=0 then ok=1 if c(i)>0 and i<>k2:ok=0:exit_for:else:ok=1:end_if next i end_sub
sub fou_blanc() dim_local bf b=0:bf=mod((k2-k1),7):if bf=0 then b=7 if b=0 bf=mod((k2-k1),9):if bf=0 then b=9 end_if couleur_k2():if k2r<>k1r and k2v<>k1v and k2b<>k1b then b=0 if b=0 then exit_sub if k2<k1 then b=b*-1 for i=k1+b to k2 step b if c(i)>0 then ok=0:exit_for if c(i)=0 then ok=1 if c(i)<0 and i<>k2:ok=0:exit_for:else:ok=1:end_if next i end_sub
sub fou_noir() dim_local bf b=0:bf=mod((k2-k1),7):if bf=0 then b=7 if b=0 bf=mod((k2-k1),9):if bf=0 then b=9 end_if couleur_k2():if k2r<>k1r and k2v<>k1v and k2b<>k1b then b=0 if b=0 then exit_sub if k2<k1 then b=b*-1 for i=k1+b to k2 step b if c(i)<0 then ok=0:exit_for if c(i)=0 then ok=1 if c(i)>0 and i<>k2:ok=0:exit_for:else:ok=1:end_if next i end_sub
sub cava_blanc() couleur_k2():if k2r=k1r and k2v=k1v and k2b=k1b then exit_sub if k2=(k1-17) and c(k2)<1 then ok=1 if k2=(k1-15) and c(k2)<1 then ok=1 if k2=(k1-10) and c(k2)<1 then ok=1 if k2=(k1-06) and c(k2)<1 then ok=1 if k2=(k1+17) and c(k2)<1 then ok=1 if k2=(k1+15) and c(k2)<1 then ok=1 if k2=(k1+10) and c(k2)<1 then ok=1 if k2=(k1+06) and c(k2)<1 then ok=1 end_sub
sub cava_noir() couleur_k2():if k2r=k1r and k2v=k1v and k2b=k1b then exit_sub if k2=(k1-17) and c(k2)>-1 then ok=1 if k2=(k1-15) and c(k2)>-1 then ok=1 if k2=(k1-10) and c(k2)>-1 then ok=1 if k2=(k1-06) and c(k2)>-1 then ok=1 if k2=(k1+17) and c(k2)>-1 then ok=1 if k2=(k1+15) and c(k2)>-1 then ok=1 if k2=(k1+10) and c(k2)>-1 then ok=1 if k2=(k1+06) and c(k2)>-1 then ok=1 end_sub
sub couleur_k2() k2r=color_pixel_red(0,left(k2)+74,top(k2)+5) k2v=color_pixel_green(0,left(k2)+74,top(k2)+5) k2b=color_pixel_blue(0,left(k2)+74,top(k2)+5) end_sub
Bon, je vais commencer à préparer mes valises aujourd'hui, A+ | |
| | | papydall
Nombre de messages : 7017 Age : 74 Localisation : Moknine (Tunisie) Entre la chaise et le clavier Date d'inscription : 03/03/2012
| Sujet: Re: Un petit jeu d'échec sans IA Ven 2 Aoû 2013 - 12:30 | |
| Bonjour Bignono Je te souhaite de passer d’excellentes vacances avec ta famille.
Moi-même, je fête des heureux événements avec ma famille élargie. Je m’occuperais de ton programme plus tard pour voir comment faire. J’avais réfléchis dans le passé à programmer un jeu d’échecs, mais je n’ai jamais allé jusqu’au bout.
A+ | |
| | | bignono
Nombre de messages : 1127 Age : 67 Localisation : Val de Marne Date d'inscription : 13/11/2011
| Sujet: Re: Un petit jeu d'échec sans IA Ven 2 Aoû 2013 - 14:33 | |
| Merci Papydall Mais comme mon code ne me satisfaisait pas pleinement au sujet de la promotion du pion en Dame automatiquement dans mon précédent post et qu'il peut survenir des cas où le roi adverse se retrouve pat suite à cela, j'ai encore modifié mon code en donnant le choix de la pièce pour privilégié la sous promotion du pion. Donc quand le pion arrivera à Dame, on aura le choix entre le fou, le cavalier, la tour ou la dame! Voici le code modifié: - Code:
-
' Programme de jeu d'échec par J-L NAUDIN dit bignono ' Version 4 du 2 Août 2013
data 116,-4,106,-3,110,-2,119,-5,108,-6,110,-2,106,-3,116,-4 data 111,-1,111,-1,111,-1,111,-1,111,-1,111,-1,111,-1,111,-1 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 112,01,112,01,112,01,112,01,112,01,112,01,112,01,112,01 data 114,04,104,03,098,02,113,05,107,06,098,02,104,03,114,04
data 114,04,104,03,098,02,107,06,113,05,098,02,104,03,114,04 data 112,01,112,01,112,01,112,01,112,01,112,01,112,01,112,01 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 032,00,032,00,032,00,032,00,032,00,032,00,032,00,032,00 data 111,-1,111,-1,111,-1,111,-1,111,-1,111,-1,111,-1,111,-1 data 116,-4,106,-3,110,-2,108,-6,119,-5,110,-2,106,-3,116,-4
dim b,d,i,j,k,n,r1,r2,s,c(64),k1,k2,kc,k1r,k1v,k1b,k2r,k2v,k2b,ok,m,q,pr$,p$ label joue width 0,680:height 0,690:left 0,(screen_x-width(0))/2:top 0,20:s=1 if message_confirmation_yes_no("Voulez-vous les blancs?")=1 restore:n=0 else restore:for i=1 to 8:for j=1 to 8:read d:read c(k):next j:next i:n=1 end_if for i=1 to 8:for j=1 to 8 k=k+1:alpha k:left k,(j*75)-50:top k,(i*75)-50 if odd(i)=1 if even(k)=1:c(k)=2:color k,65,135,205:else:c(k)=1:color k,155,205,254:end_if else if even(k)=1:c(k)=1:color k,155,205,254:else:c(k)=2:color k,65,135,205:end_if end_if font_name k,"Chess Alpha":font_bold k:font_size k,56:read d:caption k,chr$(d):read c(k) on_click k,joue next j:next i font_name 0,"Lucida Console":font_bold 0:font_size 0,12:font_color 0,255,0,0 for i=97 to 104:print_locate left(i-40)+30,630:print chr$(i):next i for i=8 to 1 step -1:print_locate 5,((9-i)*75)-20:print i:next i end
joue: if kc=0 k1=number_click:if sgn(c(k1))<>s then return if c(k1)=0 then return kc=1:k1r=color_pixel_red(0,left(k1)+74,top(k1)+5):k1v=color_pixel_green(0,left(k1)+74,top(k1)+5):k1b=color_pixel_blue(0,left(k1)+74,top(k1)+5) 2d_pen_color 255,0,0:2d_poly_from left(k1),top(k1):2d_poly_to left(k1)+75,top(k1):2d_poly_to left(k1)+75,top(k1)+75:2d_poly_to left(k1),top(k1)+75:2d_poly_to left(k1),top(k1) return end_if k2=number_click if k2=k1 else ok=0 if c(k1)= 1 and n=0 then pion_blanc() if c(k1)=-1 and n=1 then pion_blanc2() if c(k1)= 2 then fou_blanc() if c(k1)= 3 then cava_blanc() if c(k1)= 4 then tour_blanc() if c(k1)= 5 then dame_blanc() if c(k1)= 6 then roi_blanc() if c(k1)=-1 and n=0 then pion_noir() if c(k1)= 1 and n=1 then pion_noir2() if c(k1)=-2 then fou_noir() if c(k1)=-3 then cava_noir() if c(k1)=-4 then tour_noir() if c(k1)=-5 then dame_noir() if c(k1)=-6 then roi_noir() if n=0 if k1=61 and abs(c(k1))=6 and k2=63 and c(63)=0 and c(62)=0 and abs(c(64))=4 if r1=0 caption 62,caption$(64):c(62)=c(64):caption 64,chr$(32):c(64)=0:ok=1:r1=1 end_if end_if if k1=5 and abs(c(k1))=6 and k2=7 and c(7)=0 and c(6)=0 and abs(c(8))=4 if r2=0 caption 6,caption$(8):c(6)=c(8):caption 8,chr$(32):c(8)=0:ok=1:r2=1 end_if end_if if k1=61 and abs(c(k1))=6 and k2=59 and c(58)=0 and c(59)=0 and c(60)=0 and abs(c(57))=4 if r1=0 caption 60,caption$(57):c(60)=c(57):caption 57,chr$(32):c(57)=0:ok=1:r1=1 end_if end_if if k1=5 and abs(c(k1))=6 and k2=3 and c(4)=0 and c(3)=0 and c(2)=0 and abs(c(1))=4 if r2=0 caption 4,caption$(1):c(4)=c(1):caption 1,chr$(32):c(1)=0:ok=1:r2=1 end_if end_if else if k1=60 and abs(c(k1))=6 and k2=58 and c(58)=0 and c(59)=0 and abs(c(57))=4 if r1=0 caption 59,caption$(57):c(59)=c(57):caption 57,chr$(32):c(57)=0:ok=1:r1=1 end_if end_if if k1=4 and abs(c(k1))=6 and k2=2 and c(2)=0 and c(3)=0 and abs(c(1))=4 if r2=0 caption 3,caption$(1):c(3)=c(1):caption 1,chr$(32):c(1)=0:ok=1:r2=1 end_if end_if if k1=60 and abs(c(k1))=6 and k2=62 and c(61)=0 and c(62)=0 and c(63)=0 and abs(c(64))=4 if r1=0 caption 61,caption$(64):c(61)=c(64):caption 64,chr$(32):c(64)=0:ok=1:r1=1 end_if end_if if k1=4 and abs(c(k1))=6 and k2=6 and c(5)=0 and c(6)=0 and c(7)=0 and abs(c(8))=4 if r2=0 caption 5,caption$(8):c(5)=c(8):caption 8,chr$(32):c(8)=0:ok=1:r2=1 end_if end_if end_if if ok=1 s=sgn(c(k1)):s=s*-1 caption k2,caption$(k1):c(k2)=c(k1) caption k1,chr$(32):c(k1)=0 if c(k2)=1 and k2<9 and n=0 then choix():caption k2,chr$(m):c(k2)=q if c(k2)=-1 and k2>56 and n=0 then choix():caption k2,chr$(m):c(k2)=q if c(k2)=1 and k2>56 and n=1 then choix():caption k2,chr$(m):c(k2)=q if c(k2)=-1 and k2<9 and n=1 then choix():caption k2,chr$(m):c(k2)=q end_if end_if kc=0:2d_pen_color k1r,k1v,k1b:2d_poly_from left(k1),top(k1):2d_poly_to left(k1)+75,top(k1) 2d_poly_to left(k1)+75,top(k1)+75:2d_poly_to left(k1),top(k1)+75:2d_poly_to left(k1),top(k1) return
sub choix() repeat p$=message_input("Choisissez votre pièce","F = Fou, C = Cavalier, T = Tour, D = Dame",pr$) p$=message_text$:p$=upper$(p$) until p$="F" or p$="C" or p$="T" or p$="D" if c(k2)=1 if p$="F" then m=98 :q=2 if p$="C" then m=104:q=3 if p$="T" then m=114:q=4 if p$="D" then m=113:q=5 end_if if c(k2)=-1 if p$="F" then m=110:q=-2 if p$="C" then m=106:q=-3 if p$="T" then m=116:q=-4 if p$="D" then m=119:q=-5 end_if end_sub
sub pion_blanc() if k1>8 if k1>48 and c(k2)=0 and k2=(k1-16) and c(k1-8)=0 then ok=1:exit_sub if k2=(k1-8) and c(k2)=0 then ok=1:exit_sub if k2=(k1-9) or k2=(k1-7) and c(k2)<0 then ok=1 couleur_k2():if k2r<>k1r and k2v<>k1v and k2b<>k1b then ok=0 end_if end_sub
sub pion_noir() if k1<57 if k1<17 and c(k2)=0 and k2=(k1+16) and c(k1+8)=0 then ok=1:exit_sub if k2=(k1+8) and c(k2)=0 then ok=1:exit_sub if k2=(k1+9) or k2=(k1+7) and c(k2)>0 then ok=1 couleur_k2():if k2r<>k1r and k2v<>k1v and k2b<>k1b then ok=0 end_if end_sub
sub pion_blanc2() if k1>8 if k1>48 and c(k2)=0 and k2=(k1-16) and c(k1-8)=0 then ok=1:exit_sub if k2=(k1-8) and c(k2)=0 then ok=1:exit_sub if k2=(k1-9) or k2=(k1-7) and c(k2)>0 then ok=1 couleur_k2():if k2r<>k1r and k2v<>k1v and k2b<>k1b then ok=0 end_if end_sub
sub pion_noir2() if k1<57 if k1<17 and c(k2)=0 and k2=(k1+16) and c(k1+8)=0 then ok=1:exit_sub if k2=(k1+8) and c(k2)=0 then ok=1:exit_sub if k2=(k1+9) or k2=(k1+7) and c(k2)<0 then ok=1 couleur_k2():if k2r<>k1r and k2v<>k1v and k2b<>k1b then ok=0 end_if end_sub
sub roi_blanc() if abs(k2-k1)=1 or abs(k2-k1)=7 or abs(k2-k1)=8 or abs(k2-k1)=9 if k2=1 or k2=9 or k2=17 or k2=25 or k2=33 or k2=41 or k2=49 or k2=57 if mod(k1,8)=0 then ok=0:exit_sub end_if if k1=1 or k1=9 or k1=17 or k1=25 or k1=33 or k1=41 or k1=49 or k1=57 if mod(k2,8)=0 then ok=0:exit_sub end_if if c(k2)<1:ok=1:else:ok=0:end_if end_if end_sub
sub roi_noir() if abs(k2-k1)=1 or abs(k2-k1)=7 or abs(k2-k1)=8 or abs(k2-k1)=9 if k2=1 or k2=9 or k2=17 or k2=25 or k2=33 or k2=41 or k2=49 or k2=57 if mod(k1,8)=0 then ok=0:exit_sub end_if if k1=1 or k1=9 or k1=17 or k1=25 or k1=33 or k1=41 or k1=49 or k1=57 if mod(k2,8)=0 then ok=0:exit_sub end_if if c(k2)>-1:ok=1:else:ok=0:end_if end_if end_sub
sub dame_blanc() fou_blanc():if b=0 then tour_blanc() end_sub
sub dame_noir() fou_noir():if b=0 then tour_noir() end_sub
sub tour_blanc() dim_local bf,bg,bh b=0:bf=mod(k2-k1,8):if bf=0 then b=8 if b=0 bg=k1+(8-mod(k1,8)):if mod(k1,8)=0 then bg=k1 bh=k2+(8-mod(k2,8)):if mod(k2,8)=0 then bh=k2 if bg=bh then b=1 end_if if b=0 then exit_sub if k2<k1 then b=b*-1 for i=k1+b to k2 step b if c(i)>0 then ok=0:exit_for if c(i)=0 then ok=1 if c(i)<0 and i<>k2:ok=0:exit_for:else:ok=1:end_if next i end_sub
sub tour_noir() dim_local bf,bg,bh b=0:bf=mod(k2-k1,8):if bf=0 then b=8 if b=0 bg=k1+(8-mod(k1,8)):if mod(k1,8)=0 then bg=k1 bh=k2+(8-mod(k2,8)):if mod(k2,8)=0 then bh=k2 if bg=bh then b=1 end_if if b=0 then exit_sub if k2<k1 then b=b*-1 for i=k1+b to k2 step b if c(i)<0 then ok=0:exit_for if c(i)=0 then ok=1 if c(i)>0 and i<>k2:ok=0:exit_for:else:ok=1:end_if next i end_sub
sub fou_blanc() dim_local bf b=0:bf=mod((k2-k1),7):if bf=0 then b=7 if b=0 bf=mod((k2-k1),9):if bf=0 then b=9 end_if couleur_k2():if k2r<>k1r and k2v<>k1v and k2b<>k1b then b=0 if b=0 then exit_sub if k2<k1 then b=b*-1 for i=k1+b to k2 step b if c(i)>0 then ok=0:exit_for if c(i)=0 then ok=1 if c(i)<0 and i<>k2:ok=0:exit_for:else:ok=1:end_if next i end_sub
sub fou_noir() dim_local bf b=0:bf=mod((k2-k1),7):if bf=0 then b=7 if b=0 bf=mod((k2-k1),9):if bf=0 then b=9 end_if couleur_k2():if k2r<>k1r and k2v<>k1v and k2b<>k1b then b=0 if b=0 then exit_sub if k2<k1 then b=b*-1 for i=k1+b to k2 step b if c(i)<0 then ok=0:exit_for if c(i)=0 then ok=1 if c(i)>0 and i<>k2:ok=0:exit_for:else:ok=1:end_if next i end_sub
sub cava_blanc() couleur_k2():if k2r=k1r and k2v=k1v and k2b=k1b then exit_sub if k2=(k1-17) and c(k2)<1 then ok=1 if k2=(k1-15) and c(k2)<1 then ok=1 if k2=(k1-10) and c(k2)<1 then ok=1 if k2=(k1-06) and c(k2)<1 then ok=1 if k2=(k1+17) and c(k2)<1 then ok=1 if k2=(k1+15) and c(k2)<1 then ok=1 if k2=(k1+10) and c(k2)<1 then ok=1 if k2=(k1+06) and c(k2)<1 then ok=1 end_sub
sub cava_noir() couleur_k2():if k2r=k1r and k2v=k1v and k2b=k1b then exit_sub if k2=(k1-17) and c(k2)>-1 then ok=1 if k2=(k1-15) and c(k2)>-1 then ok=1 if k2=(k1-10) and c(k2)>-1 then ok=1 if k2=(k1-06) and c(k2)>-1 then ok=1 if k2=(k1+17) and c(k2)>-1 then ok=1 if k2=(k1+15) and c(k2)>-1 then ok=1 if k2=(k1+10) and c(k2)>-1 then ok=1 if k2=(k1+06) and c(k2)>-1 then ok=1 end_sub
sub couleur_k2() k2r=color_pixel_red(0,left(k2)+74,top(k2)+5) k2v=color_pixel_green(0,left(k2)+74,top(k2)+5) k2b=color_pixel_blue(0,left(k2)+74,top(k2)+5) end_sub
Bon, je pense pouvoir partir dimanche matin plus sereinement maintenant! A+ | |
| | | Jicehel
Nombre de messages : 5947 Age : 52 Localisation : 77500 Date d'inscription : 18/04/2011
| Sujet: Re: Un petit jeu d'échec sans IA Dim 4 Aoû 2013 - 11:35 | |
| Bravo Bignono et si tu arrives après à faire jouer l'ordi alors là, ce sera aussi balèze que ton tarot (qui fait toujours partie du top des jeux Panoramic à ce jour), mais bon ce serait un travail titanesque, je pense. | |
| | | Yannick
Nombre de messages : 8635 Age : 53 Localisation : Bretagne Date d'inscription : 15/02/2010
| Sujet: re Dim 4 Aoû 2013 - 17:41 | |
| De retour, je vais pouvoir tester ... | |
| | | Contenu sponsorisé
| Sujet: Re: Un petit jeu d'échec sans IA | |
| |
| | | | Un petit jeu d'échec sans IA | |
|
Sujets similaires | |
|
| Permission de ce forum: | Vous ne pouvez pas répondre aux sujets dans ce forum
| |
| |
| |