MIPS 组装双陆棋棋盘游戏故障..

发布于 2024-12-26 13:41:31 字数 869 浏览 0 评论 0原文

我的架构类有一个作业,要在 MIPS 汇编中实现 31 个西洋双陆棋游戏,到目前为止我已经做了很多工作,并且我一直在使用 2 个数组来显示棋盘,例如我使用 0 来指示空字段和其他数字13 显示当前放置在该字段中的棋子数量,有白色棋子(使用正数表示)和红色棋子使用 1-15 的负数表示。 但是当我问我的教授时,他告诉我他希望棋盘在每次移动后都更新,并且应该看起来像这样:(请注意,在游戏开始时,所有棋子都放置在棋盘的末尾这是起始字段)


                             W1
                             W2
                             W3
                             W4
                             W5
                             W6
                             |
                            W15

                            R15
                            R14
                            R13
                            R12
                            R11
                            R10
                             |
                            R1

并且上面的棋盘应该在掷骰子后更新, 这意味着我将不得不使用某种数组来表示和移动这些 数字和字母。但我真的发现在单个数组中实现动态整数和字符很令人困惑。有什么建议吗? 感谢论坛。

I have an assignment for my architecture class which to implement a 31 backgammon game in MIPS assembly, I have done alot so far, and I have been using 2 arrays to display the board, I used 0s to indicate empty fields and other numbers for example 13 to display the number of checkers currently placed in that field, there are White checkers (represented using postive numbers) and Red Checkers are represented using negative numbers from 1-15.
But when I asked my professor , he told me that he wants the board to be updated after every move and it is supposed to look like this:(note that at the beginning of the game all the checkers are placed at the end of the board which is the starting field)


                             W1
                             W2
                             W3
                             W4
                             W5
                             W6
                             |
                            W15

                            R15
                            R14
                            R13
                            R12
                            R11
                            R10
                             |
                            R1

And the above board is supposed to be updated after dice roll ,
which means Im going to have to use some sort of array to represent and move those
numbers and letters. But im really finding it confusing to implement dynamic ints and characters in a single array. Any suggestions?
Thanks Forum.

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

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

发布评论

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

评论(1

做个ˇ局外人 2025-01-02 13:41:31

你是对的,将字符(R 或 W)和整数值存储在单个数组中将非常困难。从技术上讲,您已经将所有棋子堆栈的完整表示存储在数组中。如果您将整数上的符号位视为跳棋的颜色,那么您已经解决了问题。这是一个例子:

-5 = R5
12 = W12
1  = W1
-9 = R9

所以你看到你已经存储了颜色,但是你使用的是符号位而不是字符。现在您所要做的就是确定该数字是否有符号,并在该数字的绝对值之前显示相应的字符。

for( i = 0 ; i < myArray.length ; i++ )
{
  if( myArray[i] != 0 )
  {
        if( myArray[i] > 0 ) print( 'W' );
    elseif( myArray[i] < 0 ) print( 'R' );

    print( abs( myArray[i] ) );
  }
  else print( '|' );    
}

You're correct, storing both characters (R or W) and the integer value in a single array would be very difficult. Technically, you already are storing the entire representation of all the stacks of checkers in your array. If you think of the sign bit on your integer as the color of the checkers, you've already solved the problem. Here's an example:

-5 = R5
12 = W12
1  = W1
-9 = R9

So you see you're already storing the color, but you're using the sign bit instead of a character. Now all you have to do is determine if the number is signed or not and display the corresponding character before the absolute value of the number.

for( i = 0 ; i < myArray.length ; i++ )
{
  if( myArray[i] != 0 )
  {
        if( myArray[i] > 0 ) print( 'W' );
    elseif( myArray[i] < 0 ) print( 'R' );

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