Post by bluatigro on Jun 21, 2018 3:54:45 GMT
look see and learn
can anyone think of a game in whitch this is usefulo ?
''bluatigro 21 jun 2018
''fuzzy logic example
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
nomainwin
open "Fuzzy insurance.inc" for graphics as #m
#m "trapclose [quit]"
#m "fill lightgray"
#m "size 2"
driver.is.young$ = fuz$( 0 , 0 , 18 , 25 )
driver.is.midle$ = fuz$( 18 , 25 , 50 , 70 )
driver.is.old$ = fuz$( 50 , 70 , 120 , 120 )
car.is.slow$ = fuz$( 0 , 0 , 120 , 140 )
car.is.average$ = fuz$( 120 , 140 , 170 , 200 )
car.is.fast$ = fuz$( 170 , 200 , 400 , 400 )
pay.is.low$ = fuz$( 0 , 1 , 20 , 40 )
pay.is.midle$ = fuz$( 20 , 40 , 60 , 80 )
pay.is.high$ = fuz$( 60 , 80 , 99 , 100 )
for speed = 400 to 0 step -1
for age = 0 to 120
driveryoung = fuzz( age , driver.is.young$ )
drivermidle = fuzz( age , driver.is.midle$ )
driverold = fuzz( age , driver.is.old$ )
carslow = fuzz( speed , car.is.slow$ )
caraverage = fuzz( speed , car.is.average$ )
carfast = fuzz( speed , car.is.fast$ )
''if car is fast
''or car is average and( not driver is midle )then
'' risc is high
rischigh = max( carfast , min( caraverage , 1 - drivermidle ) )
''if car is slow and not( driver is midle )
''or car is average
''or driver is midle and car is fast then
'' risk is midle
a = min( carslow , 1 - drivermidle )
b = min( carfast , drivermidle )
riscmidle = max( a , max( caraverage , b ) )
''if car is slow then risc is low
risclow = carslow
''defuzzyfication
ml = fuzmass( risclow , pay.is.low$ )
mm = fuzmass( riscmidle , pay.is.midle$ )
mh = fuzmass( rischigh , pay.is.high$ )
pl = fuzpoint( pay.is.low$ )
pm = fuzpoint( pay.is.midle$ )
ph = fuzpoint( pay.is.high$ )
pay = ( ml * pl + mm * pm + mh * ph ) _
/ ( ml + mm + mh + 1e-10 )
call plot speed , age , pay
next age
next speed
wait
end
[quit]
close #m
end
sub plot x , y , z
r = z * 2.5
if not( x mod 10 ) _
or not( y mod 10 ) then g = 255
b = 255 - z * 2.5
#m "color " ; r ; " " ; g ; " " ; b
#m "down"
#m "line " ; 600 + y / 2 + x ; " " ; 350 + y _
; " " ; 600 + y / 2 + x ; " " ; 350 + y - z
#m "up"
end sub
function fuz$( a , b , c , d )
''costruct a fuzzy-object$
fuz$ = a ; " " ; b ; " " ; c ; " " ; d
end function
function fuzz( x , f$ )
''what is membervalue of x in fuzzy-object$
a = val( word$( f$ , 1 ) )
b = val( word$( f$ , 2 ) )
c = val( word$( f$ , 3 ) )
d = val( word$( f$ , 4 ) )
uit = 0
if b <= x and x <= c then uit = 1
if a < x and x < b then
uit = ( x - a ) / ( b - a )
end if
if c < x and x < d then
uit = 1 - ( x - c ) / ( d - c )
end if
fuzz = uit
end function
function fuzmass( h , f$ )
''calulate mass of toped fuzzy-object$
a = val( word$( f$ , 1 ) )
b = val( word$( f$ , 2 ) )
c = val( word$( f$ , 3 ) )
d = val( word$( f$ , 4 ) )
fuzmass = ( ( c - b ) + ( b - a ) / 2 + ( d - c ) / 2 ) * h
end function
function fuzpoint( f$ )
''calulate value of led point
a = val( word$( f$ , 1 ) )
b = val( word$( f$ , 2 ) )
c = val( word$( f$ , 3 ) )
d = val( word$( f$ , 4 ) )
ml = ( b - a ) / 2
mm = c - b
mr = ( d - c ) / 2
pl = ( b + a ) / 2
pm = ( c + b ) / 2
pr = ( d + c ) / 2
fuzpoint = ( ml * pl + mm * pm + mr * pr ) / ( ml + mm + mr )
end function
can anyone think of a game in whitch this is usefulo ?