espace

how to increment this function ?

Recommended Posts

hi,

assuming i have this :

var wait = function (callback, duration) {
	setTimeout(callback, duration);
}

    wait(() => { o.paper[0].body.moves = false }, o.opponent_actions[0])
    wait(() => { o.paper[0].body.moves = true }, 100 + o.opponent_actions[0])
    wait(() => { o.paper[0].body.moves = false }, o.opponent_actions[0] + o.opponent_actions[1])
    wait(() => { o.paper[0].body.moves = true }, 200 + o.opponent_actions[0] + o.opponent_actions[1])
    wait(() => { o.paper[0].body.moves = false }, o.opponent_actions[0] + o.opponent_actions[1] + o.opponent_actions[2])
//etc....
how to automate that depending of o.opponent_actions.length?

Share this post


Link to post
Share on other sites

a loop in a loop maybe? i have no idea what your code tries to achieve, nor am i a professional programmer. here is pseudo code that roughly shows how i would try to automate it

for(let j = 0; j < o.opponent_actions.length; ++j)
{
    let summed_actions = 0;
    for(let i = 0; i < j; ++i) summed_actions += o.opponent_actions[i];
    wait(() => { o.paper[0].body.moves = false; }, summed_actions);
    wait(() => { o.paper[0].body.moves = true; }, 100 + j*100 + summed_actions);
}

or maybe

for(let j = 0; j < o.opponent_actions.length*2; ++j)
{
    let summed_actions = 0;
    for(let i = 0; i < j/2; ++i) summed_actions += o.opponent_actions[i];
    if(j % 2 == 1) summed_actions += 50 + j*50;
    wait(() => { o.paper[0].body.moves = j % 2 == 1; }, summed_actions);
}

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.