Huomasin että täältä puuttui Jätkänshakkipeli, joten tässä tulee.
Hiirirutiinit olen kopsinut netistä, muuten koodi on omaa tekoa. Tekoälyn voisi toteuttaa paremminkin ja käyttää aliohjelmia jotta koodi olisi luettavampaa.
Muuten ihan toimiva, olen yrittänyt viilata pahimmat bugit pois.
QB:ssa luonnollisesti käynnistettävä /l-parametrilla.
Otan ideoita vastaan tekoälyn parantamisen suhteen.
' ' J ä t k ä n s h a k k i versio 0.8 ' Tero Ristolainen 2007 ' http://tero.olen.in ' DECLARE SUB MouseDriver (AX%, bx%, cx%, dx%, lb%, rb%, EX%) DIM SHARED mouse$ DIM Grid%(32, 33) ' ruudukko 32 x 33 DIM Menuback%(1300) RANDOMIZE TIMER: SCREEN 12 MouseDriver 1, bx%, cx%, dx%, lb%, rb%, 1 ' Alustetaan hiiri Alku: MouseDriver 2, bx%, cx%, dx%, lb%, rb%, 0 ' Kursori piiloon COLOR 15: LOCATE 1, 1: PRINT " J ä t k ä n s h a k k i"; COLOR 1: PRINT SPACE$(54); "- "; LINE (0, 16)-(639, 479), 7, BF ' harmaa taustaväri FOR x% = 0 TO 32: FOR y% = 1 TO 23 ' piirretään ruudukko LINE (x% * 20, y% * 20)-(x% * 20 + 20, y% * 20 + 20), 8, B Grid%(x%, y%) = -1 NEXT: NEXT MouseDriver 1, bx%, cx%, dx%, lb%, rb%, 0 ' Kursori esiin game% = -1 ' peli = käynnissä valikko% = 0 ' valikko = ei näkyvissä DO MouseDriver 3, bx%, cx%, dx%, lb%, rb%, 0 ' Luetaan hiirtä rx% = INT(cx% / 20) + 1: ry% = INT(dx% / 20) IF lb% = 0 THEN IF valikko% = 2 THEN GOTO Alku ' uusi peli IF valikko% < 0 THEN GOSUB Menu ' valikko END IF IF lb% = -1 THEN IF cx% > 616 AND dx% < 16 THEN IF valikko% = 0 THEN valikko% = -1 ' klikataan menu-näppäintä IF valikko% = 1 THEN valikko% = -2 END IF IF valikko% = 1 AND cx% > 487 AND dx% < 48 AND dx% > 15 THEN IF dx% < 32 THEN valikko% = 2 ELSE END ' lopetus END IF IF Grid%(rx%, ry%) = -1 AND game% = -1 AND valikko% = 0 THEN MouseDriver 2, bx%, cx%, dx%, lb%, rb%, 0 ' Kursori piiloon GOSUB Ruksi GOSUB Tietokone IF game% = 0 THEN COLOR 4: LOCATE 1, 40: PRINT "H Ä V I S I T !"; IF game% = 1 THEN COLOR 2: LOCATE 1, 40: PRINT "V O I T I T !"; IF game% = 2 THEN game% = -1 MouseDriver 1, bx%, cx%, dx%, lb%, rb%, 0 ' Kursori esiin END IF END IF LOOP Menu: MouseDriver 2, bx%, cx%, dx%, lb%, rb%, 0 ' Kursori piiloon IF valikko% = -1 THEN GET (488, 16)-(639, 47), Menuback% ' valikon tausta talteen COLOR 1 LOCATE 2, 62: PRINT " U u s i p e l i "; LOCATE 3, 62: PRINT " L o p e t a "; valikko% = 1 ELSE PUT (488, 16), Menuback%, PSET ' suljetaan valikko, piirretään tausta valikko% = 0 END IF MouseDriver 1, bx%, cx%, dx%, lb%, rb%, 0 ' Kursori esiin RETURN Ruksi: ' piirretään ruksi Grid%(rx%, ry%) = 1 FOR f% = 1 TO 2 x% = rx% * 20 - 19 IF f% = 1 THEN y% = ry% * 20 + 2 ELSE y% = ry% * 20 + 17 FOR r% = 1 TO 16 LINE (x% + 1, y%)-(x% + 3, y% + 1), 1, BF LINE (x%, y%)-(x% + 1, y% + 1), 9, BF WAIT &H3DA, 8 x% = x% + 1 IF f% = 1 THEN y% = y% + 1 ELSE y% = y% - 1 NEXT r% NEXT f% RETURN Nolla: Grid%(x% + lisx%, y% + lisy%) = 0 FOR kulma% = 360 TO 1 STEP -5 DRAW "bm" + STR$((x% + lisx%) * 20 - 9) + "," + STR$((y% + lisy%) * 20 + 10) + " ta" + STR$(kulma%) + " c4bl8l1" DRAW "bm" + STR$((x% + lisx%) * 20 - 10) + "," + STR$((y% + lisy%) * 20 + 10) + " ta" + STR$(kulma%) + " c12bl8l1" WAIT &H3DA, 8 NEXT RETURN Tietokone: FOR y% = 1 TO 23: FOR x% = 1 TO 28 ' Jos 5 ristiä vaakaan IF Grid%(x%, y%) = 1 AND Grid%(x% + 1, y%) = 1 AND Grid%(x% + 2, y%) = 1 AND Grid%(x% + 3, y%) = 1 AND Grid%(x% + 4, y%) = 1 THEN game% = 1: GOTO Hyppy ' Jos 4 nollaa vaakaan IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y%) = 0 AND Grid%(x% + 2, y%) = 0 AND Grid%(x% + 3, y%) = 0 AND Grid%(x% + 4, y%) = 0 THEN game% = 0: lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 0 AND Grid%(x% + 1, y%) = 0 AND Grid%(x% + 2, y%) = 0 AND Grid%(x% + 3, y%) = 0 AND Grid%(x% + 4, y%) = -1 THEN game% = 0: lisx% = 4: lisy% = 0: GOSUB Nolla: GOTO Hyppy ' 00_00 IF Grid%(x%, y%) = 0 AND Grid%(x% + 1, y%) = 0 AND Grid%(x% + 2, y%) = -1 AND Grid%(x% + 3, y%) = 0 AND Grid%(x% + 4, y%) = 0 THEN game% = 0: lisx% = 2: lisy% = 0: GOSUB Nolla: GOTO Hyppy NEXT x%: NEXT y% FOR x% = 1 TO 32: FOR y% = 1 TO 19 ' Jos 5 ristiä pystyyn IF Grid%(x%, y%) = 1 AND Grid%(x%, y% + 1) = 1 AND Grid%(x%, y% + 2) = 1 AND Grid%(x%, y% + 3) = 1 AND Grid%(x%, y% + 4) = 1 THEN game% = 1: GOTO Hyppy ' Jos 4 nollaa pystyyn IF Grid%(x%, y%) = -1 AND Grid%(x%, y% + 1) = 0 AND Grid%(x%, y% + 2) = 0 AND Grid%(x%, y% + 3) = 0 AND Grid%(x%, y% + 4) = 0 THEN game% = 0: lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 0 AND Grid%(x%, y% + 1) = 0 AND Grid%(x%, y% + 2) = 0 AND Grid%(x%, y% + 3) = 0 AND Grid%(x%, y% + 4) = -1 THEN game% = 0: lisx% = 0: lisy% = 4: GOSUB Nolla: GOTO Hyppy ' Jos 2 nollaa - väli - 2 nollaa IF Grid%(x%, y%) = 0 AND Grid%(x%, y% + 1) = 0 AND Grid%(x%, y% + 2) = -1 AND Grid%(x%, y% + 3) = 0 AND Grid%(x%, y% + 4) = 0 THEN game% = 0: lisx% = 0: lisy% = 2: GOSUB Nolla: GOTO Hyppy NEXT y%: NEXT x% FOR x% = 1 TO 28: FOR y% = 1 TO 19 ' Jos 5 ristiä alaviistoon IF Grid%(x%, y%) = 1 AND Grid%(x% + 1, y% + 1) = 1 AND Grid%(x% + 2, y% + 2) = 1 AND Grid%(x% + 3, y% + 3) = 1 AND Grid%(x% + 4, y% + 4) = 1 THEN game% = 1: GOTO Hyppy ' Jos 4 nollaa alaviistoon IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y% + 1) = 0 AND Grid%(x% + 2, y% + 2) = 0 AND Grid%(x% + 3, y% + 3) = 0 AND Grid%(x% + 4, y% + 4) = 0 THEN game% = 0: lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 0 AND Grid%(x% + 1, y% + 1) = 0 AND Grid%(x% + 2, y% + 2) = 0 AND Grid%(x% + 3, y% + 3) = 0 AND Grid%(x% + 4, y% + 4) = -1 THEN game% = 0: lisx% = 4: lisy% = 4: GOSUB Nolla: GOTO Hyppy ' Jos 2 nollaa - väli - 2 nollaa IF Grid%(x%, y%) = 0 AND Grid%(x% + 1, y% + 1) = 0 AND Grid%(x% + 2, y% + 2) = -1 AND Grid%(x% + 3, y% + 3) = 0 AND Grid%(x% + 4, y% + 4) = 0 THEN game% = 0: lisx% = 2: lisy% = 2: GOSUB Nolla: GOTO Hyppy NEXT y%: NEXT x% FOR x% = 1 TO 28: FOR y% = 5 TO 23 ' Jos 5 ristiä yläviistoon IF Grid%(x%, y%) = 1 AND Grid%(x% + 1, y% - 1) = 1 AND Grid%(x% + 2, y% - 2) = 1 AND Grid%(x% + 3, y% - 3) = 1 AND Grid%(x% + 4, y% - 4) = 1 THEN game% = 1: GOTO Hyppy ' Jos 4 nollaa yläviistoon IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y% - 1) = 0 AND Grid%(x% + 2, y% - 2) = 0 AND Grid%(x% + 3, y% - 3) = 0 AND Grid%(x% + 4, y% - 4) = 0 THEN game% = 0: lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 0 AND Grid%(x% + 1, y% - 1) = 0 AND Grid%(x% + 2, y% - 2) = 0 AND Grid%(x% + 3, y% - 3) = 0 AND Grid%(x% + 4, y% - 4) = -1 THEN game% = 0: lisx% = 4: lisy% = -4: GOSUB Nolla: GOTO Hyppy ' Jos 2 nollaa - väli - 2 nollaa IF Grid%(x%, y%) = 0 AND Grid%(x% + 1, y% - 1) = 0 AND Grid%(x% + 2, y% - 2) = -1 AND Grid%(x% + 3, y% - 3) = 0 AND Grid%(x% + 4, y% - 4) = 0 THEN game% = 0: lisx% = 2: lisy% = -2: GOSUB Nolla: GOTO Hyppy NEXT y%: NEXT x% '----------------------------------------JOS XX_XX NIIN... FOR y% = 1 TO 23: FOR x% = 1 TO 28 IF Grid%(x%, y%) = 1 AND Grid%(x% + 1, y%) = 1 AND Grid%(x% + 2, y%) = -1 AND Grid%(x% + 3, y%) = 1 AND Grid%(x% + 4, y%) = 1 THEN lisx% = 2: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 1 AND Grid%(x% + 1, y%) = 1 AND Grid%(x% + 2, y%) = 1 AND Grid%(x% + 3, y%) = -1 AND Grid%(x% + 4, y%) = 1 THEN lisx% = 3: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 1 AND Grid%(x% + 1, y%) = -1 AND Grid%(x% + 2, y%) = 1 AND Grid%(x% + 3, y%) = 1 AND Grid%(x% + 4, y%) = 1 THEN lisx% = 1: lisy% = 0: GOSUB Nolla: GOTO Hyppy NEXT x%: NEXT y% FOR x% = 1 TO 32: FOR y% = 1 TO 19 IF Grid%(x%, y%) = 1 AND Grid%(x%, y% + 1) = 1 AND Grid%(x%, y% + 2) = -1 AND Grid%(x%, y% + 3) = 1 AND Grid%(x%, y% + 4) = 1 THEN lisx% = 0: lisy% = 2: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 1 AND Grid%(x%, y% + 1) = 1 AND Grid%(x%, y% + 2) = 1 AND Grid%(x%, y% + 3) = -1 AND Grid%(x%, y% + 4) = 1 THEN lisx% = 0: lisy% = 3: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 1 AND Grid%(x%, y% + 1) = -1 AND Grid%(x%, y% + 2) = 1 AND Grid%(x%, y% + 3) = 1 AND Grid%(x%, y% + 4) = 1 THEN lisx% = 0: lisy% = 1: GOSUB Nolla: GOTO Hyppy NEXT y%: NEXT x% FOR x% = 1 TO 28: FOR y% = 1 TO 19 IF Grid%(x%, y%) = 1 AND Grid%(x% + 1, y% + 1) = 1 AND Grid%(x% + 2, y% + 2) = -1 AND Grid%(x% + 3, y% + 3) = 1 AND Grid%(x% + 4, y% + 4) = 1 THEN lisx% = 2: lisy% = 2: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 1 AND Grid%(x% + 1, y% + 1) = 1 AND Grid%(x% + 2, y% + 2) = 1 AND Grid%(x% + 3, y% + 3) = -1 AND Grid%(x% + 4, y% + 4) = 1 THEN lisx% = 3: lisy% = 3: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 1 AND Grid%(x% + 1, y% + 1) = -1 AND Grid%(x% + 2, y% + 2) = 1 AND Grid%(x% + 3, y% + 3) = 1 AND Grid%(x% + 4, y% + 4) = 1 THEN lisx% = 1: lisy% = 1: GOSUB Nolla: GOTO Hyppy NEXT y%: NEXT x% FOR x% = 1 TO 28: FOR y% = 5 TO 23 IF Grid%(x%, y%) = 1 AND Grid%(x% + 1, y% - 1) = 1 AND Grid%(x% + 2, y% - 2) = -1 AND Grid%(x% + 3, y% - 3) = 1 AND Grid%(x% + 4, y% - 4) = 1 THEN lisx% = 2: lisy% = -2: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 1 AND Grid%(x% + 1, y% - 1) = 1 AND Grid%(x% + 2, y% - 2) = 1 AND Grid%(x% + 3, y% - 3) = -1 AND Grid%(x% + 4, y% - 4) = 1 THEN lisx% = 3: lisy% = -3: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 1 AND Grid%(x% + 1, y% - 1) = -1 AND Grid%(x% + 2, y% - 2) = 1 AND Grid%(x% + 3, y% - 3) = 1 AND Grid%(x% + 4, y% - 4) = 1 THEN lisx% = 1: lisy% = -1: GOSUB Nolla: GOTO Hyppy NEXT y%: NEXT x% '----------------------------JOS NELJÄ RISTIÄ NIIN... FOR y% = 1 TO 23: FOR x% = 1 TO 28 ' Jos 4 ristiä vaakaan IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y%) = 1 AND Grid%(x% + 2, y%) = 1 AND Grid%(x% + 3, y%) = 1 AND Grid%(x% + 4, y%) = 1 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 1 AND Grid%(x% + 1, y%) = 1 AND Grid%(x% + 2, y%) = 1 AND Grid%(x% + 3, y%) = 1 AND Grid%(x% + 4, y%) = -1 THEN lisx% = 4: lisy% = 0: GOSUB Nolla: GOTO Hyppy NEXT x%: NEXT y% FOR x% = 1 TO 32: FOR y% = 1 TO 19 ' Jos 4 ristiä pystyyn IF Grid%(x%, y%) = -1 AND Grid%(x%, y% + 1) = 1 AND Grid%(x%, y% + 2) = 1 AND Grid%(x%, y% + 3) = 1 AND Grid%(x%, y% + 4) = 1 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 1 AND Grid%(x%, y% + 1) = 1 AND Grid%(x%, y% + 2) = 1 AND Grid%(x%, y% + 3) = 1 AND Grid%(x%, y% + 4) = -1 THEN lisx% = 0: lisy% = 4: GOSUB Nolla: GOTO Hyppy NEXT y%: NEXT x% FOR x% = 1 TO 28: FOR y% = 1 TO 19 ' Jos 4 ristiä alaviistoon IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y% + 1) = 1 AND Grid%(x% + 2, y% + 2) = 1 AND Grid%(x% + 3, y% + 3) = 1 AND Grid%(x% + 4, y% + 4) = 1 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 1 AND Grid%(x% + 1, y% + 1) = 1 AND Grid%(x% + 2, y% + 2) = 1 AND Grid%(x% + 3, y% + 3) = 1 AND Grid%(x% + 4, y% + 4) = -1 THEN lisx% = 4: lisy% = 4: GOSUB Nolla: GOTO Hyppy NEXT y%: NEXT x% FOR x% = 1 TO 28: FOR y% = 5 TO 23 ' Jos 4 ristiä yläviistoon IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y% - 1) = 1 AND Grid%(x% + 2, y% - 2) = 1 AND Grid%(x% + 3, y% - 3) = 1 AND Grid%(x% + 4, y% - 4) = 1 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 1 AND Grid%(x% + 1, y% - 1) = 1 AND Grid%(x% + 2, y% - 2) = 1 AND Grid%(x% + 3, y% - 3) = 1 AND Grid%(x% + 4, y% - 4) = -1 THEN lisx% = 4: lisy% = -4: GOSUB Nolla: GOTO Hyppy NEXT y%: NEXT x% '--------------------------------JOS KOLME SAMAA NIIN... arv% = INT(RND * 2) + 1 FOR y% = 1 TO 23: FOR x% = 1 TO 28 ' Jos 3 samaa vaakaan IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y%) = 1 AND Grid%(x% + 2, y%) = 1 AND Grid%(x% + 3, y%) = 1 AND Grid%(x% + 4, y%) = -1 THEN IF arv% = 1 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF arv% = 2 THEN lisx% = 4: lisy% = 0: GOSUB Nolla: GOTO Hyppy END IF IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y%) = 0 AND Grid%(x% + 2, y%) = 0 AND Grid%(x% + 3, y%) = 0 AND Grid%(x% + 4, y%) = -1 THEN IF arv% = 1 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF arv% = 2 THEN lisx% = 4: lisy% = 0: GOSUB Nolla: GOTO Hyppy END IF NEXT x%: NEXT y% FOR x% = 1 TO 32: FOR y% = 1 TO 19 ' Jos 3 samaa pystyyn IF Grid%(x%, y%) = -1 AND Grid%(x%, y% + 1) = 1 AND Grid%(x%, y% + 2) = 1 AND Grid%(x%, y% + 3) = 1 AND Grid%(x%, y% + 4) = -1 THEN IF arv% = 1 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF arv% = 2 THEN lisx% = 0: lisy% = 4: GOSUB Nolla: GOTO Hyppy END IF IF Grid%(x%, y%) = -1 AND Grid%(x%, y% + 1) = 0 AND Grid%(x%, y% + 2) = 0 AND Grid%(x%, y% + 3) = 0 AND Grid%(x%, y% + 4) = -1 THEN IF arv% = 1 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF arv% = 2 THEN lisx% = 0: lisy% = 4: GOSUB Nolla: GOTO Hyppy END IF NEXT y%: NEXT x% FOR x% = 1 TO 28: FOR y% = 1 TO 19 ' Jos 3 samaa alaviistoon IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y% + 1) = 1 AND Grid%(x% + 2, y% + 2) = 1 AND Grid%(x% + 3, y% + 3) = 1 AND Grid%(x% + 4, y% + 4) = -1 THEN IF arv% = 1 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF arv% = 2 THEN lisx% = 4: lisy% = 4: GOSUB Nolla: GOTO Hyppy END IF IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y% + 1) = 0 AND Grid%(x% + 2, y% + 2) = 0 AND Grid%(x% + 3, y% + 3) = 0 AND Grid%(x% + 4, y% + 4) = -1 THEN IF arv% = 1 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF arv% = 2 THEN lisx% = 4: lisy% = 4: GOSUB Nolla: GOTO Hyppy END IF NEXT y%: NEXT x% FOR x% = 1 TO 28: FOR y% = 5 TO 23 ' Jos 3 samaa yläviistoon IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y% - 1) = 1 AND Grid%(x% + 2, y% - 2) = 1 AND Grid%(x% + 3, y% - 3) = 1 AND Grid%(x% + 4, y% - 4) = -1 THEN IF arv% = 1 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF arv% = 2 THEN lisx% = 4: lisy% = -4: GOSUB Nolla: GOTO Hyppy END IF IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y% - 1) = 0 AND Grid%(x% + 2, y% - 2) = 0 AND Grid%(x% + 3, y% - 3) = 0 AND Grid%(x% + 4, y% - 4) = -1 THEN IF arv% = 1 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF arv% = 2 THEN lisx% = 4: lisy% = -4: GOSUB Nolla: GOTO Hyppy END IF NEXT y%: NEXT x% '--------------------------------JOS KOLME SAMAA NIIN... FOR y% = 1 TO 23: FOR x% = 1 TO 29 ' Jos 3 samaa vaakaan IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y%) = 1 AND Grid%(x% + 2, y%) = 1 AND Grid%(x% + 3, y%) = 1 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 1 AND Grid%(x% + 1, y%) = 1 AND Grid%(x% + 2, y%) = 1 AND Grid%(x% + 3, y%) = -1 THEN lisx% = 3: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y%) = 0 AND Grid%(x% + 2, y%) = 0 AND Grid%(x% + 3, y%) = 0 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 0 AND Grid%(x% + 1, y%) = 0 AND Grid%(x% + 2, y%) = 0 AND Grid%(x% + 3, y%) = -1 THEN lisx% = 3: lisy% = 0: GOSUB Nolla: GOTO Hyppy NEXT x%: NEXT y% FOR x% = 1 TO 32: FOR y% = 1 TO 20 ' Jos 3 samaa pystyyn IF Grid%(x%, y%) = -1 AND Grid%(x%, y% + 1) = 1 AND Grid%(x%, y% + 2) = 1 AND Grid%(x%, y% + 3) = 1 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 1 AND Grid%(x%, y% + 1) = 1 AND Grid%(x%, y% + 2) = 1 AND Grid%(x%, y% + 3) = -1 THEN lisx% = 0: lisy% = 3: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = -1 AND Grid%(x%, y% + 1) = 0 AND Grid%(x%, y% + 2) = 0 AND Grid%(x%, y% + 3) = 0 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 0 AND Grid%(x%, y% + 1) = 0 AND Grid%(x%, y% + 2) = 0 AND Grid%(x%, y% + 3) = -1 THEN lisx% = 0: lisy% = 3: GOSUB Nolla: GOTO Hyppy NEXT y%: NEXT x% FOR x% = 1 TO 29: FOR y% = 1 TO 20 ' Jos 3 samaa alaviistoon IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y% + 1) = 1 AND Grid%(x% + 2, y% + 2) = 1 AND Grid%(x% + 3, y% + 3) = 1 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 1 AND Grid%(x% + 1, y% + 1) = 1 AND Grid%(x% + 2, y% + 2) = 1 AND Grid%(x% + 3, y% + 3) = -1 THEN lisx% = 3: lisy% = 3: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y% + 1) = 0 AND Grid%(x% + 2, y% + 2) = 0 AND Grid%(x% + 3, y% + 3) = 0 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 0 AND Grid%(x% + 1, y% + 1) = 0 AND Grid%(x% + 2, y% + 2) = 0 AND Grid%(x% + 3, y% + 3) = -1 THEN lisx% = 3: lisy% = 3: GOSUB Nolla: GOTO Hyppy NEXT y%: NEXT x% FOR x% = 1 TO 29: FOR y% = 4 TO 23 ' Jos 3 samaa yläviistoon IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y% - 1) = 1 AND Grid%(x% + 2, y% - 2) = 1 AND Grid%(x% + 3, y% - 3) = 1 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 1 AND Grid%(x% + 1, y% - 1) = 1 AND Grid%(x% + 2, y% - 2) = 1 AND Grid%(x% + 3, y% - 3) = -1 THEN lisx% = 3: lisy% = -3: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y% - 1) = 0 AND Grid%(x% + 2, y% - 2) = 0 AND Grid%(x% + 3, y% - 3) = 0 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 0 AND Grid%(x% + 1, y% - 1) = 0 AND Grid%(x% + 2, y% - 2) = 0 AND Grid%(x% + 3, y% - 3) = -1 THEN lisx% = 3: lisy% = -3: GOSUB Nolla: GOTO Hyppy NEXT y%: NEXT x% '------------------------------------JOS KAKSI SAMAA NIIN... FOR y% = 1 TO 23: FOR x% = 1 TO 30 ' Jos 2 samaa vaakaan IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y%) = 0 AND Grid%(x% + 2, y%) = 0 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 0 AND Grid%(x% + 1, y%) = 0 AND Grid%(x% + 2, y%) = -1 THEN lisx% = 2: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y%) = 1 AND Grid%(x% + 2, y%) = 1 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 1 AND Grid%(x% + 1, y%) = 1 AND Grid%(x% + 2, y%) = -1 THEN lisx% = 2: lisy% = 0: GOSUB Nolla: GOTO Hyppy NEXT x%: NEXT y% FOR x% = 1 TO 32: FOR y% = 1 TO 21 ' Jos 2 samaa pystyyn IF Grid%(x%, y%) = -1 AND Grid%(x%, y% + 1) = 0 AND Grid%(x%, y% + 2) = 0 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 0 AND Grid%(x%, y% + 1) = 0 AND Grid%(x%, y% + 2) = -1 THEN lisx% = 0: lisy% = 2: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = -1 AND Grid%(x%, y% + 1) = 1 AND Grid%(x%, y% + 2) = 1 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 1 AND Grid%(x%, y% + 1) = 1 AND Grid%(x%, y% + 2) = -1 THEN lisx% = 0: lisy% = 2: GOSUB Nolla: GOTO Hyppy NEXT y%: NEXT x% FOR x% = 1 TO 30: FOR y% = 1 TO 21 ' Jos 2 samaa alaviistoon IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y% + 1) = 0 AND Grid%(x% + 2, y% + 2) = 0 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 0 AND Grid%(x% + 1, y% + 1) = 0 AND Grid%(x% + 2, y% + 2) = -1 THEN lisx% = 2: lisy% = 2: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y% + 1) = 1 AND Grid%(x% + 2, y% + 2) = 1 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 1 AND Grid%(x% + 1, y% + 1) = 1 AND Grid%(x% + 2, y% + 2) = -1 THEN lisx% = 2: lisy% = 2: GOSUB Nolla: GOTO Hyppy NEXT y%: NEXT x% FOR x% = 1 TO 30: FOR y% = 3 TO 23 ' Jos 2 samaa yläviistoon IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y% - 1) = 0 AND Grid%(x% + 2, y% - 2) = 0 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 0 AND Grid%(x% + 1, y% - 1) = 0 AND Grid%(x% + 2, y% - 2) = -1 THEN lisx% = 2: lisy% = -2: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = -1 AND Grid%(x% + 1, y% - 1) = 1 AND Grid%(x% + 2, y% - 2) = 1 THEN lisx% = 0: lisy% = 0: GOSUB Nolla: GOTO Hyppy IF Grid%(x%, y%) = 1 AND Grid%(x% + 1, y% - 1) = 1 AND Grid%(x% + 2, y% - 2) = -1 THEN lisx% = 2: lisy% = -2: GOSUB Nolla: GOTO Hyppy NEXT y%: NEXT x% '---------------ARVOTAAN PAIKKA---------------------------- DO xx% = INT(RND * 2) + 1: yy% = INT(RND * 2) + 1 IF xx% = 2 THEN xx% = -1 IF yy% = 2 THEN yy% = -1 IF Grid%(rx% + xx%, ry% + yy%) = -1 THEN x% = rx%: y% = ry%: lisx% = xx%: lisy% = yy%: GOSUB Nolla EXIT DO END IF LOOP Hyppy: RETURN DATA 55,89,E5,8B,5E,0C,8B,07,50,8B,5E,0A,8B,07,50,8B DATA 5E,08,8B,0F,8B,5E,06,8B,17,5B,58,1E,07,CD,33,53 DATA 8B,5E,0C,89,07,58,8B,5E,0A,89,07,8B,5E,08,89,0F DATA 8B,5E,06,89,17,5D,CA,08,00 SUB MouseDriver (AX%, bx%, cx%, dx%, lb%, rb%, EX%) IF EX% = 1 THEN mouse$ = SPACE$(57) FOR i% = 1 TO 57 READ A$ H$ = CHR$(VAL("&H" + A$)) MID$(mouse$, i%, 1) = H$ NEXT i% END IF DEF SEG = VARSEG(mouse$) CALL Absolute(AX%, bx%, cx%, dx%, SADD(mouse$)) lb% = ((bx% AND 1) <> 0) rb% = ((bx% AND 2) <> 0) END SUB
Tyylikäs toteutus, tekoälyssä olisi tosiaan vielä parantamista. Perusidea on laskea mahdollisia pelitilanteita eteenpäin kokeilemalla eri kohtiin omia ja vastustajan siirtoja ja tutkia, mikä siirto on kannattavin, vaikka vastustaja pelaisi parhaimpansa mukaan. Mitä pitemmälle tekoäly pystyy laskemaan pelin mahdollisia jatkoja, sitä parempi siitä tulee.
Ohjelmointiputkassa pidettiin taannoin kilpailu, jossa tehtävänä oli ohjelmoida ristinollan tekoäly. Kilpailun parhaat ohjelmat ovat todella taitavia pelaamaan. Tässä linkki kilpailuun: https://www.ohjelmointiputka.net/kilpa.php?
Eikä, mä hävisin tolle. :(
Siistiä.
Aihe on jo aika vanha, joten et voi enää vastata siihen.