生成随机移动:点和盒子游戏:MIPS

时间:2015-05-09 23:00:13

标签: random printing mips

我正在尝试写一个双人玩家Dots and Boxes游戏。我很难为计算机生成随机数并在电路板上打印相同的数字。 任何帮助都会有所帮助。 用户的代码工作正常但不是计算机移动。

computerMove:
    li $a0, 0           # Set $a to int 0
    li $a1, 99          # Set upperbound to 99
    li $v0, 42          # Call Random Int Range
    syscall
    add $a0, $a0, 48        # add 48, since 0 starts at 48

    li $v0, 1           # Printing $a0 to verify -- Generates wrong number
    syscall

    li $s0, 50          # Flag
    li $s1, 97          # Setting $s1 to 'a'
    beq $a0, 97, placePiece     # if $a0 is 'a' then placePience

    li $s1, 98          # Setting $s1 to 'b'
    beq $a0, 98, placePiece     # if $a0 is 'b' then placePiece

    move $s1, $a0           # moving $a0 to $s1 for placePiece
    bgt $a0, 57 computerMove    # if $a0 greater 57 then continue
    j placePiece            # else placePiece

placePiece:
    move $t0, $s1
    # Placing Values    
    lb $t1, addr($t0)
    lb $t2, mark($t0)
    sb $t2, board($t1)
    j printBoard

printBoard:
    la $a0, board
    li $v0, 4
    syscall
    beq $s0, 50, continue
    j computerMove


.data

board:      .ascii   "\n\n   . . .          . 0 . 1 ."
            .ascii     "\n                  2   3   4"
            .ascii     "\n   . . .          . 5 . 6 ."
            .ascii     "\n                  7   8   9"
            .asciiz    "\n   . . .          . a . b .\n"

addr:       .byte       6,   8,  33,  35,  37,  62,  64,  89,  91,  93,  118, 120
mark:       .byte       '-', '-', '|', '|', '|', '-', '-', '|', '|', '|', '-', '-'
box:        .byte       34,  36,  90,  92

0 个答案:

没有答案