multi-dimensional array

I currently track a stat on 10 players in a single dimensional array like this:

1
2
3
4
5
6
7
8
9
10
11
12
int player_vpip [10];

void process_vpip()
{
	for (int n = 0; n < 10; n++)
	{
		if ((player[n].cards > 0)
		{
			player_vpip[n] = int (player_vpip[n]) + 1;
		}
	}
}


When I look up this stat, I just divide the result by the number of hands in the game to get the percentage.
Perfect, everything workst great.

Now I want to track the same stat on the same 10 players BUT limit it to the last 20 hands of the game.

I am not sure how to do this. I am sure I need to create another array, like:

int player_vpip_history [20] [10];

But I am not sure how, after 20 hands, I drop off the oldest data and move everything "up" so that the newest
data is in "row" 20.
This is my stab at it. It will move each row down starting with row 19 which I can deal with. I will then write the most current record in row 0. This process should run once for each player (10 players).

Does this look correct?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int vpip_history[20][10];

void process_history()	// keeps a history of vpip for the last 20 hands (newest hand [0][0-9])
{
	// for each player
	for (int p = 0; p < 10; p++)
	{
		// Move all elements up one position.  i is destination.
		for (int i = 19; i > 0; i--)
		{
			vpip_history[p][i] = vpip_history[p][i-1];
		}
	}
}
Last edited on
I'm not gonna lie i've never actually used this before but you might be better off using a queue.

http://www.cplusplus.com/reference/stl/queue/

You can check at the beggining whether the queue is empty, and using its size function can check if the queue contains 20 elements and if so, use the delete function to delete the element 20 inputs ago.
Last edited on
Topic archived. No new replies allowed.