| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> perl >> gong neng feng fu de Perl: yi chuan suan fa fang zhen duo xi bao ji ti

gong neng feng fu de Perl: yi chuan suan fa fang zhen duo xi bao ji ti

2008-05-19 06:25:39 编辑來源:互联网 评论
 
 
 
本文为【功能丰富的Perl:遗传算法仿真多细胞机体】的拼音翻译版
  wo de qian liang pian guan yu shi yong Perl shi xian yi chuan suan fa (GA) de wen zhang ( shen yue shen kao zi liao ) jiang shu de shi ge ti xi bao de bian yi yu sheng ming zhou qi , ta de shi he du (fitness) wan quan yi lai yu ta men zi ji de DNA。 ben wen jiang jie shao ru he fang zhen yi ge duo xi bao ji ti 。 ju ti de ying yong cheng xu jiang hui sheng cheng you qi fu duo xing he zheng que xing jue ding de zi mi (letter puzzles)。 yao huo de GA de bei jing zhi shi , nin ying gai qu shen kao xian qian de liang pian wen zhang 。
  ge ti xi bao shi zi mi zhong de zi mu kuai (letter tiles)。 ta men de shi he du jiang qu jue yu ta men yu suo you qi ta xi bao de zu he , suo yi , zai ying yong yu shang xia wen zhi qian , xi bao DNA ben shen mei you yi yi 。 er qie , DNA bi xu jiao chang , dan bing bu fu duo 。 ta zhi shi yao gao su wo men ren yi yi ge te ding xi bao ke neng hui lian jie dao na xie zi mu , dang ran , ta ye hui gao su wo men zhe ge te ding xi bao de zi mu ( ye ke neng shi yi ge kong kuai )。
  na me , rang wo men lai kai shi she ji !
  fang zhen she ji
  you liang fang mian ji ben she ji 。 shou xian shi ge ti xi bao de she ji , qi ci shi xi bao jian jiao hu de she ji 。 wo jiang cong ge ti xi bao kai shi jiang qi 。
  ben zhi shang , mei ge xi bao dou shi zong heng pin zi mi (crossword puzzle) zhong de yi ge zi mu 。 na jiang shi DNA de yi ge pian duan 。 er qie , DNA jiang jue ding yi ge xi bao yu qi ta zi mu de shi he cheng du 。 zhe yang , dui ying wen zong heng zi mi lai shuo ,“an” he “he” jiang shi he shi de zu he , er “xz” jiang bu shi 。 zhe bing bu shi shuo “xz” bu ke neng chu xian , er zhi shi shuo shi yong ta sheng cheng de zong heng zi mi mei you duo gao de jia zhi 。 wo jiang shi yong yi ge ci dian , zhe ge ci dian mo ren wei yu GNU/Linux xi tong de /usr/share/dict/words zhong ( zhi shao zai wo de Debian xi tong zhong shi zhe yang ―― fou ze , ke yi shi yong whereis huo locate ming ling lai zhao dao ta , bing xiang ying di xiu gai $words_file)。
  xi bao zhi jian de jiao hu jiang fa sheng zai yi ge N cheng N de zi mi zhong , qi zhong N zai ming ling xing zhong gei ding , mo ren wei 10。 zai ren he shi ke dou hui you N^2 ge xi bao bei xuan zhong , liu xia N*2 ge xi bao ( suo yi , zai yi ge 10x10 zi mi de xun huan zhou qi zhong , zong gong you 120 ge xi bao )。 zhe xie shu zi shi ren yi de , bu tai chong yao , zhi bu guo , yi ge da de “ wu xian zhi ” de chi jiang shi xi bao xuan ze de zhi de shi he du jiang di , er yi ge xiao de chi jiang xian zhi yuan su de ji hui 。
  nin ying gai ji zhu , zhe li de mu biao bu shi sheng cheng “ zheng que ” de jie jue fang an ―― mei you zhe yang de jie jue fang an 。 mu biao shi fang zhen xi bao zhi jian de jiao hu , te bie yao zhu yi ping heng zi mu xi bao suo xu yao de kong kuai xi bao 。
  cong chu shi xi bao chi zhong dui xi bao de xuan ze you zi mu guan lian xing lai wan cheng 。 ru guo zai zi mi ban (puzzle board) shang mei you qi ta xi bao , na me ren he xi bao dou shi ke yi de 。 bu guo , ru guo cheng xu zheng zai wei yi ge yu “A” he “Q” xiang lin de kuai lai xuan ze xi bao , na me “A” he “Q” de xi bao guan lian xing jiu you guan xi le 。 yin ci , xi bao guan lian xing shi DNA de yi ge ji ben bu fen , he xi bao de zi mu yi yang shou dao bian yi de ying xiang 。 xi bao guan lian xing de fan wei shi 0 dao 255, suo yi ke yi fang bian di you DNA de yi ge zi jie lai miao shu ta 。
  zui hou , wo jiang huan cun xi bao suo gou cheng de ci 。 wo bu hui cai yong zhe zhong jian dan de fang fa : xuan chu mei ge kuai bing zhi chu ta gou cheng na xie ci 。 nin xiang zhi dao wei shen me ma ? yin wei wo shi guo na zhong fang fa , wei le de dao zheng que de fang fa , lang fei le hao duo ge xiao shi de shi jian , er qie ta bing bu kuai !
  wo de fang fa shi , cong zuo dao you , cong shang dao xia dui mi ban jin xing sao miao ( liang bian , zhe shi wei le de dao chui zhi fang xiang he shui ping fang xiang de ci )。 dang zhao dao yi ge ci hou , wo hui ji zhu gou cheng na ge ci de xi bao , ran hou jiang na ge ci tian jia dao suo you na xie xi bao de ci huan cun zhong 。 ci huan cun shi yi ge shu zu , bu shi san lie biao , fan yang chu shi shi shang tong yi ge ci ke yi chu xian zai shui ping fang xiang shang , ye ke yi chu xian zai chui zhi fang xiang shang , dan xi bao zhi neng gui yu yi ge zhe yang de ci 。 dui yu wei bu zu dao de xi bao lai shuo , na jiang shi ji qi bu gong ping de 。
  dui yu mi ban er yan , ta shi yi ge jian dan de san lie biao 。 wo chang shi guo shi yong qian tao shu zu lai fang zhen yi ge ju zhen , bu guo mei you bi yao na me ma fan 。 wo zhi xu yao shi yong yi ge ju you x y jian de jian dan san lie biao jiu ke yi wan cheng fang zhen 。 wei yi suo xu yao de yang she shi xy2index() han shu ; wo bian xie le yi ge ming wei index2xy() de fan xiang yang she han shu , dan shi mei bi yao shi yong ta 。
  yu xian qian wen zhang de bu tong zhi chu
  ben wen zhong de cheng xu shi wo xian qian zhuan xie de liang pian yi chuan suan fa wen zhang zhong GA fang zhen cheng xu de gai jin ban ben 。 ji yu du zhe Matt Neuberg de jian yi , yi ji wo ben ren de jing yan , wo zuo le yi xie xiu gai 。
  select_parents() shi bu yan ge de , yin wei ta jiang bu shi he de qin ben (parents) liu zai zhong qun (population) zhong , ji shi ta men de shi he du wei 0, bu ke neng bei xuan ze 。 wei le jiu zheng na yi dian , wo tian jia le yi ge e wai de grep() tiao yong 。
  recombine() han shu
  wo ying gai ti xing nin , ji yu qin ben de shi he du , qin ben zhong qun bao han you dui qin ben de duo ge yin yong 。 qin ben yue shi he , zai qin ben zhong qun zhong chu xian de ci shu jiu hui duo , yin er jiu hui you geng duo ji hui fan zhi xia qu 。
  recombine() shi yong List::Util shuffle() han shu lai sui ji zu he qin ben zhong qun 。 zhe yang zuo de xiao guo hao yu xuan ze sui ji qin ben bing bao chi dui na xie yi jing shi qin ben de zhui zong 。 ling wai , yi qian di er ge qin ben shi sui ji xuan ze chu lai de , er qie wo ren wei zhe yang shi dui yan hua de xiang dang zhun que de miao shu , dan shi wo gai bian le na zhong fang fa , tong guo jiang ta men cong qin ben zhong qun zhong xuan ze chu lai ran hou zai cha ru hui qu de fang shi , ji yu ta men de shi he du lai xuan ze di er ge qin ben 。
  qing dan 1. recombine() han shu
  sub recombine
  {
  my $population = shift @_;
  my $pop_size = scalar @$population;# population size
  my @parent_population;
  my @new_population;
  my $total_parent_slots = 0;
  $total_parent_slots += $_-{parent}
  foreach @$population;
  my $position = 0;
  foreach my $individual (@$population)
  {
  foreach my $parenting_opportunity (1 .. $individual-{parent})
  {
  push @parent_population, $individual;
  }
  $individual-{parent} = 0;
  }
  @parent_population = shuffle @parent_population;
  while (1)
  {
  # this could result in a parent breeding with itself, which is not a big deal
  my $parent = shift @parent_population;
  my $parent2 = shift @parent_population;
  my $out_of_parents = 0;
  # when we're out of parents...
  unless (defined $parent2)
  {
  $parent2 = $parent;
  $out_of_parents = 1;
  }
  my $child = { survived = 1, parent = 0, fitness = 0, dna = 0 };
  # this is breeding!
  my $dna1 = $parent-{dna};
  my $dna2 = $parent2-{dna};
  # note we do operations on BYTES, not BITS.
  This is because bytes
  # are the unit of information (and preserving them is the faster
  # breeding method)
  foreach my $byte (1 .. $dna_byte_length)
  {
  # get one byte from either parent (the parent choice is random) and add it to the child
  vec($child-{dna}, $byte-1, 8) = vec(((rand()
  }
  push @new_population, $child;# the child is now a part of the new generation
  push @parent_population, $parent2;# use the second parent again, but at the tail end
  last if $out_of_parents;
  }
  return \@new_population;
  }
  zhu yi , ru guo zui hou yi ge qin ben qia hao shi zi qin ben zhong qun zhong huo de de , ying gai ru he qu she zhi $out_of_parents; na shi tiao chu qin ben xuan ze xun huan de wei yi tu jing 。
  gou jian zi mi
  zi mi wang ge you xiang ying de ming wei build_puzzle() de han shu lai gou jian 。 zhong qun zhong de mei yi ge ge ti xi bao dou zai nei bu cun chu le yi ge wang ge wei zhi , suo yi , dang wo xiang yao zhao dao mou ge xi bao de wang ge wei zhi shi , bu bi sou suo wang ge huo zhe wei chi yi ge wai bu san lie biao 。 mei yi ge ge ti huan yong you yi ge “ dan ci ” shu zu yin yong , zai zhe ge shu zu zhong bao chi you zai yan sheng guo cheng zhong na ge ge ti sheng cheng de dan ci 。
  ling wai , wo wei mei ge xi bao fu yu le yi ge ID shu xing , bu guo zhi shi shi yong ta lai jian cha suan fa de zheng que xing 。
  zai build_puzzle() zhong , suo you de ge ti dou an zhi yu @puzzle_population。 wo zuo le yi ge @puzzle_population de kao bei , zhe yang wo ke yi cong ta li mian qu shan chu ge ti , yi shi de dui ge ti de gai bian bu hui shi yong jiu de ―― ta shi yi ge qian kao bei (shallow copy)。 xuan ze kuai de shun xu shi sui ji de , zai ci shi yong le List::Util::shuffle()。 zhu yi , suo you de wei zhi dou cun chu zai yi ge [x,y] shu zu zhong 。 na yang , shu ju ke yi xiang dan yi de shen shu yi yang chuan di , er bu shi duo ge shen shu 。
  qing dan 2. build_puzzle() han shu
  sub build_puzzle
  {
  my $population = shift @_;
  my @puzzle_population = @$population;# make a local copy we can alter
  my $i = 0;
  foreach (@puzzle_population)
  {
  $_-{id} = $i++;
  $_-{position} = undef;
  $_-{words} = [];
  }
  my $puzzle = {};
  my @positions;
  foreach my $row (0 .. $size-1)
  {
  foreach my $column (0 .. $size-1)
  {
  push @positions, [$row, $column];
  }
  }
  foreach my $p (shuffle @positions)
  {
  my $row
  = $p-[0];
  my $column = $p-[1];
  my $cell =
  choose_tile(\@puzzle_population, $puzzle, $p);
  $cell-{position} = $p;
  $puzzle-{xy2index($p)} = $cell;
  }
  return $puzzle;
  }
  zhu yi , shang mian de recombine() he build_puzzle() zhong , yi ji cheng xu suo you qi ta wei zhi , dou mei you lei si yu $i de ji shu qi 。 you yu Perl mei you nei cun fen pei wen ti , suo yi dui wo lai shuo que xian de zui zhu yao lai yuan jiu shi zhui zong ji shu qi bian liang de cuo wu ( cuo wu de chu shi hua , cuo wu de zeng liang , huo zhe cuo wu de bian jie )。 zhe bing bu shi shuo wo zai bian xie Perl cheng xu de shi hou chu xian le hen duo que xian , zhi shi wo fa xian ji shu qi bian liang hui zeng jia shi yong shi chu xian que xian de ke neng xing 。
  xian zai deng chang de shi choose_tile()。 zi mi zhong de mei yi ge wang ge wei zhi dou hui tiao yong ta lai xuan ze yi ge jiang cheng wei zi mi kuai de xi bao 。 zai wei wang ge
  【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
   wo de qian liang pian guan yu shi yong Perl shi xian yi chuan suan fa (GA) de wen zhang ( shen yue shen kao zi liao ) jiang shu de shi ge ti xi bao de bian yi yu sheng ming zhou qi , ta de shi he du (fitness) wan quan yi lai yu ta men zi ji de DNA。 ben wen jiang jie shao ru he fang zhen yi ge duo xi bao ji ti 。 ju ti de ying yong cheng xu jiang hui sheng cheng you qi fu duo xing he zheng que xing jue ding de zi mi (letter puzzles)。 yao huo de GA de bei jing zhi shi , nin ying gai qu shen kao xian qian de liang pian wen zhang 。    ge ti xi bao shi zi mi zhong de zi mu kuai (letter tiles)。 ta men de shi he du jiang qu jue yu ta men yu suo you qi ta xi bao de zu he , suo yi , zai ying yong yu shang xia wen zhi qian , xi bao DNA ben shen mei you yi yi 。 er qie , DNA bi xu jiao chang , dan bing bu fu duo 。 ta zhi shi yao gao su wo men ren yi yi ge te ding xi bao ke neng hui lian jie dao na xie zi mu , dang ran , ta ye hui gao su wo men zhe ge te ding xi bao de zi mu ( ye ke neng shi yi ge kong kuai )。    na me , rang wo men lai kai shi she ji !    fang zhen she ji    you liang fang mian ji ben she ji 。 shou xian shi ge ti xi bao de she ji , qi ci shi xi bao jian jiao hu de she ji 。 wo jiang cong ge ti xi bao kai shi jiang qi 。    ben zhi shang , mei ge xi bao dou shi zong heng pin zi mi (crossword puzzle) zhong de yi ge zi mu 。 na jiang shi DNA de yi ge pian duan 。 er qie , DNA jiang jue ding yi ge xi bao yu qi ta zi mu de shi he cheng du 。 zhe yang , dui ying wen zong heng zi mi lai shuo ,“an” he “he” jiang shi he shi de zu he , er “xz” jiang bu shi 。 zhe bing bu shi shuo “xz” bu ke neng chu xian , er zhi shi shuo shi yong ta sheng cheng de zong heng zi mi mei you duo gao de jia zhi 。 wo jiang shi yong yi ge ci dian , zhe ge ci dian mo ren wei yu GNU/Linux xi tong de /usr/share/dict/words zhong ( zhi shao zai wo de Debian xi tong zhong shi zhe yang ―― fou ze , ke yi shi yong whereis huo locate ming ling lai zhao dao ta , bing xiang ying di xiu gai $words_file)。    xi bao zhi jian de jiao hu jiang fa sheng zai yi ge N cheng N de zi mi zhong , qi zhong N zai ming ling xing zhong gei ding , mo ren wei 10。 zai ren he shi ke dou hui you N^2 ge xi bao bei xuan zhong , liu xia N*2 ge xi bao ( suo yi , zai yi ge 10x10 zi mi de xun huan zhou qi zhong , zong gong you 120 ge xi bao )。 zhe xie shu zi shi ren yi de , bu tai chong yao , zhi bu guo , yi ge da de “ wu xian zhi ” de chi jiang shi xi bao xuan ze de zhi de shi he du jiang di , er yi ge xiao de chi jiang xian zhi yuan su de ji hui 。    nin ying gai ji zhu , zhe li de mu biao bu shi sheng cheng “ zheng que ” de jie jue fang an ―― mei you zhe yang de jie jue fang an 。 mu biao shi fang zhen xi bao zhi jian de jiao hu , te bie yao zhu yi ping heng zi mu xi bao suo xu yao de kong kuai xi bao 。    cong chu shi xi bao chi zhong dui xi bao de xuan ze you zi mu guan lian xing lai wan cheng 。 ru guo zai zi mi ban (puzzle board) shang mei you qi ta xi bao , na me ren he xi bao dou shi ke yi de 。 bu guo , ru guo cheng xu zheng zai wei yi ge yu “A” he “Q” xiang lin de kuai lai xuan ze xi bao , na me “A” he “Q” de xi bao guan lian xing jiu you guan xi le 。 yin ci , xi bao guan lian xing shi DNA de yi ge ji ben bu fen , he xi bao de zi mu yi yang shou dao bian yi de ying xiang 。 xi bao guan lian xing de fan wei shi 0 dao 255, suo yi ke yi fang bian di you DNA de yi ge zi jie lai miao shu ta 。    zui hou , wo jiang huan cun xi bao suo gou cheng de ci 。 wo bu hui cai yong zhe zhong jian dan de fang fa : xuan chu mei ge kuai bing zhi chu ta gou cheng na xie ci 。 nin xiang zhi dao wei shen me ma ? yin wei wo shi guo na zhong fang fa , wei le de dao zheng que de fang fa , lang fei le hao duo ge xiao shi de shi jian , er qie ta bing bu kuai !    wo de fang fa shi , cong zuo dao you , cong shang dao xia dui mi ban jin xing sao miao ( liang bian , zhe shi wei le de dao chui zhi fang xiang he shui ping fang xiang de ci )。 dang zhao dao yi ge ci hou , wo hui ji zhu gou cheng na ge ci de xi bao , ran hou jiang na ge ci tian jia dao suo you na xie xi bao de ci huan cun zhong 。 ci huan cun shi yi ge shu zu , bu shi san lie biao , fan yang chu shi shi shang tong yi ge ci ke yi chu xian zai shui ping fang xiang shang , ye ke yi chu xian zai chui zhi fang xiang shang , dan xi bao zhi neng gui yu yi ge zhe yang de ci 。 dui yu wei bu zu dao de xi bao lai shuo , na jiang shi ji qi bu gong ping de 。    dui yu mi ban er yan , ta shi yi ge jian dan de san lie biao 。 wo chang shi guo shi yong qian tao shu zu lai fang zhen yi ge ju zhen , bu guo mei you bi yao na me ma fan 。 wo zhi xu yao shi yong yi ge ju you x y jian de jian dan san lie biao jiu ke yi wan cheng fang zhen 。 wei yi suo xu yao de yang she shi xy2index() han shu ; wo bian xie le yi ge ming wei index2xy() de fan xiang yang she han shu , dan shi mei bi yao shi yong ta 。    yu xian qian wen zhang de bu tong zhi chu    ben wen zhong de cheng xu shi wo xian qian zhuan xie de liang pian yi chuan suan fa wen zhang zhong GA fang zhen cheng xu de gai jin ban ben 。 ji yu du zhe Matt Neuberg de jian yi , yi ji wo ben ren de jing yan , wo zuo le yi xie xiu gai 。   select_parents() shi bu yan ge de , yin wei ta jiang bu shi he de qin ben (parents) liu zai zhong qun (population) zhong , ji shi ta men de shi he du wei 0, bu ke neng bei xuan ze 。 wei le jiu zheng na yi dian , wo tian jia le yi ge e wai de grep() tiao yong 。   recombine() han shu    wo ying gai ti xing nin , ji yu qin ben de shi he du , qin ben zhong qun bao han you dui qin ben de duo ge yin yong 。 qin ben yue shi he , zai qin ben zhong qun zhong chu xian de ci shu jiu hui duo , yin er jiu hui you geng duo ji hui fan zhi xia qu 。   recombine() shi yong List::Util shuffle() han shu lai sui ji zu he qin ben zhong qun 。 zhe yang zuo de xiao guo hao yu xuan ze sui ji qin ben bing bao chi dui na xie yi jing shi qin ben de zhui zong 。 ling wai , yi qian di er ge qin ben shi sui ji xuan ze chu lai de , er qie wo ren wei zhe yang shi dui yan hua de xiang dang zhun que de miao shu , dan shi wo gai bian le na zhong fang fa , tong guo jiang ta men cong qin ben zhong qun zhong xuan ze chu lai ran hou zai cha ru hui qu de fang shi , ji yu ta men de shi he du lai xuan ze di er ge qin ben 。    qing dan 1. recombine() han shu   sub recombine   {   my $population = shift @_;   my $pop_size = scalar @$population; # population size   my @parent_population;   my @new_population;   my $total_parent_slots = 0;   $total_parent_slots += $_-{parent}   foreach @$population;   my $position = 0;   foreach my $individual (@$population)   {   foreach my $parenting_opportunity (1 .. $individual-{parent})   {   push @parent_population, $individual;   }   $individual-{parent} = 0;   }   @parent_population = shuffle @parent_population;   while (1)   {   # this could result in a parent breeding with itself, which is not a big deal   my $parent = shift @parent_population;   my $parent2 = shift @parent_population;   my $out_of_parents = 0;   # when we're out of parents...   unless (defined $parent2)   {   $parent2 = $parent;   $out_of_parents = 1;   }   my $child = { survived = 1, parent = 0, fitness = 0, dna = 0 };   # this is breeding!   my $dna1 = $parent-{dna};   my $dna2 = $parent2-{dna};   # note we do operations on BYTES, not BITS.   This is because bytes   # are the unit of information (and preserving them is the faster   # breeding method)   foreach my $byte (1 .. $dna_byte_length)   {   # get one byte from either parent (the parent choice is random) and add it to the child   vec($child-{dna}, $byte-1, 8) = vec(((rand()   }   push @new_population, $child; # the child is now a part of the new generation   push @parent_population, $parent2; # use the second parent again, but at the tail end   last if $out_of_parents;   }   return \@new_population;   }    zhu yi , ru guo zui hou yi ge qin ben qia hao shi zi qin ben zhong qun zhong huo de de , ying gai ru he qu she zhi $out_of_parents; na shi tiao chu qin ben xuan ze xun huan de wei yi tu jing 。    gou jian zi mi    zi mi wang ge you xiang ying de ming wei build_puzzle() de han shu lai gou jian 。 zhong qun zhong de mei yi ge ge ti xi bao dou zai nei bu cun chu le yi ge wang ge wei zhi , suo yi , dang wo xiang yao zhao dao mou ge xi bao de wang ge wei zhi shi , bu bi sou suo wang ge huo zhe wei chi yi ge wai bu san lie biao 。 mei yi ge ge ti huan yong you yi ge “ dan ci ” shu zu yin yong , zai zhe ge shu zu zhong bao chi you zai yan sheng guo cheng zhong na ge ge ti sheng cheng de dan ci 。    ling wai , wo wei mei ge xi bao fu yu le yi ge ID shu xing , bu guo zhi shi shi yong ta lai jian cha suan fa de zheng que xing 。    zai build_puzzle() zhong , suo you de ge ti dou an zhi yu @puzzle_population。 wo zuo le yi ge @puzzle_population de kao bei , zhe yang wo ke yi cong ta li mian qu shan chu ge ti , yi shi de dui ge ti de gai bian bu hui shi yong jiu de ―― ta shi yi ge qian kao bei (shallow copy)。 xuan ze kuai de shun xu shi sui ji de , zai ci shi yong le List::Util::shuffle()。 zhu yi , suo you de wei zhi dou cun chu zai yi ge [x,y] shu zu zhong 。 na yang , shu ju ke yi xiang dan yi de shen shu yi yang chuan di , er bu shi duo ge shen shu 。    qing dan 2. build_puzzle() han shu   sub build_puzzle   {   my $population = shift @_;   my @puzzle_population = @$population; # make a local copy we can alter   my $i = 0;   foreach (@puzzle_population)   {   $_-{id} = $i++;   $_-{position} = undef;   $_-{words} = [];   }   my $puzzle = {};   my @positions;   foreach my $row (0 .. $size-1)   {   foreach my $column (0 .. $size-1)   {   push @positions, [$row, $column];   }   }   foreach my $p (shuffle @positions)   {   my $row   = $p-[0];   my $column = $p-[1];   my $cell =   choose_tile(\@puzzle_population, $puzzle, $p);   $cell-{position} = $p;   $puzzle-{xy2index($p)} = $cell;   }   return $puzzle;   }    zhu yi , shang mian de recombine() he build_puzzle() zhong , yi ji cheng xu suo you qi ta wei zhi , dou mei you lei si yu $i de ji shu qi 。 you yu Perl mei you nei cun fen pei wen ti , suo yi dui wo lai shuo que xian de zui zhu yao lai yuan jiu shi zhui zong ji shu qi bian liang de cuo wu ( cuo wu de chu shi hua , cuo wu de zeng liang , huo zhe cuo wu de bian jie )。 zhe bing bu shi shuo wo zai bian xie Perl cheng xu de shi hou chu xian le hen duo que xian , zhi shi wo fa xian ji shu qi bian liang hui zeng jia shi yong shi chu xian que xian de ke neng xing 。    xian zai deng chang de shi choose_tile()。 zi mi zhong de mei yi ge wang ge wei zhi dou hui tiao yong ta lai xuan ze yi ge jiang cheng wei zi mi kuai de xi bao 。 zai wei wang ge   
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
华丽的模特拍摄(8)
华丽的模特拍摄(7)
华丽的模特拍摄(6)
华丽的模特拍摄(5)
八里沟
朝阳宫
天下峨眉 云上金顶
老家(四)
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有