.data
currentState: .asciiz "This is the current state of the GameBoard:\n"
playerOne: .asciiz "Player One won\n"
playerTwo: .asciiz "Player Two won\n"
playerNone: .asciiz "No winners found\n"
CR: .byte '\n
SPACE: .byte 0x20
O: .byte 'o
X: .byte 'x
DOT .byte '.
# enable only one at a time to test your code
# it should detect the win for the designated player
#
gameBoard: .byte 0,0,0,0,0,0,0,0,0 # no winner
#gameBoard: .byte 1,1,1,0,0,0,0,0,0 # player one wins - by row 0
#gameBoard: .byte 0,0,0,-1,-1,-1,0,0,0 # player two wins - by row 1
#gameBoard: .byte 0,0,0,0,0,0,-1,-1,-1 # player two wins - by row 2
#gameBoard: .byte 1,0,0,1,0,0,1,0,0 # player one wins - by col 0
#gameBoard: .byte 0,1,0,0,1,0,0,1,0 # player one wins - by col 1
#gameBoard: .byte 0,0,-1,0,0,-1,0,0,-1 # player two wins - by col 2
#gameBoard: .byte 1,0,0,0,1,0,0,0,1 # player one wins - by diag 0
#gameBoard: .byte 0,0,-1,0,-1,0,-1,0,0 # player two wins - by diag 1
.code
.globl main
##########################################################################
# CheckTriplet
# Check the gameboard positions matching the triplet passed in
# to determine either player has won that specific triplet.
#
# Input:
# $a0 : first position to check on gameboard
# $a1 : second position to check on gameboard
# $a2 : third position to check on gameboard
#
# Output:
# $v0 : 0 = no winner found
# $v0 : 1 = player one won
# $v0 : -1 = player two won
# AS WELL AS an appropriate message if player one or player two has won
#
##########################################################################
CheckTriplet:
# ENTER YOUR CODE HERE
done: jr $ra
##########################################################################
# CheckForWin
# Invoke CheckTriplet against the 8 possible winning combinations
# to determine if anyone has won the game yet
# row 0
# row 1
# row 2
# col 0
# col 1
# col 2
# diagonal 0
# diagonal 1
#
# Output:
# $v0 : 0 = no winner found
# $v0 : 1 = player one won
# $v0 : -1 = player two won
##########################################################################
CheckForWin:
addi $sp,$sp,-4 # make room on the stack for our variables
sw $ra,0($sp) # save our return address
# ENTER YOUR CODE HERE
doneCFW: lw $ra,0($sp) # restore our return address
addi $sp,$sp,4 # free the room we have taken on the stack
jr $ra # return from function
##########################################################################
# PRINTBOARD
##########################################################################
PrintBoard:
# COPY YOUR PAST IMPLEMENTATION HERE
##########################################################################
# MAIN
##########################################################################
main:
jal PrintBoard
jal CheckForWin
bnez $v0,finished
la $a0,playerNone # if no winners found, for now, just say so and exit
syscall $print_string
finished: syscall $exit