''does not work right jet
'demo Genetic Algoritm .
DIM a( 4 ), dice( 4 ), fit( 4 )
a( 0 ) = byte( "01010101" )
a( 1 ) = byte( "00110011" )
a( 2 ) = byte( "00001111" )
CLS
PRINT " Blua Tigro (C) 1993"
PRINT " Presends : Bitmaster ."
PRINT " Bitmaster is a program"
PRINT " that shows the computers"
PRINT " capability to lern ."
PRINT " Its trying to gues your code ."
PRINT " This code exsists of eight bits ."
PRINT " The bits are 0 or 1 ."
PRINT " Please respond corectly"
PRINT " on the computers qwestion(s) ."
GOSUB [waitforkey]
[restart]
FOR t = 0 TO 4 'first generation .
dice( t ) = INT( RND( 0 ) * 256)
NEXT t
count = 0
total = 1
CLS
PRINT "1 = Computer plays ."
PRINT "2 = You try it ."
PRINT "3 = End this game ."
input a$ : a = val( a$ )
IF a >= 3 or a < 1 THEN END
IF a = 2 THEN GOTO [human]
[game]
print "Try " ; str$( total ) ; " : I think it is : " ;
FOR m = 0 TO 7
IF ( dice( count ) AND 2 ^ m ) = 0 THEN
print "0" ;
ELSE
print "1" ;
END IF
NEXT m
print
INPUT "How many are corect [ x = end ] "; goed$
fit( count ) = VAL( good$ )
IF good$ = "x" THEN GOTO [restart]
IF fit( count ) = 8 THEN GOTO [end]
IF ( total mod 4 ) = 0 THEN 'next generation
print "Next generation ."
FOR t = 1 TO 3 'sort generation
FOR b = 0 TO t
IF fit( b ) < fit( t ) THEN
h = fit( t )
fit( t ) = fit( b )
fit( b ) = h
h = dice( t )
dice( t ) = dice( b )
dice( b ) = h
END IF
NEXT b
NEXT t
FOR t = 2 TO 3
'2 best are parents .
'crossover chromosomes .
d = int( rnd( 0 ) * 3 )
IF RND( 0 ) < .5 THEN
half = 255 - a( d )
ELSE
half = a( d )
END IF
dice( t ) = ( dice( 0 ) AND half ) _
+ ( dice( 1 ) AND ( 255 - half ) )
NEXT t
'no 2 the same .
'mutate chromosomes .
FOR a = 1 TO 3
FOR b = 0 TO a - 1
IF dice( a ) = dice( b ) THEN
d = INT( RND( 0 ) * 8 )
dice( a ) = dice( a ) XOR 2 ^ d
END IF
NEXT b
NEXT a
count = 0
END IF
count = count + 1
total = total + 1
GOTO [game]
[end]
PRINT
PRINT "The computer has corectly guest"
PRINT "your code in "; total ; " gueses ."
GOSUB [waitforkey]
GOTO [restart]
[waitforkey]
PRINT
PRINT "[ Press return or enter]"
input a$
RETURN
[human]
CLS
PRINT : PRINT : PRINT
dice = int( rnd( 0 ) * 256 )
count = 1
[dice]
PRINT
q$ = ""
INPUT "Your gues [ 00000000 - 11111111 ] = "; q$
IF q$ = "x" THEN GOTO [restart]
IF LEN( q$ ) <> 8 THEN
PRINT
PRINT "Please use 8 bits"
GOTO [dice]
end if
g = 0
FOR t = 0 TO 7
a = VAL( MID$( q$ , t + 1 , 1 ))
b = ( dice AND 2 ^ t ) / 2 ^ t
IF a = b THEN g = g + 1
NEXT t
PRINT
PRINT "You guest "; g ; " bits corectly ."
IF g = 8 THEN
PRINT
PRINT " You guest corectly in "; count; " times ."
GOSUB [waitforkey]
END IF
count = count + 1
IF g = 8 THEN GOTO [restart]
GOTO [dice]
function byte( a$ )
som = 0
for i = 1 to len( a$ )
if mid$( a$ , len( a$ ) - i + 1 , 1 ) = "1" then
som = som + 2 ^ ( len( a$ ) - i )
end if
next i
byte = som
end function