简体   繁体   English

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

[英]Looking for a suitable data structure for manipulating player stats in a game

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. 该结构需要在php中正常工作,但我对出于学习目的的任何想法都感兴趣。

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 伪代码:所有内容的比例均为1到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. 例如:[driving] [monster_trucks] [large_wheels]或[driving] [monster_trucks] [small_wheels],因此必须有更好的数据结构方法。

Thanks 谢谢

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 我不确定您使用的是哪个版本的php,但有关类/对象的手册在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM