A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Methinks it is like a weasel...

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    5

    Methinks it is like a weasel...

    I am using ActionScript 2 (yeah, I know, it's outdated, but I'm so very accustomed to it), and I am trying to make a program similar to that of the Weasel Program by Richard Dawkins in the 1987 documentary "The Blind Watchmaker". Basically, a random string of letters is generated, with a target phrase it is trying to reach, and each time a letter is correct, it stays that way, and the rest of the string carries on guessing until the word is correct.

    So far, I've only gotten the string to generate random letters over and over again until it eventually just happens to get the target phrase and stop guessing. It's working fine, but all attempts to get it to work similar to the Weasel Program have failed. Here is the code I am using to make it guess over and over.

    Code:
    function generateRandomString(newLength:Number):String
    {
    	var a:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    	var alphabet:Array = a.split("");
    	var randomLetter:String = "";
    	for (var i = 0; i < newLength; i++)
    	{
    		randomLetter += alphabet[Math.floor(Math.random() * alphabet.length)];
    	}
    	return randomLetter;
    }
    
    _root.onEnterFrame = function()
    {
    	var finalString:String = "CRAIG";
    	var finalArray:Array = finalString.split("");
    	var weaselArray:Array = weasel_txt.text.split("");
    	if (weasel_txt.text != finalString)
    	{
    		weasel_txt.text = generateRandomString(5);
    	}
    	else
    	{
    		return;
    	}
    };
    The "weasel_txt" is a dynamic text box with that instance name. That's all the stage is set up with. I'm hoping somebody can get back to me as soon as possible.

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Found this on my trails, just paste it onto a frame and see.
    PHP Code:
    MyWord "CRAIG".split("");

    function 
    LetterSpin(Arg)
    {
        if (
    Arg 27)
        {
            return (
    chr(Arg 64));
        }
        if (
    Arg == 27)
        {
            return (
    " ");
        }
        if (
    Arg 27 && Arg 38)
        {
            return (
    Arg 28);
        }
        if (
    Arg 37)
        {
            return (
    chr(Arg 59));
        }
    }

    50;
    50;
    for (
    0MyWord.lengthi++)
    {
        
    Clip _root.createEmptyMovieClip("Clip" ii);
        
    Clip._x x;
        
    Clip._y y;
        
    Clip.Identity i;
        
    TheText Clip.createTextField("NewText"10000);
        
    TheText.autoSize true;
        
    Clip.Temp MyWord[i];
        
    Clip.LetterNow random(36);
        
    TheText.text MyWord[i];
        
    TheText._width;
        
    TheText.text LetterSpin(Clip.LetterNow);
        
    Clip.onEnterFrame = function()
        {
            
    this.LetterNow = ++this.LetterNow 64;
            
    this.NewText.text _root.LetterSpin(this.LetterNow);
            if (
    this.NewText.text == this.Temp && (this.Identity == || !_root["Clip" + (this.Identity 1)].onEnterFrame))
            {
                if (
    this.Identity == _root.MyWord.length 1)
                {
                    
    trace("DONE");
                }
                
    delete this.onEnterFrame;
            }
        };

    not exactly what you started doing ( which you got from Here) but nearly, play around with it.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center