DB设计问题-多人游戏

发布于 2024-10-09 15:58:53 字数 742 浏览 2 评论 0原文

我是数据库设计的新手。我正在尝试编写一款棋盘游戏(最多 4 名玩家),并试图想出一种在彼此之间交流动作的方法。 我根据 stackoverflow 上的建议使用数据库。

我的问题是这样的 - 当玩家 A 采取行动时,该行动必须由 B、C 和 D 读取。因此,A 采取行动的事实需要传达给 B、C 和 D。我按照以下方式进行。请告诉我是否有更好的方法。对我来说,这一切似乎都是错误的,而且非常脆弱。

我有一个包含以下字段的表 -

gameId、userMove、flagA、flagB、flagC、flagD

因此,当 A 进行移动时,我会在其他内容中写入 - (flagA=0, flagB=1, flagC=1, flagD=1)

当B、C 或 D 读取 A 的移动,并减少相应的标志。

除非所有标志都为 0,否则 A 不会更新表。

当其他人采取行动时,也会发生同样的情况。

评论?为此必须有更好的方法。我在这里看到错误的事情 -

  • 我在选择上循环,直到 A 的所有标志都为 0
  • 我在选择上循环,直到将相应用户的标志设置为读取移动。

我需要担心大量的服务器负载和客户端超时。

我希望我能够清楚地解释我的问题。如果需要请提问。

任何帮助表示赞赏。

编辑:该游戏是基于网络的(在浏览器中运行),我使用 php 进行服务器端开发,因此我无法使用内存缓存,尽管如果可能的话我很乐意这样做。

谢谢, - 帕夫

I am new to DB design. I am trying to write a board game (4 players max) and was trying to come up with a way to communicate moves among each other.
I am using a DB for this as per suggestions on stackoverflow.

My problem is this - When player A makes a move that move has to be read by B,C and D. So the fact that A made the move needs to be communicated to B,C and D. I am doing it the following way. Please tell me if there is a better way to do it. To me it seems all wrong and incredibly flaky.

I have a table with the following fields -

gameId, userMove, flagA, flagB, flagC, flagD

So when A makes the move I write among other things - (flagA=0, flagB=1, flagC=1, flagD=1)

When B,C or D read A's move they decrement their corresponding flag.

A will not update the table unless all flags are 0.

Same thing happens when others make their moves.

Comments? There has to be a better way for this. The things I am seeing wrong here -

  • I am looping on a select until all flags are 0 for A
  • I am looping on a select until the flag for the corresponding user is set to read the move.

That is a lot of server load and client timeouts I need to worry about.

I hope I have been able to explain my problem clearly. Please ask questions if needed.

Any help is appreciated.

EDIT: The game is web based (runs in a browser) and I am using php for the server side development and so I cannot use an in-memory cache though I would have loved to do that if possible.

Thanks,
- Pav

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

瞳孔里扚悲伤 2024-10-16 15:58:53

如果您的游戏玩家将在单个游戏会话期间与一个游戏服务器进行交互,那么您似乎可以将所有这些状态保留在内存中。

数据库非常适合持久存储数据,并保证原子性、一致性和完整性。但是,对于您所描述的时间状态,您似乎不需要任何这些功能。

If the players of your game will be interacting with one game server during a single game session, it looks like you can keep all that state in memory.

Databases are great for durable storage of data with guarantees for atomicity, consistency and integrity. However, you don't seem to need any of these features for the temporal state that you are describing.

淡看悲欢离合 2024-10-16 15:58:53

如果 flagA、B、C 和 D 都是位,您可能会考虑将它们全部放入一列中,并将该列视为位掩码。

这将允许一列控制所有标志。它可以使您的选择和更新更加清晰。

在此处阅读有关使用位掩码的信息:

If flagA,B,C and D are all bits you might consider putting them all into one column and treating that column as a bit mask.

This will allow one column to control all flags. It can make your selects and updates much cleaner.

Read up on using bitmasks here:

回忆追雨的时光 2024-10-16 15:58:53

您是否考虑过使用文件来存储信息?

Have you considered usng a file to store the info?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文