I have to derive my own equation, I

  • Thread starter eNathan
  • Start date
  • Tags
    Derive
In summary, the conversation revolved around creating an equation to determine which player's turn it is in a multiplayer game, given the number of players (P'), the number of turns each player gets in a row (e), and the total number of turns that have taken place (T). The equation provided was p = ceiling(T/e) + P - floor((ceiling(T/e) + P - 1) / P) * P, which was confirmed to work for various values of P, e, and T. The conversation also included attempts to simplify the equation and troubleshoot any potential issues. Ultimately, the equation was successfully used to complete the programming of the software.
  • #1
eNathan
352
2
I am programming a software which generates random (or close too) numbers. I am adding a multi-player feature to it. I ask the user how many players there are (variable P'), and how many turns in a row each player gets (variable e, for every). I also know the total amount of global turns that have taken place in the game (variable T).

Each player gets there turn via least to greatest. Player "1" goes first, and gets to play for "e" amount of times. Each time any player takes a turn, variable "T" increases by +1. How do I know who's turn is (variable p) given the values of P', T, and e? I make algerbra equations all the time, but I have been struggling with this for days and I just can't seem to get it. I hope somebody here is good enough at mathematics to derive an equation from this. I know you have to use the Fix() function in it, and you probably have to divide T by P' somewhere. But I do not have the equation :cry: I will draw a chart of how the game will fold out.



P' = 2 (it's a two player game) e=1 (Each player gets to play one time in a row)

remember...T = Total turns in the game p = Who's turn it should be

T p
-------
1 1
2 2
3 1
4 2
5 1
6 2
7 1


P' = 2 (it's a two player game) e=2 (Each player gets to play two times in a row)

remember...T = Total turns in the game p = Who's turn it should be

T p
-------
1 1
2 1
3 2
4 2
5 1
6 1
7 2

P' = 2 (how many players there are) e=3 (Each player gets to play three times in a row)

remember...T = Total turns in the game p = Who's turn it should be

T p
-------
1 1
2 1
3 1
4 2
5 2
6 2
7 1

again, I need to know p with only knowing "P'", "T", and "e". If I can draw a diagram of it on paper, I know it can be done mathematically :smile:

Thank you very much
 
Mathematics news on Phys.org
  • #2
A bit trickier than I first thought...

[tex]p=ceiling(\frac{T}{e})+P-floor[\frac{ceiling(\frac{T}{e})+P-1}{P}]*P[/tex]

where ceiling(x) is the least integer greater than or equal to x, and floor(x) is the greatest integer less than or equal to x.
 
Last edited:
  • #3
ASCII = p = Ceil(T/e)+P-1-Floor((Ceil(T/e)+P-1)/P)*P+1
I hope lol I am going to try it right now :)
 
  • #4
nope, that one gave some very upredictable results. Your first one was closer to working, unless...I typed the equation wrong. Is this right?
p = Ceil(T/e)+P-1-Floor((Ceil(T/e)+P-1)/P)*P
 
Last edited:
  • #5
You don't need the +1-1 in there... I cleaned that up a little while ago. It came from the method I was using.

I think that equation should theoretically work. Try some cases by hand.

Let's try P=3, e=2, T=7.

T p
1 1
2 1
3 2
4 2
5 3
6 3
7 1
8 1

So, p should equal 1.

ceiling(T/e)=ceiling(7/2)=4
floor((4+P-1)/P) = floor(6/3)=2
2*3=6
4+3-6=1
Thus Ceil(T/e)+P-Floor((Ceil(T/e)+P-1)/P)*P = 1, like it should.

Not sure what the problem is...
 
  • #6
but when you try that with higher numbers, everything goes wrong. I think I can fix your equation if I think about it enough, but I have to get some sleep. I will give you my results.

When T = 1, p = 2
When T = 2, p = 2
When T = 3, p = 3
When T = 4, p = 3
When T = 5, p = 4
When T = 6, p = 4
When T = 7, p = 5
 
  • #7
I'm not sure what's going on then.

Ceil(T/e)+P-Floor((Ceil(T/e)+P-1)/P)*P works for every number I try. Maybe order of operations isn't followed?

Try temporary variables, like
a=T/e
b=Ceil(a)
c=(b+P-1)/P
d=Floor(c)*P

p=b+P-d
 
  • #8
Sorry for the late reply, but yes that did work. Thank you very much, now I can finish my software :)
 

1. What is the process for deriving my own equation?

The process for deriving your own equation involves understanding the principles and theories related to the topic, identifying the variables involved, and using mathematical techniques such as algebra, calculus, and statistics to create a relationship between the variables.

2. How do I choose the right variables for my equation?

Choosing the right variables for your equation depends on the problem you are trying to solve and the data available. It is important to select relevant and measurable variables that have a direct impact on the outcome of the equation.

3. Can I use existing equations to derive my own equation?

Yes, you can use existing equations as a starting point for deriving your own equation. However, it is important to understand the limitations and assumptions of the existing equation and make necessary modifications to fit your specific problem.

4. What are some common mistakes to avoid when deriving my own equation?

Some common mistakes to avoid when deriving your own equation include not clearly defining the problem, using incorrect or irrelevant variables, and making incorrect assumptions about the relationship between the variables. It is also important to check the units and dimensions of your equation to ensure accuracy.

5. How can I test the validity of my derived equation?

To test the validity of your derived equation, you can use real-world data to see if the equation accurately predicts the outcome. You can also compare your equation to existing equations or theories to see if it aligns with established principles. Additionally, peer review and feedback from other scientists can help evaluate the validity of your equation.

Similar threads

Replies
4
Views
641
Replies
9
Views
2K
Replies
6
Views
1K
Replies
2
Views
4K
Replies
1
Views
477
Replies
2
Views
226
Replies
4
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
7
Views
1K
  • Calculus and Beyond Homework Help
Replies
29
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
Back
Top