Voici un petit jeu que j'ai inventé lorsque j'étais enfant. Le but du jeu est de remplir 25 cases (5 x 5) en se déplaçant comme un cheval au échec sans jamais touchés deux fois la même case.
Le code source GWBASIC du jeu :
- 10 DIM T(5,5)
- 20 SCREEN 0:WIDTH 40:CLS:KEY OFF:COLOR 7,0
- 30 PRINT "+=====================================+"
- 40 PRINT "| |"
- 50 PRINT "| |"
- 60 PRINT "| |"
- 70 PRINT "| |"
- 80 PRINT "| |"
- 90 PRINT "| |"
- 100 PRINT "| |"
- 110 PRINT "| |"
- 120 PRINT "| SYLVAIN MALTAIS |"
- 130 PRINT "| |"
- 140 PRINT "| PRESENTE |"
- 150 PRINT "| |"
- 160 PRINT "|";:COLOR 30,0:PRINT " | ---+ +-- ";:COLOR 7,0:PRINT "|"
- 170 PRINT "|";:COLOR 30,0:PRINT " | +--+ +-+ ";:COLOR 7,0:PRINT "|"
- 180 PRINT "|";:COLOR 30,0:PRINT " | | | ";:COLOR 7,0:PRINT "|"
- 190 PRINT "|";:COLOR 30,0:PRINT " +--- ++-- --+ ";:COLOR 7,0:PRINT "|"
- 200 PRINT "| |"
- 210 PRINT "| |"
- 220 PRINT "| |"
- 230 PRINT "| |"
- 240 PRINT "+=====================================+"
- 250 FOR A=0 TO 3000:NEXT
- 320 GOTO 1020
- 460 IF A$=CHR$(27) THEN RUN"MAITRE"
- 470 A$=INKEY$:IF A$="" THEN 470
- 480 SCREEN 0,1,0:WIDTH 40:COLOR 7,0:CLS
- 490 PRINT TAB(9)," L 2 5"
- 500 PRINT TAB(9),"+-+-+-+-+-+"
- 510 PRINT TAB(9),"| | | | | |5"
- 520 PRINT TAB(9),"+-+-+-+-+-´"
- 530 PRINT TAB(9),"| | | | | |4"
- 540 PRINT TAB(9),"+-+-+-+-+-´"
- 550 PRINT TAB(9),"| | | | | |3"
- 560 PRINT TAB(9),"+-+-+-+-+-´"
- 570 PRINT TAB(9),"| | | | | |2"
- 580 PRINT TAB(9),"+-+-+-+-+-´"
- 590 PRINT TAB(9),"| | | | | |1"
- 600 PRINT TAB(9),"+-+-+-+-+-+":PRINT TAB(9)," A B C D E":LOCATE 18,1:COLOR 6:PRINT "A1-":CP$="A1-"
- 610 XA=18:YA=4:NO=1:B$="A1":A=1:LOCATE 11,16:COLOR 6:PRINT "X":COLOR 7
- 620 FOR C=1 TO 5:FOR B=1 TO 5:T(C,B)=0:NEXT B,C:T(1,1)=1:B=1
- 630 A$="":COLOR 6,0:LOCATE 15,6:PRINT "VOTRE DERNIER COUP:"B$:PRINT SPACE$(40):PRINT SPACE$(40)
- 640 A$="":LOCATE 16,1:PRINT SPACE$(40):LOCATE 16,6:PRINT "VOTRE COUP(EX:C2) ?";:COLOR 22:PRINT "_";:COLOR 6
- 645 C$=INKEY$:IF C$="" THEN 645 ELSE IF C$=CHR$(13) THEN 630
- 646 PRINT CHR$(29)+C$;:COLOR 22:PRINT "_";:COLOR 6:A$=A$+C$:IF LEN(A$)=2 THEN 660 ELSE 645
- 660 X=ASC(LEFT$(A$,1))-64:Y=VAL(RIGHT$(A$,1))
- 670 IF X=1 AND Y=1 AND T(2,3)=1 AND T(3,2)=1 THEN 990
- 680 IF X=1 AND Y=2 AND T(3,1)=1 AND T(3,3)=1 AND T(2,4)=1 THEN 990
- 690 IF X=1 AND Y=3 AND T(2,1)=1 AND T(2,5)=1 AND T(3,2)=1 AND T(3,4)=1 THEN 990
- 700 IF X=1 AND Y=4 AND T(2,2)=1 AND T(3,3)=1 AND T(3,5)=1 THEN 990
- 705 IF X=1 AND Y=5 AND T(2,3)=1 AND T(3,4)=1 THEN 990
- 710 IF X=2 AND Y=1 AND T(1,3)=1 AND T(3,3)=1 AND T(4,2)=1 THEN 990
- 720 IF X=2 AND Y=2 AND T(1,4)=1 AND T(3,4)=1 AND T(4,1)=1 AND T(4,3)=1 THEN 990
- 730 IF X=2 AND Y=3 AND T(1,1)=1 AND T(1,5)=1 AND T(3,1)=1 AND T(3,5)=1 AND T(4,2)=1 AND T(4,4)=1 THEN 990
- 740 IF X=2 AND Y=4 AND T(1,2)=1 AND T(3,2)=1 AND T(4,3)=1 AND T(4,5)=1 THEN 990
- 750 IF X=2 AND Y=5 AND T(1,3)=1 AND T(3,3)=1 AND T(4,4)=1 THEN 990
- 760 IF X=3 AND Y=1 AND T(1,2)=1 AND T(2,3)=1 AND T(4,3)=1 AND T(5,2)=1 THEN 990
- 770 IF X=3 AND Y=2 AND T(1,1)=1 AND T(1,3)=1 AND T(2,4)=1 AND T(4,4)=1 AND T(5,1)=1 AND T(5,3)=1 THEN 990
- 780 IF X=3 AND Y=3 AND T(1,2)=1 AND T(1,4)=1 AND T(2,1)=1 AND T(2,5)=1 AND T(4,1)=1 AND T(4,5)=1 AND T(5,2)=1 AND T(5,4)=1 THEN 990
- 790 IF X=3 AND Y=4 AND T(1,3)=1 AND T(1,5)=1 AND T(2,2)=1 AND T(4,2)=1 AND T(5,3)=1 AND T(5,5)=1 THEN 990
- 800 IF X=3 AND Y=5 AND T(1,4)=1 AND T(2,3)=1 AND T(4,3)=1 AND T(5,4)=1 THEN 990
- 810 IF X=4 AND Y=1 AND T(2,2)=1 AND T(3,3)=1 AND T(5,3)=1 THEN 990
- 820 IF X=4 AND Y=2 AND T(2,1)=1 AND T(2,3)=1 AND T(3,4)=1 AND T(5,4)=1 THEN 990
- 830 IF X=4 AND Y=3 AND T(2,2)=1 AND T(2,4)=1 AND T(3,1)=1 AND T(3,5)=1 AND T(5,1)=1 AND T(5,5)=1 THEN 990
- 840 IF X=4 AND Y=4 AND T(2,3)=1 AND T(2,5)=1 AND T(3,2)=1 AND T(5,2)=1 THEN 990
- 850 IF X=4 AND Y=5 AND T(2,4)=1 AND T(3,3)=1 AND T(5,3)=1 THEN 990
- 860 IF X=5 AND Y=1 AND T(3,2)=1 AND T(4,3)=1 THEN 990
- 870 IF X=5 AND Y=2 AND T(3,1)=1 AND T(3,3)=1 AND T(4,4)=1 THEN 990
- 880 IF X=5 AND Y=3 AND T(3,2)=1 AND T(3,4)=1 AND T(4,1)=1 AND T(4,5)=1 THEN 990
- 890 IF X=5 AND Y=4 AND T(3,3)=1 AND T(3,5)=1 AND T(4,2)=1 THEN 990
- 900 IF X=5 AND Y=5 AND T(3,4)=1 AND T(4,3)=1 THEN 990
- 910 IF ((A=X-1 OR A=X+1) AND (B=Y-2 OR B=Y+2)) OR ((A=X-2 OR A=X+2) AND (B=Y-1 OR B=Y+1)) THEN 920 ELSE 980
- 920 IF X>5 OR Y>5 THEN 980
- 930 IF T(X,Y)=1 THEN 980
- 940 IF NO=24 THEN 1000
- 950 LOCATE XA,YA:PRINT MID$(A$,1,2)+"-":CP$=CP$+MID$(A$,1,2)+"-":YA=YA+3:NO=NO+1:LOCATE 13-2*Y,14+2*X:PRINT "X":T(X,Y)=1:A=X:B=Y:B$=A$
- 960 IF YA>39 THEN YA=1:XA=XA+1
- 970 GOTO 630
- 980 LOCATE 17,4:COLOR 28,0:PRINT "VOUS NE POUVEZ JOUEZ CE COUP.":COLOR 6,0:GOTO 640
- 990 SCREEN 0:WIDTH 40:COLOR 15,0:CLS:LOCATE 12,12:PRINT "VOUS AVEZ PERDUE.":GOTO 1010
- 1000 SCREEN 0:WIDTH 40:COLOR 15,0:CLS:LOCATE 12,12:PRINT "BRAVO! TU AS GAGNER!"
- 1010 FOR A=0 TO 3000:NEXT
- 1020 SCREEN 0,1,0:WIDTH 80:COLOR 15,0:CLS:R=7
- 1030 LOCATE 2,18:COLOR 30:PRINT "MENU":COLOR 7
- 1040 PRINT STRING$(80,"_"):LOCATE 25,1:COLOR 0,15:PRINT "PRESSE LES FLECHES("+CHR$(24)+" "+CHR$(25)+")POUR CHOISIR ET <ENTER> POUR EXECUTER . . . ":COLOR 15,0
- 1050 COLOR 15,0:LOCATE 7,1:PRINT " 1-POUR IMPRIMER LES COUPS SUR L'IMPRIMENTE"
- 1060 LOCATE 8,1:PRINT " 2-POUR IMPRIMER LES COUPS SUR L'ECRAN"
- 1070 LOCATE 9,1:PRINT " 3-POUR JOUER UNE AUTRE PARTIE DE L25"
- 1080 LOCATE 10,1:PRINT " 4-POUR LES INSTRUCTIONS"
- 1090 LOCATE 11,1:PRINT " 5-POUR RETOURNER AU PRE-MENU"
- 1100 IF R=7 THEN B$="1-POUR IMPRIMER LES COUPS SUR L'IMPRIMENTE"
- 1110 IF R=8 THEN B$="2-POUR IMPRIMER LES COUPS SUR L'ECRAN"
- 1120 IF R=9 THEN B$="3-POUR JOUER UNE AUTRE PARTIE DE L25"
- 1130 IF R=10 THEN B$="4-POUR LES INSTRUCTIONS"
- 1140 IF R=11 THEN B$="5-POUR RETOURNER AU PRE-MENU"
- 1150 LOCATE R,1:COLOR 20,0:PRINT CHR$(16)" ";:COLOR 30,1:PRINT B$
- 1160 A$=INKEY$:IF A$="" THEN 1160
- 1170 K=VAL(A$):IF A$=CHR$(0)+"H" OR A$="8" THEN R=R-1
- 1180 IF A$=CHR$(0)+"P" THEN R=R+1 ELSE IF A$=CHR$(13) THEN K=R-6
- 1190 IF R=6 THEN R=11 ELSE IF R=12 THEN R=7
- 1200 ON K GOTO 2040,1210,480,3200,1400
- 1205 GOTO 1050
- 1210 SCREEN 0:WIDTH 40:CLS:LOCATE 10,1:PRINT "LA DERNIERE PARTIE"
- 1220 LOCATE 12,1:IF CP$="" THEN PRINT "VOUS N'AVEZ PAS ENCORS JOUER DE PARTIE" ELSE PRINT CP$
- 1230 LOCATE 15,1:PRINT "PRESSE UNE TOUCHE POUR CONTINUER . . . "
- 1240 A$=INKEY$:IF A$="" THEN 1240 ELSE 1020
- 1400 RUN"MAITRE"
- 2040 LPRINT " L25 ":LPRINT :LPRINT CP$
- 3200 SCREEN 0:WIDTH 40:CLS:LOCATE 3,14:COLOR 30,0:PRINT "INSTRUCTION":COLOR 7,0
- 3300 PRINT "_______________________________________"
- 3400 PRINT :PRINT " L25 est un jeux de logique qui consi-"
- 3500 PRINT "ste à jouer le plus de coup possible de"
- 3600 PRINT "la manière suivante:Il se déplace d'une"
- 3700 PRINT "case VERTICALEMENT ou HORIZONTALEMENT"
- 3800 PRINT "et puis d'une case en DIAGONALE ,lequel"
- 3900 PRINT "ne doit pas être ADJACENT a cel quitté"
- 4000 PRINT "de tous les déplacements constitues un"
- 4100 PRINT "seul déplacement ou en d'autres mots,il"
- 4200 PRINT "se déplace comme un cavalier au ECHEC."
- 4300 PRINT "_______________________________________"
- 4400 LOCATE 18,18:COLOR 1:PRINT "BONNE CHANCE!!":COLOR 7,0
- 4490 LOCATE 21,1:COLOR 0,7:PRINT "PRESSE UNE TOUCHE POUR CONTINUER... "
- 4510 A$=INKEY$:IF A$="" THEN 4510 ELSE 1020
Solution
Voici une des solutions gagnant, la technique en losange:
1 | 14 | 9 | 20 | 3 |
24 | 19 | 2 | 15 | 10 |
13 | 8 | 25 | 4 | 21 |
18 | 23 | 6 | 11 | 16 |
7 | 12 | 17 | 22 | 5 |
Dernière mise à jour : Samedi, le 24 janvier 2015