I have to derive my own equation, I

  • Context: Undergrad 
  • Thread starter Thread starter eNathan
  • Start date Start date
  • Tags Tags
    Derive
Click For Summary

Discussion Overview

The discussion revolves around deriving an equation to determine whose turn it is in a multiplayer game based on the number of players, turns taken, and the number of consecutive turns each player has. Participants explore mathematical formulations and test various equations to achieve this goal.

Discussion Character

  • Mathematical reasoning
  • Exploratory
  • Technical explanation

Main Points Raised

  • One participant describes the problem of determining the current player's turn (variable p) given the total number of players (P'), total turns (T), and turns per player (e).
  • Another participant proposes an equation: p=ceiling(T/e)+P-floor[ceiling(T/e)+P-1/P]*P, suggesting it could solve the problem.
  • A different formulation is presented as ASCII: p = Ceil(T/e)+P-1-Floor((Ceil(T/e)+P-1)/P)*P+1, with the contributor expressing uncertainty about its accuracy.
  • One participant attempts to validate the proposed equations with specific values for P, e, and T, noting that the results were unpredictable with one of the equations.
  • Another participant suggests simplifying the equation by removing unnecessary terms and confirms that their revised equation should theoretically work, providing a specific example to illustrate its application.
  • Concerns are raised about the equation's performance with higher numbers, indicating potential issues with the logic or order of operations.
  • One participant suggests using temporary variables to clarify the calculations, which leads to a successful outcome for another participant who confirms the effectiveness of the revised approach.

Areas of Agreement / Disagreement

Participants express differing views on the effectiveness of the proposed equations, with some finding success while others encounter issues. The discussion remains unresolved regarding the optimal formulation, as multiple approaches are tested without consensus.

Contextual Notes

Participants highlight potential limitations in their equations, including the need for careful attention to order of operations and the handling of specific cases. There are indications that the equations may not perform consistently across all scenarios.

eNathan
Messages
351
Reaction score
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
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:
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 :)
 
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:
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...
 
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
 
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
 
Sorry for the late reply, but yes that did work. Thank you very much, now I can finish my software :)
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 22 ·
Replies
22
Views
2K
  • · Replies 7 ·
Replies
7
Views
1K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 29 ·
Replies
29
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
8K