douxi4114 2011-09-10 22:45 采纳率: 100%
浏览 23
已采纳

实现作业集合的最佳算法是什么?

This is what I'm trying to achieve. I have a set of 50 different jobs (by class I mean, soldier, mage, monk, etc)

Each user randomly gets a card each time he/she completes a quest. So at certain point you can have a soldier and a monk, but a mage will be missing. That means your collection will look like

Soldier    Yes
Mage       No
Monk       Yes

At anytime you can get the same card (you can have 10 soldiers, but for your collection is only a yes or no)

At anytime you can drop the job. But you keep the job "collected" Therefore if you drop a Soldier the collection will look like this

Soldier    Yes
Mage       No
Monk       Yes

If you notice, even if I don't have a Soldier right now. I have already "collected" that job.

I was thinking about what would be the best way to implement this in MySQL and PHP?

Mi ideas right now are 2 1. create a new table collection and keep one record for each job you get. 2. create just one field with pipes as separators and implode/explode results

  • 写回答

3条回答 默认 最新

  • douzhang8840 2011-09-10 22:56
    关注

    Why don't you use a single bitmask column.

    Say Soldier = 1, Mage = 2, Monk = 4.

    Thus if you have only mage and monk the value would be 2 | 4 = 6.

    This way you allow yourself to easily add different classes later, without the need to change the schema.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 写uniapp时遇到的问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流