Quantcast

Jump to content


Photo

Detect Trainable or not


  • Please log in to reply
6 replies to this topic

#1 Noitidart

Noitidart
  • Neocodex Co-Founder

  • 23214 posts


Users Awards

Posted 15 May 2010 - 09:18 AM

Hey i have quick request. This should be an easy function to write.
The function, given the stats of a pet (mov,str,def,hp,lvl) it should detect if it is trainable so then return 0. If it is not trainable return the number of levels it needs to gain before it becomes trainable please.

The stats should be provided via array please.

#2 jcrdude

jcrdude
  • Oh shit there's a thing here

  • 7001 posts


Users Awards

Posted 15 May 2010 - 09:40 AM

Hey i have quick request. This should be an easy function to write.
The function, given the stats of a pet (mov,str,def,hp,lvl) it should detect if it is trainable so then return 0. If it is not trainable return the number of levels it needs to gain before it becomes trainable please.

The stats should be provided via array please.



I'll put this in Javascript because I know it and you like it :3

function trainable(statArray)
{
	if(statArray[4]*2>statArray[0] && statArray[4]*2>statArray[1] && statArray[4]*2>statArray[2] && statArray[4]*2>statArray[3])
	{
		return 0
	}
	else
	{
		var temp=0
		temp = Math.max(statArray[0],statArray[1],statArray[2],statArray[3])
		return Math.ceil((temp/2)-statArray[4])
	}
}


//mov,str,def,hp,lvl
stats = [15,16,17,18,10]

alert(trainable(stats))

I haven't tested it, but it makes sense. If all stats are less than double the level, return 0... else find the highest stat, divide it by 2, subtract the current level, round up, then return the result that tells you how many levels need to be trained.

EDIT: Don't know why it put my parenthesis on the next line, but clearly it is attached to the previous line.

Edited by jcrboy, 15 May 2010 - 09:42 AM.


#3 Noitidart

Noitidart
  • Neocodex Co-Founder

  • 23214 posts


Users Awards

Posted 15 May 2010 - 10:43 AM

Oh hoo yes i do like js :D
Im looking for php as this is for neopost lol but id love a js version too. Ill test it out :D

Can we make another func please one that says if you can train hp or not. I think theres a 3*lvl+2 or something rule. I dont know it for sure. http://battlepedia.t.../Fast-Training/
Is that right?

#4 jcrdude

jcrdude
  • Oh shit there's a thing here

  • 7001 posts


Users Awards

Posted 15 May 2010 - 10:57 AM

Oh hoo yes i do like js :D
Im looking for php as this is for neopost lol but id love a js version too. Ill test it out :D

Can we make another func please one that says if you can train hp or not. I think theres a 3*lvl+2 or something rule. I dont know it for sure. http://battlepedia.t.../Fast-Training/
Is that right?


Technically, yes. I would ask Argue for the logic that got developed for the AutoTrainer. We know the stats that should be most efficient for training, it's just hard to perfect the order in which it should be done. Those stat bonuses REALLY like fucking you over. Also if you're doing a one pet training regiment, you would want to allow extra leeway in case you got Faerie Quests to make up some training points.

#5 Dan

Dan
  • Resident Know-It-All

  • 6382 posts


Users Awards

Posted 15 May 2010 - 11:00 AM

It's a bit of a code smell to have all of your pet's stats in one array - it's better to add more parameters on to your method.
function Trainable(strength, agility, level)
etc

#6 jcrdude

jcrdude
  • Oh shit there's a thing here

  • 7001 posts


Users Awards

Posted 15 May 2010 - 11:07 AM

It's a bit of a code smell to have all of your pet's stats in one array - it's better to add more parameters on to your method.

function Trainable(strength, agility, level)
etc


No idea what a code smell is, but I think I agree. I was just coding to the requested parameters.

#7 Dan

Dan
  • Resident Know-It-All

  • 6382 posts


Users Awards

Posted 15 May 2010 - 11:14 AM

No idea what a code smell is, but I think I agree. I was just coding to the requested parameters.


Code Smell - an issue with the code mostly, something you really want to avoid.

It kind-of falls under the entire premise of making your code readable -

function(strength, agility, level)
{
	strength.blahblfjdsif
}

function(detectedStrength, detectedAgility, detectedLevel)
is a hell of a lot more readable than:

function(arraystats)
{
	arraystats[0] // this is the strength
	arraystats[1] // this is the agility
}




2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users