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.
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:
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.