/*
This script deciphers genetic code from a winning DNA
This will show all 243 rules and the DNA response to each rule for a given individual.
It is interesting to see that a winner doesn't pick up cans at the current location but manages to score near perfect.
It finds heuristics such as move to the leftmost can before picking any up.
Simply set @s to whichever DNA you want to decipher
*/
set nocount on
declare @rules table (n int, s int, e int, w int, c int, a int)
declare
@s varchar(243),
@i int,
@j int,
@k int,
@l int,
@m int
--480
set @s='545342243124124143344341032144140303220322010400042510042042141550511323440113015044025044201243550041415034540515145251531414434555055351111555424521443545143131144122531421053031415333223140432511051400244240224221041511122034531311435350154'
set @i=0
while @i <= 2
begin
set @j=0
while @j <= 2
begin
set @k=0
while @k <= 2
begin
set @l=0
while @l <= 2
begin
set @m=0
while @m <= 2
begin
insert into @rules
select @i, @j, @k, @l, @m, cast(substring(@s, (@i*81)+(@j*27)+(@k*9)+(@l*3)+@m+1,1) as int)
set @m = @m + 1
end
set @l = @l + 1
end
set @k = @k + 1
end
set @j = @j + 1
end
set @i = @i + 1
end
-- these are dead rules that never happen
delete from @rules where n=2 and s=2
delete from @rules where e=2 and w=2
-- what happens when there is a can in the current location? I would expect the action to always be 4:pickup but the smartie does not
-- for locations 0:empty 1:can 2:wall
-- for actions 0:n 1:s 2:e 3:w 4:pu 5:rnd
select * from @rules where c=1