I'm planning to store player stats in a database for a game, and need to find a suitable data structure for testing against them in the code. The structure needs to work well in php, but I'm interested in any ideas for learning purposes.
In this first iteration of pseudo-code, I'm imagining multi-dimensional arrays for the data-structures, but don't think they're good enough. What other structures are available and how can the program access them efficiently as the number of stats and keys required to find each stat grow larger?
Pseudo-code: Everything is on a scale of 1 to 10
$player_base_skill_level
{
[driving] = 4
[running] = 6
}
$handicaps
{
[driving][monster_trucks] = -5
[running][long_distance] = -3
}
//User wants to drive a monster truck
$action[base_action] = 'driving'
$action[sub1_action] = 'monster_trucks'
function chance_of_success($action)
{
$degree_of_difficulty = 8;
$player_actual_skill_level = $player_base_skill_level[$base_action] + $handicaps[$base_action][$sub1_action];
if($player_actual_skill_level > $degree_of_difficulty = 8)
return 'success';
else
return 'failure';
}
The array keys will grow out of control in this solution as things get more complex; example: [driving][monster_trucks][large_wheels] or [driving][monster_trucks][small_wheels], so there must be a better way to structure the data.
Thanks