I have to derive my own equation, I need help

  • Thread starter eNathan
  • Start date
  • #1
352
1
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 cant 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
 

Answers and Replies

  • #2
367
1
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
352
1
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
352
1
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
367
1
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
352
1
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
367
1
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
352
1
Sorry for the late reply, but yes that did work. Thank you very much, now I can finish my software :)
 

Related Threads on I have to derive my own equation, I need help

  • Last Post
Replies
3
Views
3K
  • Last Post
Replies
3
Views
2K
  • Last Post
Replies
10
Views
9K
Q
Replies
1
Views
1K
  • Last Post
Replies
13
Views
2K
  • Last Post
Replies
17
Views
2K
  • Last Post
Replies
8
Views
2K
Replies
1
Views
2K
  • Last Post
Replies
5
Views
1K
  • Last Post
Replies
14
Views
3K
Top