我可以用什么数据结构来垄断卡片 [英] what data structure can I used for cards in monopoly

查看:80
本文介绍了我可以用什么数据结构来垄断卡片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我们的任务是制作一个垄断模拟器,其中最终输出是玩家降落最多的前五名,所以不再涉及金钱了在这个计划中。我只需要实施这些牌,所以如果玩家落在社区胸前或者他们将能够移动到棋盘上的正确位置。



你能推荐吗?我可以用于卡的数据结构??我正在考虑使用堆栈,这样可以吗?



we were tasked to make a monopoly simulatot wherein the final output is the top 5 places where players landed the most so there is no money involved anymore in this program. I just need to implement the cards so if the players land on community chest or chance they will be able to move to the correct place on the board.

can you recommend a data structure that I can use for the cards?? I was thinking about using stack, would that be ok?

推荐答案

堆栈可能是一个糟糕的选择:记住它是一堆卡,所以当你从一个卡中删除一个顶部你最后用它做什么?在真实世界的游戏中,你遵守卡片,然后将它返回到堆的底部。



使用堆栈,这意味着弹出所有项目,并在添加一张卡后再次插入它们。你可能想要开始查看队列,在那里你将卡片添加到尾部,然后从头部删除它们。
A stack is probably a poor choice: remember that it's a pile of cards so when you remove one from the top what do you do with it at the end? In the real-world game you obey the card, and then you return it to the bottom of the pile.

With a stack, that means popping all the items off, and inserting them back on again after you add the one card. You might want to start looking at a queue instead, where you add cards to the tail, and remove them from the head.


这篇关于我可以用什么数据结构来垄断卡片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆