dswqz24846 2010-09-23 06:22
浏览 47
已采纳

寻找合适的数据结构来操纵游戏中的玩家统计数据

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

  • 写回答

1条回答 默认 最新

  • dps57553 2010-09-23 06:36
    关注

    One thing that may be worthwhile is to generate a player statistics object. This object could either be a collection of "statistic objects" ie. handicaps, skills etc. If you do it this way you can encapsulate all of your work. For example, each object could have it's own chance_of_success method that you could call without having to worry about the specifics of that object.

    I'm not sure which version of php you are using but the manual for classes/objects is here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮