Jump to content
  • Advertisement
Sign in to follow this  

Non-physics math question

This topic is 3661 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, I'm not sure if this is the correct place to ask this question, but this sub-forum has Math in the name so I'm gonna go with it :) I'm wanting to add bonus items to a web browser RPG. After the player is done with an adventure, he is shown a page with his increase in gold and experience, and also a decrease in HP. I want to add bonus items on top of that. Right now, my idea is to limit the available bonus items based on the level of the player as well as the class of the item, and then later based on the type of adventure taken. Unfortunately, I'm not so skilled with the math involved, so I was wondering if someone knew what subjects I need to study up on, and if there are examples out there that I might be able to glean from? Thanks for the help.

Share this post

Link to post
Share on other sites
Mikha, this forum is certainly an appropriate place to ask math questions, even if unrelated to physics. Let's leave the thread here for a while.

You might want to go browse the AI forum as well. There might be some similar discussions there. But...please do NOT post a duplicate thread over there. Wait and see if you get replies/recommendations here first. I can move the thread if it makes more sense to put it in AI.

Share this post

Link to post
Share on other sites
Hey, sorry to bring this thread back from the dead (though it's only 4 days old), but I figured I might garner some help if I show I'm actually putting a little work into it :)

First, here's the code I have.

(defun calculate-class-items (items &rest args)
"Chooses the bonus item based on the class. First, it finds out the classes
of all the items in a list, uses the lower and higher class definitions
to make a range which it then chooses from at random.

Example: Say that items is a list of 3 items. Let's says that they are the
following items with their class ranges:

Healing Potion, 1-15
Super Healing Potion, 15-30
Dragon Shield Deluxe, 28-31

calculate-class-items will create a range of 1-31 which it will then choose from
at random. If it chooses 5, then a healing potion is given to the player. If
it chooses 15, then it will then create a new list with just HP and SHP in it,
and then choose from those two at random using their item numbers as a range.

If HP's number is 1, and SHP's number is 5, then calculate-class-items will choose
from between those two numbers only."
(let ((items (get-class-items items))
(low-class (first (sort (loop for (a b) in items collect a collect b) #'<)))
(high-class (last (sort (loop for (a b) in items collect a collect b) #'<))))
;; decide-item chooses between multiple items using unique item numbers,
;; pick-class chooses between items using their class numbers
(decide-item (pick-class low-class high-class))))

It's in Common Lisp, in case you're wondering. Anyway, as you can see I use two different sets of numbers when deciding the bonus item. I have class ranges and then I have unique item numbers. If the function pick-class picks a class that only one item has, then decide-item won't do anything except continue on. Otherwise, if pick-class picks a class with more than one item with that class, then decide-item will decide which item to give based on unique item numbers.

Right now, the only thing I can think of is to randomly choose between the range, but I was wondering if there were better ways to do it?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!