Bonjour,
Je suis en train de programmer un morpion, mais j'ai un problème pour tracer les croix. En effet, quand j'appuie par exemple sur 7, la croix en haut à gauche se dessine mais le problème c'est que toutes les autres demi-croix aussi. Voici mon programme et j'ai mis en gras ce que j'appelle demi-croix pour que vous compreniez bien (en fait ça c'est mis entre [b] mais je sais pas comment afficher le texte du code en gras...)
Code
:SauveBDG1
:Menu("MORPION","JOUER",A,"SORTIR",B
:LBL A
:1->Xmin
:95->Xmax
:1->Ymin
:63->Ymax
:AxesNAff
:FonctOff
:0->G
:EffDessin
:For(A,24,72,16
:Ligne(A,8,A,56
:1->C
:End
:EffListe L1
:9->dim(L1
:For(A,8,56,16
:Ligne(24,A,72,A
:End
:Lbl 0
:C->B
:0->[THETA]
:codeTouche->[THETA]
:If [THETA]=72 et L1(7)=0:B->L1(7)
:If [THETA]=73 et L1(8)=0:B->L1(8)
:If [THETA]=74 et L1(9)=0:B->L1(9)
:If [THETA]=82 et L1(4)=0:B->L1(4)
:If [THETA]=83 et L1(5)=0:B->L1(5)
:If [THETA]=84 et L1(6)=0:B->L1(6)
:If [THETA]=92 et L1(1)=0:B->L1(1)
:If [THETA]=93 et L1(2)=0:B->L1(2)
:If [THETA]=94 et L1(3)=0:B->L1(3)
:If [THETA][DIFFERENT DE]0:Goto 1
:Goto 0
:Lbl 1
:If L1(7)=1:Ligne(27,43,37,53):[b]Ligne(27,53,37,43[/b]
:If L1(7)=.1:Cercle(32,48,6
:If L1(8)=1:Ligne(43,43,53,53):[b]Ligne(43,53,53,43[/b]
:If L1(8)=.1:Cercle(48,48,6
:If L1(9)=1:Ligne(59,43,69,53):[b]Ligne(59,53,69,43[/b]
:If L1(9)=.1:Cercle(64,48,6
:If L1(4)=1:Ligne(27,27,37,37):[b]Ligne(27,37,37,27[/b]
:If L1(4)=.1:Cercle(32,32,6
:If L1(5)=1:Ligne(43,27,53,37):[b]Ligne(43,37,53,27[/b]
:If L1(5)=.1:Cercle(48,32,6
:If L1(6)=1:Ligne(59,27,69,37):[b]Ligne(59,37,69,27[/b]
:If L1(6)=.1:Cercle(64,32,6
:If L1(1)=1:Ligne(27,11,37,21):[b]Ligne(27,21,37,11[/b]
:If L1(1)=.1:Cercle(32,16,6
:If L1(2)=1:Ligne(43,11,53,21):[b]Ligne(43,21,53,11[/b]
:If L1(2)=.1:Cercle(48,16,6
:If L1(3)=1:Ligne(59,11,69,21):[b]Ligne(59,21,69,11[/b]
:If L1(3)=.1:Cercle(64,16,6
:0->F
:If L1(1)+L1(2)+L1(3)=3 ou L1(1)+L1(2)+L1(3)=.3:1->F
:If L1(4)+L1(5)+L1(6)=3 ou L1(4)+L1(5)+L1(6)=.3:2->F
:If L1(7)+L1(8)+L1(9)=3 ou L1(7)+L1(8)+L1(9)=.3:3->F
:If L1(1)+L1(4)+L1(7)=3 ou L1(1)+L1(4)+L1(7)=.3:4->F
:If L1(2)+L1(5)+L1(8)=3 ou L1(2)+L1(5)+L1(8)=.3:5->F
:If L1(3)+L1(6)+L1(9)=3 ou L1(3)+L1(6)+L1(9)=.3:6->F
:If L1(1)+L1(5)+L1(9)=3 ou L1(1)+L1(5)+L1(9)=.3:7->F
:If L1(7)+L1(5)+L1(3)=3 ou L1(7)+L1(5)+L1(3)=.3:8->F
:If L1(1)+L1(2)+L1(3)+L1(4)+L1(5)+L1(6)+L1(7)+L1(8)+L1(9)=5.4 et F=0:1->G
:If F[DIFFERENT DE]0 ou G=1:Goto [THETA]
:If B=1:.1->C
:If B=.1:1->C
:Goto 0
:Lbl [THETA]
:If F=1:Ligne(24,16,72,16
:If F=2:Ligne(24,32,72,32
:If F=3:Ligne(24,48,72,48
:If F=4:Ligne(32,8,32,56
:If F=5:Ligne(48,8,48,56
:If F=6:Ligne(64,8,64,56
:If F=7:Ligne(24,8,72,56
:If F=8:Ligne(24,56,72,8
:If G=1:F+1->F
:If G=1 et F[DIFFERENT DE]9:Goto [THETA]
:Pause
:EffDessin
:EffEcr
:Menu("Rejouer ?","Oui",A,"Non",B
:LBL B
:RappelBDG 1
:FonctOn
:Output(1,1,"
Connaisez vous la solution à ce problème (d'après moi ça vient des ":" mais je ne sais pas comment afficher plusieurs lignes dans une condition, sans passer par cette syntaxe...) ?
Autorisation : Membre
Nb de messages : 850
Inscrit le : Sam 15 Oct 2011, 11:07
Posté le : Sam 26 Mai 2012, 18:08
Aha oui ...
Oui je comprends. En fait quand tu veux éxécuter plusieurs commandes après un if tu dois mettre une boucle If/then/(else si besoin)/end. Un If sans end ni then n'éxécutera (ou pas) QU'UNE SEULE ligne après le if.
Donc c'est censé ici faire :
Code
If L1(7)=1
Then
Ligne(27,43,37,53
Ligne(27,53,37,43
End
Et ainsi de suite ...
Ensuite, comme tu peux t'en douter, ton programme peut être grandement optimisé.
Je n'ai cependant pas dans l'immédiat le temps d'y remédier !
---------------------- La la la ...
Avez-vous pensé à regarder le manuel avant de demander conseil ? Un manuel est fait avant tout pour être consulté : MANUEL
Vous avez un problème avec l'ordinateur avec votre calculatrice ? SOLUTION EN VIDEO
Effectivement, ça fonctionne, pour ce qui est de l'optimisation, je suppose que je peux faire des boucles à la place des étiquettes, non ? De toute manière, il va falloir que je m'y mette parce que le programme est plutôt long. Si quelqu'un peut m'aider ?
F-BVXT Invité
Posté le : Sam 26 Mai 2012, 19:59
Voilà, j'ai échangé les étiquettes par des boucles.
Code
:SauveBDG1
:Menu("MORPION","JOUER",A,"SORTIR",B
:LBL A
:1->Xmin
:95->Xmax
:1->Ymin
:63->Ymax
:AxesNAff
:FonctOff
:0->G
:EffDessin
:For(A,24,72,16
:Ligne(A,8,A,56
:1->C
:End
:EffListe L1
:9->dim(L1
:For(A,8,56,16
:Ligne(24,A,72,A
:End
:1->C
:0->F
:Repeat F[DIFFERENT DE]0 ou G=1
:Repeat [THETA]=72 ou [THETA]=73 ou [THETA]=74 ou [THETA]=82 ou [THETA]=83 ou [THETA]=84 ou [THETA]=92 ou [THETA]=93 ou [THETA]=94
:C->B
:0->[THETA]
:codeTouche->[THETA]
:If [THETA]=72 et L1(7)=0:B->L1(7)
:If [THETA]=73 et L1(8)=0:B->L1(8)
:If [THETA]=74 et L1(9)=0:B->L1(9)
:If [THETA]=82 et L1(4)=0:B->L1(4)
:If [THETA]=83 et L1(5)=0:B->L1(5)
:If [THETA]=84 et L1(6)=0:B->L1(6)
:If [THETA]=92 et L1(1)=0:B->L1(1)
:If [THETA]=93 et L1(2)=0:B->L1(2)
:If [THETA]=94 et L1(3)=0:B->L1(3)
:End
:If L1(7)=1
:Then
:Ligne(27,43,37,53
:Ligne(27,53,37,43
:End
:If L1(7)=.1:Cercle(32,48,6
:If L1(8)=1
:Then
:Ligne(43,43,53,53
:Ligne(43,53,53,43
:End
:If L1(8)=.1:Cercle(48,48,6
:If L1(9)=1
:Then
:Ligne(59,43,69,53
:Ligne(59,53,69,43
:End
:If L1(9)=.1:Cercle(64,48,6
:If L1(4)=1
:Then
:Ligne(27,27,37,37
:Ligne(27,37,37,27
:End
:If L1(4)=.1:Cercle(32,32,6
:If L1(5)=1
:Then
:Ligne(43,27,53,37
:Ligne(43,37,53,27
:End
:If L1(5)=.1:Cercle(48,32,6
:If L1(6)=1
:Then
:Ligne(59,27,69,37
:Ligne(59,37,69,27
:End
:If L1(6)=.1:Cercle(64,32,6
:If L1(1)=1
:Then
:Ligne(27,11,37,21
:Ligne(27,21,37,11
:End
:If L1(1)=.1:Cercle(32,16,6
:If L1(2)=1
:Then
:Ligne(43,11,53,21
:Ligne(43,21,53,11
:End
:If L1(2)=.1:Cercle(48,16,6
:If L1(3)=1
:Then
:Ligne(59,11,69,21
:Ligne(59,21,69,11
:End
:If L1(3)=.1:Cercle(64,16,6
:If L1(1)+L1(2)+L1(3)=3 ou L1(1)+L1(2)+L1(3)=.3:1->F
:If L1(4)+L1(5)+L1(6)=3 ou L1(4)+L1(5)+L1(6)=.3:2->F
:If L1(7)+L1(8)+L1(9)=3 ou L1(7)+L1(8)+L1(9)=.3:3->F
:If L1(1)+L1(4)+L1(7)=3 ou L1(1)+L1(4)+L1(7)=.3:4->F
:If L1(2)+L1(5)+L1(8)=3 ou L1(2)+L1(5)+L1(8)=.3:5->F
:If L1(3)+L1(6)+L1(9)=3 ou L1(3)+L1(6)+L1(9)=.3:6->F
:If L1(1)+L1(5)+L1(9)=3 ou L1(1)+L1(5)+L1(9)=.3:7->F
:If L1(7)+L1(5)+L1(3)=3 ou L1(7)+L1(5)+L1(3)=.3:8->F
:If L1(1)+L1(2)+L1(3)+L1(4)+L1(5)+L1(6)+L1(7)+L1(8)+L1(9)=5.4 et F=0:1->G
:If B=1:.1->C
:If B=.1:1->C
:End
:Repeat G[DIFFERENT DE]1 ou F=9
:If F=1:Ligne(24,16,72,16
:If F=2:Ligne(24,32,72,32
:If F=3:Ligne(24,48,72,48
:If F=4:Ligne(32,8,32,56
:If F=5:Ligne(48,8,48,56
:If F=6:Ligne(64,8,64,56
:If F=7:Ligne(24,8,72,56
:If F=8:Ligne(24,56,72,8
:If G=1:F+1->F
:End
:Pause
:EffDessin
:EffEcr
:Menu("Rejouer ?","Oui",A,"Non",B
:LBL B
:RappelBDG 1
:FonctOn
:Output(1,1,"
Le programme est quand même plutôt lent, alors si vous avez des idées pour l'améliorer je suis preneur.
:SauveBDG1
:Menu("MORPION","JOUER",A,"SORTIR",B
:LBL A
:1->Xmin
:95->Xmax
:1->Ymin
:63->Ymax
:AxesNAff
:FonctOff
:0->G
:EffDessin
:For(A,24,72,16
:Ligne(A,8,A,56
:End
:EffListe L1
:9->dim(L1
:For(A,8,56,16
:Ligne(24,A,72,A
:End
:1->C
:EffVar FRepeat F ou G=1
:Repeat max([THETA]={72,73,74,82,83,84,92,93,94
:C->B
:0->[THETA]
:codeTouche->[THETA]
:If [THETA]=72 et L1(7)=0:B->L1(7)
:If [THETA]=73 et L1(8)=0:B->L1(8)
:If [THETA]=74 et L1(9)=0:B->L1(9)
:If [THETA]=82 et L1(4)=0:B->L1(4)
:If [THETA]=83 et L1(5)=0:B->L1(5)
:If [THETA]=84 et L1(6)=0:B->L1(6)
:If [THETA]=92 et L1(1)=0:B->L1(1)
:If [THETA]=93 et L1(2)=0:B->L1(2)
:If [THETA]=94 et L1(3)=0:B->L1(3)
:End
:If L1(7)=1
:Then
:Ligne(27,43,37,53
:Ligne(27,53,37,43
:End
:If L1(7)=.1:Cercle(32,48,6
:If L1(8)=1
:Then
:Ligne(43,43,53,53
:Ligne(43,53,53,43
:End
:If L1(8)=.1:Cercle(48,48,6
:If L1(9)=1
:Then
:Ligne(59,43,69,53
:Ligne(59,53,69,43
:End
:If L1(9)=.1:Cercle(64,48,6
:If L1(4)=1
:Then
:Ligne(27,27,37,37
:Ligne(27,37,37,27
:End
:If L1(4)=.1:Cercle(32,32,6
:If L1(5)=1
:Then
:Ligne(43,27,53,37
:Ligne(43,37,53,27
:End
:If L1(5)=.1:Cercle(48,32,6
:If L1(6)=1
:Then
:Ligne(59,27,69,37
:Ligne(59,37,69,27
:End
:If L1(6)=.1:Cercle(64,32,6
:If L1(1)=1
:Then
:Ligne(27,11,37,21
:Ligne(27,21,37,11
:End
:If L1(1)=.1:Cercle(32,16,6
:If L1(2)=1
:Then
:Ligne(43,11,53,21
:Ligne(43,21,53,11
:End
:If L1(2)=.1:Cercle(48,16,6
:If L1(3)=1
:Then
:Ligne(59,11,69,21
:Ligne(59,21,69,11
:End
:If L1(3)=.1:Cercle(64,16,6
:If L1(1)+L1(2)+L1(3)=3 ou L1(1)+L1(2)+L1(3)=.3:1->F
:If L1(4)+L1(5)+L1(6)=3 ou L1(4)+L1(5)+L1(6)=.3:2->F
:If L1(7)+L1(8)+L1(9)=3 ou L1(7)+L1(8)+L1(9)=.3:3->F
:If L1(1)+L1(4)+L1(7)=3 ou L1(1)+L1(4)+L1(7)=.3:4->F
:If L1(2)+L1(5)+L1(8)=3 ou L1(2)+L1(5)+L1(8)=.3:5->F
:If L1(3)+L1(6)+L1(9)=3 ou L1(3)+L1(6)+L1(9)=.3:6->F
:If L1(1)+L1(5)+L1(9)=3 ou L1(1)+L1(5)+L1(9)=.3:7->F
:If L1(7)+L1(5)+L1(3)=3 ou L1(7)+L1(5)+L1(3)=.3:8->F
:0
:For(Z,1,9
:Rép+L1(Z
:End
:If Rép = 5.4 et non(F : 1 -> G
:If B=1:.1->C
:If B=.1:1->C
:End
:Repeat G[DIFFERENT DE]1 ou F=9
:If F=1:Ligne(24,16,72,16
:If F=2:Ligne(24,32,72,32
:If F=3:Ligne(24,48,72,48
:If F=4:Ligne(32,8,32,56
:If F=5:Ligne(48,8,48,56
:If F=6:Ligne(64,8,64,56
:If F=7:Ligne(24,8,72,56
:If F=8:Ligne(24,56,72,8
:If G=1:F+1->F
:End
:Pause
:EffDessin
:EffEcr
:Menu("Rejouer ?","Oui",A,"Non",B
:LBL B
:RappelBDG 1
:FonctOn
:Output(1,1,"
Donc apparement, quand on met par exemple A, ça veux dire A [DIFFERENT DE] 0. Est-ce que ça marche également pour les listes ? Ce qui voudrait dire ici que :
Code
:If [THETA]=72 et L1(7)=0:B->L1(7)
Deviendrait :
Code
:If [THETA]=72 et L1(7:B->L1(7
F-BVXT Invité
Posté le : Sam 26 Mai 2012, 22:10
Voilà, j'ai essayé avec les listes et ça fonctionne :
Code
:SauveBDG1
:Menu("MORPION","JOUER",A,"SORTIR",B
:LBL A
:1->Xmin
:95->Xmax
:1->Ymin
:63->Ymax
:AxesNAff
:FonctOff
:0->G
:EffDessin
:For(A,24,72,16
:Ligne(A,8,A,56
:End
:EffListe L1
:9->dim(L1
:For(A,8,56,16
:Ligne(24,A,72,A
:End
:1->C
:EffVar FRepeat F ou G=1
:Repeat max([THETA]={72,73,74,82,83,84,92,93,94
:C->B
:0->[THETA]
:codeTouche->[THETA]
:If [THETA]=72 et non(L1(7:B->L1(7
:If [THETA]=73 et non(L1(8:B->L1(8
:If [THETA]=74 et non(L1(9:B->L1(9
:If [THETA]=82 et non(L1(4:B->L1(4
:If [THETA]=83 et non(L1(5:B->L1(5
:If [THETA]=84 et non(L1(6:B->L1(6
:If [THETA]=92 et non(L1(1:B->L1(1
:If [THETA]=93 et non(L1(2:B->L1(2
:If [THETA]=94 et non(L1(3:B->L1(3
:End
:If L1(7)=1
:Then
:Ligne(27,43,37,53
:Ligne(27,53,37,43
:End
:If L1(7)=.1:Cercle(32,48,6
:If L1(8)=1
:Then
:Ligne(43,43,53,53
:Ligne(43,53,53,43
:End
:If L1(8)=.1:Cercle(48,48,6
:If L1(9)=1
:Then
:Ligne(59,43,69,53
:Ligne(59,53,69,43
:End
:If L1(9)=.1:Cercle(64,48,6
:If L1(4)=1
:Then
:Ligne(27,27,37,37
:Ligne(27,37,37,27
:End
:If L1(4)=.1:Cercle(32,32,6
:If L1(5)=1
:Then
:Ligne(43,27,53,37
:Ligne(43,37,53,27
:End
:If L1(5)=.1:Cercle(48,32,6
:If L1(6)=1
:Then
:Ligne(59,27,69,37
:Ligne(59,37,69,27
:End
:If L1(6)=.1:Cercle(64,32,6
:If L1(1)=1
:Then
:Ligne(27,11,37,21
:Ligne(27,21,37,11
:End
:If L1(1)=.1:Cercle(32,16,6
:If L1(2)=1
:Then
:Ligne(43,11,53,21
:Ligne(43,21,53,11
:End
:If L1(2)=.1:Cercle(48,16,6
:If L1(3)=1
:Then
:Ligne(59,11,69,21
:Ligne(59,21,69,11
:End
:If L1(3)=.1:Cercle(64,16,6
:If L1(1)+L1(2)+L1(3)=3 ou L1(1)+L1(2)+L1(3)=.3:1->F
:If L1(4)+L1(5)+L1(6)=3 ou L1(4)+L1(5)+L1(6)=.3:2->F
:If L1(7)+L1(8)+L1(9)=3 ou L1(7)+L1(8)+L1(9)=.3:3->F
:If L1(1)+L1(4)+L1(7)=3 ou L1(1)+L1(4)+L1(7)=.3:4->F
:If L1(2)+L1(5)+L1(8)=3 ou L1(2)+L1(5)+L1(8)=.3:5->F
:If L1(3)+L1(6)+L1(9)=3 ou L1(3)+L1(6)+L1(9)=.3:6->F
:If L1(1)+L1(5)+L1(9)=3 ou L1(1)+L1(5)+L1(9)=.3:7->F
:If L1(7)+L1(5)+L1(3)=3 ou L1(7)+L1(5)+L1(3)=.3:8->F
:0
:For(Z,1,9
:Rép+L1(Z
:End
:If Rép = 5.4 et non(F : 1 -> G
:If B=1:.1->C
:If B=.1:1->C
:End
:Repeat G[DIFFERENT DE]1 ou F=9
:If F=1:Ligne(24,16,72,16
:If F=2:Ligne(24,32,72,32
:If F=3:Ligne(24,48,72,48
:If F=4:Ligne(32,8,32,56
:If F=5:Ligne(48,8,48,56
:If F=6:Ligne(64,8,64,56
:If F=7:Ligne(24,8,72,56
:If F=8:Ligne(24,56,72,8
:If G=1:F+1->F
:End
:Pause
:EffDessin
:EffEcr
:Menu("Rejouer ?","Oui",A,"Non",B
:LBL B
:RappelBDG 1
:FonctOn
:Output(1,1,"
Là, je vois vraiment pas comment optimiser et pourtant le programme est vraiment lent (de plus en plus lent quand le nombre de "coups" augmentent). Parfois, je dois attendre 8 seconde avant que la croix apparaisse. N'y aurait-il pas un moyen de rendre le programme plus rapide ?
Autorisation : Membre
Nb de messages : 3738
Inscrit le : Lun 19 Oct 2009, 21:25
Posté le : Sam 26 Mai 2012, 22:16
Oui.
Plusieurs articles permettent d'aborder quelques notions telles que celle ci.
Un de mes articles traite justement de la gestion de tests avec certaines méthodes.
Code
:If [THETA]=72 et L1(7)=0:B->L1(7)
...
:If [THETA]=94 et L1(3)=0:B->L1(3)
//// peut devenir ça
max(([THETA]={72,73,74,82,83,84,92,93,94}){7,8,9,4,5,6,1,2,3}not(L1
:If Ans
B->L1(Ans
---------------------- ti82statfr: 2008, inscrit: 2009, ti84pocketfr: noël2011, ti30xbmultiview: iut 2012-2014
Perfectionniste, manque tact. Pas le temps de tout publier depuis 2011. Répond toujours aux questions. (rédigé juin 2014)
Autorisation : Membre
Nb de messages : 3738
Inscrit le : Lun 19 Oct 2009, 21:25
Posté le : Sam 26 Mai 2012, 23:28
Je dois vérifier ce que je t'ai proposé : j'ai peut-être commis une grossière erreur.
Edit: il y a bien un problème que je ne parviens pas à résoudre.
Annule ma proposition si je ne trouve pas avant ta prochaine mise à jour.
---------------------- ti82statfr: 2008, inscrit: 2009, ti84pocketfr: noël2011, ti30xbmultiview: iut 2012-2014
Perfectionniste, manque tact. Pas le temps de tout publier depuis 2011. Répond toujours aux questions. (rédigé juin 2014)