|
Post by bluatigro on Jul 24, 2018 11:33:40 GMT
''bluatigro 24 jul 2018 ''tree and tent puzle.
''on a farm there are some tree's ''every tree has a tent near ''tent's do not near tent's also diagonal ''the number's at the end of a ''colom or row are the number ''of tent's in that row or colom
dim gen( in( 200 , 10 , 8 ) ) , t( 10 , 8 ) dim ry( 200 ) , fout( 200 ) dim x( 10 ) , y( 8 ) global empty , tent , notent , tree notent = 0 empty = 1 tent = 2 tree = 3
treetel = 0 for y = 0 to 8 read p$ for x = 1 to 10 if mid$( p$ , x , 1 ) = "T" then t( x , y ) = tree treetel = treetel + 1 end if next x y( y ) = val( right$( p$ , 1 ) ) next y read p$ for x = 1 to 10 x( x ) = val( mid$( p$ , x , 1 ) ) next x for x = 1 to 10 for y = 0 to 8 if neartree( x , y ) then t( x , y ) = empty end if next y next x restore data "T T T 2" data " T T2" data " 1" data " T T 3" data " TT1" data " 2" data " T T T T1" data " T T 3" data " T T 1" data " T T T4" data "2212322132" for no = 0 to 200 for x = 1 to 10 for y = 0 to 8 if t( x , y ) = empty then if rnd(0) < treetel / 90 then gen( in( no , x , y ) ) = tent end if end if next y next x next no for i = 0 to 200 ry( i ) = i next i
done = 0 tel = 0 while not( done ) if fitness( ry( 0 ) ) = 0 then done = 1 tel = tel + 1 if tel > 1000 then done = 1 for i = 0 to 200 fout( i ) = fitness( i ) next i for h = 1 to 200 for l = 0 to h - 1 if fout( ry( h ) ) < fout( ry( l ) ) then help = ry( h ) ry( h ) = ry( l ) ry( l ) = help end if next l next h for i = 20 to 200 a = rnd.int( 0 , 20 ) b = rnd.int( 0 , 20 ) call crossover ry( a ) , ry( b ) , ry( i ) if rnd(0) < .1 then call mutate ry( i ) end if next i print tel , fout( ry( 0 ) ) wend for y = 0 to 8 for x = 1 to 10 select case gen( in( ry(0) , x , y ) ) case tree print "T" ; case tent print "A" ' case else print "." ; end select next x print y( y ) next y for i = 1 to 10 print x( i ) ; next i print print "[ game over ]" end function fitness( no ) uit = 0 for x = 1 to 10 tel = 0 for y = 0 to 8 if gen( in( no , x , y ) ) = tent then tel = tel + 1 end if next y uit = uit + abs( tel - x( x ) ) next x for y = 0 to 8 tel = 0 for x = 1 to 10 if gen( in( no , x , y ) ) = tent then tel = tel + 1 end if next x uit = uit + abs( tel - y( y ) ) next y fitness = uit end function function neartree( x , y ) uit = 0 if x + 1 <= 10 then if t( x + 1 , y ) = tree then uit = 1 end if if x - 1 >= 1 then if t( x - 1 , y ) = tree then uit = 1 end if if y + 1 <= 8 then if t( x , y + 1 ) = tree then uit = 1 end if if y - 1 >= 0 then if t( x , y - 1 ) = tree then uit = 1 end if neartree = uit end function function rnd.int( l , h ) rnd.int = int( rnd(0) * ( h - l + 1 ) + l ) end function function in( no , x , y ) in = no * 100 + x * 9 + y end function sub crossover a , b , uit for x = 1 to 10 for y = 0 to 8 if rnd(0) < .5 then z = gen( in( a , x , y ) ) else z = gen( in( b , x , y ) ) end if gen( in( uit , x , y ) ) = z next y next x end sub sub mutate no x = rnd.int( 1 , 10 ) y = rnd.int( 0 , 8 ) while gen( in( no , x , y ) ) = tree _ or gen( in( no , x , y ) ) = notent x = rnd.int( 1 , 10 ) y = rnd.int( 0 , 8 ) wend if gen( in( no , x , y ) ) = empty then gen( in( no , x , y ) ) = tent else gen( in( no , x , y ) ) = empty end if end sub
|
|
|
Post by B+ on Jul 24, 2018 15:47:41 GMT
Hi bluatigro,
Your code needs some scans, in case someone grows tired trying to figure out what this does before it gets around to finishing.
Here is more helpful info:
The rules are very simple. Each tree has one tent attached to it and each tent is attached to a tree either horizontally or vertically. No tents are adjacent to each other, either horizontally, vertically or diagonally. At the beginning of the puzzle you are shown all the trees and then need to deduce where each tent is. To help you, the number of tents in each row and column is displayed.
Looks Sudoku like on Internet but blu appears to be evolving a solution by trial and error.
|
|