MIPS有效地从数组中删除值

时间:2014-12-02 19:41:31

标签: arrays mips

我在MIPS Mars编写扑克牌。

下面是包含一副牌的数组。

cards:  .asciiz "2S","2C","2D","2H",
            "3S","3C","3D","3H",
            "4S","4C","4D","4H",
            "5S","5C","5D","5H",
            "6S","6C","6D","6H",
            "7S","7C","7D","7H",
            "8S","8C","8D","8H",
            "9S","9C","9D","9H",
            "10S","10C","10D","10H",
            "JS","JC","JD","JH",
            "QS","QC","QD","QH",
            "KS","KC","KD","KH",
            "AS","AC","AD","AH"

随着随机卡的选择并传递给播放器,我想从阵列中删除该卡。 为实现这一点,我想到了:

#use recursion to store the cards in another array up to the point of random card
#skip that random card space and continue storing.
#prepare to pass out next random card by decrementing random gen value by 1

这是我现在能想到的,但是想知道是否有人能想到更有效的方法。

1 个答案:

答案 0 :(得分:0)

如果订单不重要(并且它听起来不像),你可以移动最后一张卡"在牌组中"进入卡所占据的位置。如果你希望将来可以重新使用套牌,你可以交换这两个位置,这样你就可以在阵列中拥有所有52张牌。