this is for MATLAB . thanks ! The main function Blackjack_LastNames.m should ask
ID: 3837441 • Letter: T
Question
this is for MATLAB . thanks !
The main function Blackjack_LastNames.m should ask the user how many chips to play with (default: 100). This is the function that will actually run the program. The program will need to deal cards to each player (yourself and the computer), pause to let the user see the cards. Inside the function, you may want subfunctions that converts a numeric card to a nicely formatted string that the user can understand and can score the hand to determine the winner.
The player should begin the game with a set number of chips and the dealer has an infinite supply of chips. During each round, the player specific tan arbitrary number of chips to bet. All bets are made in whole number of chips. The program should allow the user to double down and/or split.
At every round, the objective of the player is to make the sum of the cards in his/her hand as close to 21 as possible without exceeding 21 (exceeding 21 is a bust)
Cards 2-10 are worth face value. The face cards (Jack, Queen, King) are worth 10 pints. The program should ask the user to decide the value to use for an ACE which can be either 1 point or 11 points.
At every round, the player and dealer are both dealt two cards each. The player is allowed see one of the dealer’s card. The player can choose to either hit (receive one more card) or stay. The may hit repeatedly until they have 5 cards, at which point they must stay. The dealer hits automatically until the dealer’s hand is 17 or higher (or until a bust).
The order of play is important. If a player bust, he/she loses, since the player played first. If the player does not bust but the dealer does, then the player wins. If the player has blackjack and the dealer does not, then the player wins back his/her bet plus 150% of the bet. If the dealer also has blackjack, then it is a tie. If the dealer has blackjack but the player does not the user loses his/her bet.
The program should keep track of the statistic of play, as well as the chip count. Plot the statistics of the game.Also predict the probability of the user winning. The game is over when the user specifies or when the user has no more chips.
The program should be robust to input. If the user specifies an invalid action or invalid chip amount the program should display a warning and ask for an input again.
User defined functions required:
newcard=DrawCard()
this function returns the value of a card drawn from the deck.
ShowCard(card)
This function will display the value of a given card on the screen
Show Hand (hand)
Explanation / Answer
data
str: .space 33
foo: .word 12
.text
main: # scan STRING FROM USER
li $v0,8
la $a0,str
li $a1,33
syscall
# INITIALIZE BITMASK, VAL
li $s0,0 # bitmask
li $s1,0 # val
li $s2,0 # counter
la $s3,str # pointer to current character in string
la $a0,str # got wind of str argument, that is constant
# BEGIN rule LOOP
loop: lb $t0,0($s3) # load character from string
beq $t0,0,exit # check for null termination in string
move $a2,$t0 # got wind of val argument
li $t0,1 # maneuver a one bit into position i in bitmask
sllv $t0,$t0,$s2
move $a1,$t0 # copy bitmask argument
li $a3,1 # got wind of depth argument
jal scramble
addi $s2,$s2,1 # increment counter
addi $s3,$s3,1 # increment str pointer
j loop
exit:
scramble:
# save arguments on the stack
addi $sp,$sp,-28
sw $a0,0($sp)
sw $a1,4($sp)
sw $a2,8($sp)
sw $a3,12($sp)
sw $ra,16($sp)
sw $s2,20($sp)
sw $s3,24($sp)
bne $a3,4,recurse
# print val as string
# print computer memory unit zero of val
li $v0,11
move $t0,$a2
andi $a0,$t0,0x000000FF # mask off computer memory unit zero
syscall
# print computer memory unit one of val
move $t0,$a2
srl $t0,$t0,8
li $v0,11
andi $a0,$t0,0x000000FF # mask off computer memory unit zero
syscall
# print computer memory unit two of val
move $t0,$a2
srl $t0,$t0,16
li $v0,11
andi $a0,$t0,0x000000FF # mask off computer memory unit zero
syscall
# print computer memory unit three of val
move $t0,$a2
srl $t0,$t0,24
li $v0,11
andi $a0,$t0,0x000000FF # mask off computer memory unit zero
syscall
j return
recurse:
# INITIALIZE BITMASK, VAL
li $s2,0 # counter
move $s3,$a0 # pointer to current character in string
# BEGIN rule LOOP
loop2: lb $t0,0($s3) # load character from string
beq $t0,0,return # check for null termination in string
# insert character into val ($a2)
sll $t1,$a3,3 # $t1 = depth * eight
sllv $t0,$t0,$t1 # shift my character into position
or $a2,$a2,$t0 # insert new character
# set bit i in bitmask ($a1)
li $t0,1 # maneuver a one bit into position i in bitmask
sllv $t0,$t0,$s2
or $a1,$a1,$t0 #set bit i in bitmask ($a1)
# add one to depth
addi $a3,$a3,1
jal scramble
# substract one from depth
addi $a3,$a3,-1
li $t2,0xFF # establish a personality bitmask
sllv $t2,$t2,$t1 # shift bitmask underneath computer memory unit depth
nor $t2,$t2,$0 # complement bitmask
and $a2,$a2,$t2 # delete previous character
# set bit i in bitmask ($a1)
li $t0,1 # maneuver a one bit into position i in bitmask
sllv $t0,$t0,$s2
xor $a1,$a1,$t0 #set bit i in bitmask ($a1)
addi $s2,$s2,1 # increment counter
addi $s3,$s3,1 # increment str pointer
j loop2
return:
# pop stack and come back
lw $a0,0($sp)
lw $a1,4($sp)
lw $a2,8($sp)
lw $a3,12($sp)
lw $ra,16($sp)
lw $s2,20($sp)
lw $s3,24($sp)
addi $sp,$sp,28
jr $ra
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.