Ah ok thanks Jim. Fortunately the connect4 game is all done and dusted now
and I have moved on to something more complex i.e a 3D rugby game hehe

Thanks for all your help

Paul

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of jim
Sent: 05 November 2006 20:58
To: 'Flashcoders mailing list'
Subject: RE: [Flashcoders] OT conver java code to flash

Sorry, been off a couple of days. It doesn't need the % anymore as they
modulus was giving the rand.nextInt() an upper bound of 10000 but not we are
multiplying the Math.random() by 10000 which rives a similar result.

Jim

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Paul Steven
Sent: 03 November 2006 14:19
To: 'Flashcoders mailing list'
Subject: RE: [Flashcoders] OT conver java code to flash

Thanks Jim, I had overlooked that fact and is probably why the game is not
behaving correctly.

Just to clarify, does it still need the "%" operator.

The java code is:

if (Math.abs(rand.nextInt()) % 10000 < (10000 / numOfEqual))
          bestXPos = i;
}

And what you suggested was:

var intUpperBound :Number = 10000;

if(Math.abs(Math.random()*intUpperBound) < (intUpperBound /numOfEqual)) {

        bestXPos = i; 
}

Should it be the following to be equivalent to the java functionality?

var intUpperBound :Number = 10000;

if(Math.abs(Math.random()*intUpperBound) % 10000 < (intUpperBound
/numOfEqual)) {

        bestXPos = i; 

}

Thanks

Paul



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of jim
Sent: 03 November 2006 13:52
To: 'Flashcoders mailing list'
Subject: RE: [Flashcoders] OT conver java code to flash

Its not quite just a random choice. I think that the other variables affect
what is happening here. The numOfEqual is filtering the returned number to
make sure that the bestXPos is always larger than the last one (I think)

So if we take this and enter some actual values on say the third loop
through:

Step 1:

numOfEqual++;

if(Math.abs(Math.random()*intUpperBound) < (intUpperBound / numOfEqual))
{
        bestXPos = i; 
}

Step 2:

3;

if(Math.abs(0.333*10000) < (10000/ 3))
{
        bestXPos = i; 
}

Step 3:

3;

if(3330 < 3333.33333333333)
{
        bestXPos = i; 
}

So you see in that case the Math.random() returned 0.333 so the resulting
number allowed you to pass the if statement but if it had been 0.334 or more
it would not have let you pass so bestXPos would not have been set.

The function you are using now is just giving you a 50/50 chance of passing
but the old java function was giving you variable odds depending on how many
passes had been performed.

Hope you understand as I am not great at explaining these things

Jim





-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Paul Steven
Sent: 03 November 2006 13:35
To: 'Flashcoders mailing list'
Subject: RE: [Flashcoders] OT conver java code to flash

Thanks Jim. I was curious as I have seen Math.rand() mentioned on various
flash forums and even on one of the macromedia / adobe live docs page. But I
guess these were just mistakes by people familiar with Java.

For my particular need, I have just simplified it to

if (Math.abs(Math.random()) < (0.5)) {
        bestXPos = i; 
}

As I was not sure what exactly the Java code did but realised it simply
wanted to implement making a random choice.

Thanks

Paul

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of jim
Sent: 03 November 2006 13:17
To: 'Flashcoders mailing list'
Subject: RE: [Flashcoders] OT conver java code to flash

It is Math.random() sorry. The Math.random() function returns a number
between 1 & 0. The Java function that you are using returns a random integer
or whole number, I don think there is an upper bound to it.

The rest of your function is getting the modulus of the random number which
in fact is setting the upper bound to 10000.

So to get the same sort of function you will need to set what upper bound
you want, I will use 10000 for now. I havnt tested this but it should give a
similar result.

var intUpperBound :Number = 10000;

if(goodness == bestWorst)
{
        numOfEqual++;

      if(Math.abs(Math.random()*intUpperBound) < (intUpperBound /
numOfEqual)) {

                bestXPos = i; 

        }

}

Hth
Jim

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Paul Steven
Sent: 02 November 2006 23:15
To: 'Flashcoders mailing list'
Subject: RE: [Flashcoders] OT conver java code to flash

Thanks Jim

It is AS2, and the context is below. Btw what is the difference between
Math.rand() and Math.random()?

// ---------------------------------------------------
// If two moves are equally good, make a random choice
// ---------------------------------------------------

if (goodness == bestWorst) {

      numOfEqual++;

      if (Math.abs(rand.nextInt()) % 10000 < (10000 / numOfEqual)) {

                bestXPos = i; 

        }

}

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of jim
Sent: 02 November 2006 22:50
To: 'Flashcoders mailing list'
Subject: RE: [Flashcoders] OT conver java code to flash

Which version of actionscript? And in whats the context? 

The only thing that dosnt look like it will directlty port over is the
rand.nextInt() but you can use Math.rand() the rest is basic maths stuff you
can do in actionscript.

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Paul Steven
Sent: 02 November 2006 17:15
To: 'Flashcoders mailing list'
Subject: [Flashcoders] OT conver java code to flash

Not familiar with Java code but trying to rewrite some code in Flash. Anyone
convert this line to flash actionscript please

if (Math.abs(rand.nextInt()) % 10000 <
        (10000 / numOfEqual)) 
        bestXPos = i;

Thanks

Paul

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to