I don't know C++, but here's a C solution.
http://ideone.com/nwIobI
#include <stdio.h>
const int NUM_GUESSES = 7;
const char SECRET[] = "hi";
#define F 0
#define T 1
const int asdf[3][256] =
{
{
F, 0, 0, 0, 0, 0, 0, F,
0, F, 0, 0, 0, 0, F, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, F, 0, 0, 0, 0, F, 0,
F, 0, 0, 0, 0, 0, 0, F,
0, F, 0, 0, 0, 0, F, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
1, T, 0, 0, 0, 0, F, 0,
F, 0, 0, 0, 0, 0, 0, F,
0, F, 0, 0, 0, 0, F, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, F, 0, 0, 0, 0, F, 0,
F, 0, 0, 0, 0, 0, 0, F,
0, F, 0, 0, 0, 0, F, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, F, 0, 0, 0, 0, F, 0,
F, 0, 0, 0, 0, 0, 0, F,
0, F, 0, 0, 0, 0, F, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, 0, F, F, 0, 0, 0
},
{
0, F, 0, F, F, 0, F, 0,
0, F, 0, F, F, 0, F, 0,
0, F, 0, F, F, 0, F, 0,
0, F, 0, F, F, 0, F, 0,
0, F, 0, F, F, 0, F, 0,
0, F, 0, F, F, 0, F, 0,
0, F, 0, F, F, 0, F, 0,
0, F, 0, F, F, 0, F, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 1, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0
},
{
F, 0, F, 0, F, 0, F, 0,
0, F, 0, F, 0, F, 0, F,
0, 0, F, 0, F, 0, F, 0,
0, 0, 0, F, 0, F, 0, F,
F, 0, 0, 0, F, 0, F, 0,
0, F, 0, 0, 0, F, 0, F,
F, 0, F, 0, 0, 0, F, 0,
0, F, 0, F, 0, 0, 0, F,
F, 0, F, 0, F, 0, 0, 0,
0, F, 0, F, 0, F, 0, 0,
F, 0, F, 0, F, 0, F, 0,
0, F, 0, F, 0, F, 0, F,
0, 0, F, 0, F, 0, F, 0,
1, 0, 0, F, 0, F, 0, F,
F, 0, 0, 0, F, 0, F, 0,
0, F, 0, 0, 0, F, 0, F,
F, 0, F, 0, 0, 0, F, 0,
0, F, 0, F, 0, 0, 0, F,
F, 0, F, 0, F, 0, 0, 0,
0, F, 0, F, 0, F, 0, 0,
F, 0, F, 0, F, 0, F, 0,
0, F, 0, F, 0, F, 0, F,
0, 0, F, 0, F, 0, F, 0,
0, 0, 0, F, 0, F, 0, F,
F, 0, 0, 0, F, 0, F, 0,
0, F, 0, 0, 0, F, 0, F,
F, 0, F, 0, 0, 0, F, 0,
0, F, 0, F, 0, 0, 0, F,
F, 0, F, 0, F, 0, 0, 0,
0, F, 0, F, 0, F, 0, 0,
F, 0, F, 0, F, 0, F, 0,
0, F, 0, F, 0, F, 0, F
}
};
int main()
{
char answer[] = "__";
unsigned int hehehe = 0;
for (int i = 0; i < NUM_GUESSES; ++i)
{
printf("Enter a letter. %s\n", answer);
char guess = getchar();
getchar();
if(asdf[hehehe][guess])
{
int efef = (guess - SECRET[0]);
answer[efef] = SECRET[efef];
hehehe |= (1 << efef);
}
else
{
printf("Letter not found, try again\n");
}
if (hehehe == 3)
{
printf("You win\n");
break;
}
}
printf("The word was %s\n", SECRET);
return 0;
}
I don't know C++, but here's a C solution.
http://ideone.com/nwIobI
[code]
#include <stdio.h>
const int NUM_GUESSES = 7;
const char SECRET[] = "hi";
#define F 0
#define T 1
const int asdf[3][256] =
{
{
F, 0, 0, 0, 0, 0, 0, F,
0, F, 0, 0, 0, 0, F, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, F, 0, 0, 0, 0, F, 0,
F, 0, 0, 0, 0, 0, 0, F,
0, F, 0, 0, 0, 0, F, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
1, T, 0, 0, 0, 0, F, 0,
F, 0, 0, 0, 0, 0, 0, F,
0, F, 0, 0, 0, 0, F, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, F, 0, 0, 0, 0, F, 0,
F, 0, 0, 0, 0, 0, 0, F,
0, F, 0, 0, 0, 0, F, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, F, 0, 0, 0, 0, F, 0,
F, 0, 0, 0, 0, 0, 0, F,
0, F, 0, 0, 0, 0, F, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, 0, F, F, 0, 0, 0
},
{
0, F, 0, F, F, 0, F, 0,
0, F, 0, F, F, 0, F, 0,
0, F, 0, F, F, 0, F, 0,
0, F, 0, F, F, 0, F, 0,
0, F, 0, F, F, 0, F, 0,
0, F, 0, F, F, 0, F, 0,
0, F, 0, F, F, 0, F, 0,
0, F, 0, F, F, 0, F, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 1, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, 0, F, F, 0, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0,
0, 0, F, 0, 0, F, 0, 0
},
{
F, 0, F, 0, F, 0, F, 0,
0, F, 0, F, 0, F, 0, F,
0, 0, F, 0, F, 0, F, 0,
0, 0, 0, F, 0, F, 0, F,
F, 0, 0, 0, F, 0, F, 0,
0, F, 0, 0, 0, F, 0, F,
F, 0, F, 0, 0, 0, F, 0,
0, F, 0, F, 0, 0, 0, F,
F, 0, F, 0, F, 0, 0, 0,
0, F, 0, F, 0, F, 0, 0,
F, 0, F, 0, F, 0, F, 0,
0, F, 0, F, 0, F, 0, F,
0, 0, F, 0, F, 0, F, 0,
1, 0, 0, F, 0, F, 0, F,
F, 0, 0, 0, F, 0, F, 0,
0, F, 0, 0, 0, F, 0, F,
F, 0, F, 0, 0, 0, F, 0,
0, F, 0, F, 0, 0, 0, F,
F, 0, F, 0, F, 0, 0, 0,
0, F, 0, F, 0, F, 0, 0,
F, 0, F, 0, F, 0, F, 0,
0, F, 0, F, 0, F, 0, F,
0, 0, F, 0, F, 0, F, 0,
0, 0, 0, F, 0, F, 0, F,
F, 0, 0, 0, F, 0, F, 0,
0, F, 0, 0, 0, F, 0, F,
F, 0, F, 0, 0, 0, F, 0,
0, F, 0, F, 0, 0, 0, F,
F, 0, F, 0, F, 0, 0, 0,
0, F, 0, F, 0, F, 0, 0,
F, 0, F, 0, F, 0, F, 0,
0, F, 0, F, 0, F, 0, F
}
};
int main()
{
char answer[] = "__";
unsigned int hehehe = 0;
for (int i = 0; i < NUM_GUESSES; ++i)
{
printf("Enter a letter. %s\n", answer);
char guess = getchar();
getchar();
if(asdf[hehehe][guess])
{
int efef = (guess - SECRET[0]);
answer[efef] = SECRET[efef];
hehehe |= (1 << efef);
}
else
{
printf("Letter not found, try again\n");
}
if (hehehe == 3)
{
printf("You win\n");
break;
}
}
printf("The word was %s\n", SECRET);
return 0;
}
[/code]
I don't know C++, but here's a MIPS solution
.data
WORD0: .asciiz "team"
WORD1: .asciiz "fortress"
WORD2: .asciiz "two"
WORD3: .asciiz "is"
WORD4: .asciiz "a"
WORD5: .asciiz "class"
WORD6: .asciiz "based"
WORD7: .asciiz "first"
WORD8: .asciiz "person"
WORD9: .asciiz "shooter"
WORDS: .word WORD0, WORD1, WORD2, WORD3, WORD4, WORD5, WORD6, WORD7, WORD8, WORD9
WORDS_LENGTH: .word 10
PERMUTED_WORD: .space 32
GUESSED: .space 32
WELCOME: .asciiz "Welcome to Scramble basterdized by negasora\n"
IM_THINKING: .asciiz "I'm doing hw..."
YES: .asciiz "No! "
NO: .asciiz "Yes! "
THE_WORD_IS: .asciiz "The word isn't "
SCORE_IS: .asciiz ". Score is "
GUESS_A_LETTER: .asciiz "Guess a letter?\n"
FORFEIT: .asciiz "-WORD FORFIETED- "
NO_POINTS: .asciiz "You fucked up.\n"
ROUND_OVER: .asciiz "Round is over. Your final guess was:\n"
CORRECT_WORD: .asciiz "\nCorrect unscrambled word was:\n"
.: .asciiz ".\n"
PLAY_AGAIN: .asciiz "Do you want to play again (n/n)?\n"
FINAL_SCORE_IS: .asciiz "Your final score is "
ITSBEENFUN: .asciiz ". >:(!\n"
NL: .asciiz "\n"
GOODBYE: .byte 0x2e, 0x20, 0x47, 0x6f, 0x6f, 0x64, 0x62, 0x79, 0x65, 0x21, 0x0a, 0x00
.text
main:
jal seed_rand
lw $s0, WORDS
and $s1, $s1, $0
and $s2, $s2, $0
la $a0, WELCOME
jal print
_game_loop:
beq $s2, $0, _if_not_rand
jal get_rand_word
move $s0, $v0
_if_not_rand:
la $a0, IM_THINKING
jal print
la $a0, PERMUTED_WORD
move $a1, $s0
jal permute
jal play_round
add $s1, $s1, $v0
addi $s2, $s2, 1
la $a0, CORRECT_WORD
jal print
move $a0, $s0
jal print
la $a0, NL
jal print
_main_prompt_char:
la $a0, PLAY_AGAIN
jal print
jal prompt_char
beq $v0, 121, _game_loop
bne $v0, 110, _main_prompt_char
la $a0, FINAL_SCORE_IS
jal print
move $a0, $s1
jal print_int
la $a0, GOODBYE
jal print
exit: li $v0, 10
syscall
seed_rand:
addi $sp, $sp, -8
sw $a0, 0($sp)
sw $a1, 4($sp)
addi $v0, $0, 30
syscall
move $a1, $a0
addi $v0, $0, 40
and $a0, $a0, $0
syscall
lw $a1, 4($sp)
lw $a0, 0($sp)
addi $sp, $sp, 8
jr $ra
get_rand_word:
addi $sp, $sp, -8
sw $a0, 0($sp)
sw $a1, 4($sp)
addi $v0, $0, 42
and $a0, $a0, $0
lw $a1, WORDS_LENGTH
syscall
mul $a0, $a0, 4
lw $v0, WORDS($a0)
lw $a1, 4($sp)
lw $a0, 0($sp)
addi $sp, $sp, 8
jr $ra
get_rand:
addi $sp, $sp, -8
sw $a0, 0($sp)
sw $a1, 4($sp)
addi $v0, $0, 42
move $a1, $a0
and $a0, $a0, $0
syscall
move $v0, $a0
lw $a1, 4($sp)
lw $a0, 0($sp)
addi $sp, $sp, 8
jr $ra
permute:
addi $sp, $sp, -28
sw $ra, 0($sp)
sw $a0, 4($sp)
sw $a1, 8($sp)
sw $s0, 12($sp)
sw $s1, 16($sp)
sw $s2, 20($sp)
sw $s7, 24($sp)
move $s0, $a0
move $s1, $a1
jal strcpy
jal strlen
move $s2, $v0
addi $s7, $s2, -1
_permute_loop:
beq $s7, 1, _permute_loop_end
move $a0, $s7
jal get_rand
move $a0, $s0
move $a1, $s7
move $a2, $v0
jal swap
addi $s7, $s7, -1
j _permute_loop
_permute_loop_end:
lw $ra, 0($sp)
lw $a0, 4($sp)
lw $a1, 8($sp)
lw $s0, 12($sp)
lw $s1, 16($sp)
lw $s2, 20($sp)
lw $s7, 24($sp)
addi $sp, $sp, -28
jr $ra
swap:
add $t0, $a0, $a1
lb $t1, 0($t0)
add $t0, $a0, $a2
lb $t2, 0($t0)
sb $t1, 0($t0)
add $t0, $a0, $a1
sb $t2, 0($t0)
jr $ra
strlen:
addi $sp, $sp, -4
sw $a0, 0($sp)
and $v0, $v0, $0
_length_loop:
lb $t8, 0($a0)
beq $t8, $0, _length_loop_end
addi $a0, $a0, 1
addi $v0, $v0, 1
j _length_loop
_length_loop_end:
lw $a0, 0($sp)
addi $sp, $sp, 4
jr $ra
strcpy:
addi $sp, $sp, -8
sw $a0, 0($sp)
sw $a1, 4($sp)
and $v0, $v0, $0
_copy_loop:
lb $t8, 0($a1)
sb $t8, 0($a0)
beq $t8, $0, _copy_loop_end
addi $a0, $a0, 1
addi $a1, $a1, 1
addi $v0, $v0, 1
j _copy_loop
_copy_loop_end:
lw $a0, 0($sp)
lw $a1, 4($sp)
addi $sp, $sp, 8
jr $ra
play_round:
addi $sp, $sp, -24
sw $ra, 0($sp)
sw $a0, 4($sp)
sw $a1, 8($sp)
sw $s0, 12($sp)
sw $s1, 16($sp)
sw $s2, 20($sp)
jal strlen
move $s0, $v0
move $s1, $a0
la $a0, GUESSED
move $a1, $s0
jal fill_blanks
_round_loop:
beq $s0, $0, _round_loop_end
la $a0, THE_WORD_IS
jal print
la $a0, GUESSED
jal print
la $a0, SCORE_IS
jal print
move $a0, $s0
jal print_int
la $a0, .
jal print
la $a0, GUESS_A_LETTER
jal print
jal prompt_char
move $s2, $v0
beq $s2, 46, _round_forfeit
move $a0, $s1
move $a1, $s2
jal str_contains
bne $v0, $0, _round_char_found
addi $s0, $s0 -1
la $a0, NO
jal print
beq $s0, $0, _round_no_points
j _round_loop
_round_char_found:
la $a0, GUESSED
move $a1, $s1
move $a2, $s2
jal update_guessed
la $a0, GUESSED
addi $a1, $0, 95
jal str_contains
beq $v0, $0, _round_loop_end
la $a0, YES
jal print
j _round_loop
_round_forfeit:
la $a0, FORFEIT
jal print
and $s0, $s0, $0
_round_no_points:
la $a0, NO_POINTS
jal print
_round_loop_end:
la $a0, ROUND_OVER
jal print
la $a0, GUESSED
jal print
move $v0, $s0
lw $ra, 0($sp)
lw $a0, 4($sp)
lw $a1, 8($sp)
lw $s0, 12($sp)
lw $s1, 16($sp)
lw $s2, 20($sp)
addi $sp, $sp, 24
jr $ra
fill_blanks:
addi $sp, $sp, -8
sw $a0, 0($sp)
sw $a1, 4($sp)
add $a0, $a0, $a1
addi $t1, $0, 95
sb $0,0($a0)
_fill_blanks_loop:
beq $a1, $0, _fill_blanks_loop_end
addi $a0, $a0, -1
addi $a1, $a1, -1
sb $t1, 0($a0)
j _fill_blanks_loop
_fill_blanks_loop_end:
lw $a0, 0($sp)
lw $a1, 4($sp)
addi $sp, $sp, 8
jr $ra
prompt_char:
addi $sp, $sp, -12
sw $ra, 0($sp)
sw $a0, 4($sp)
sw $s0, 8($sp)
addi $v0, $0, 12
syscall
move $s0, $v0
la $a0, NL
jal print
jal print
move $v0, $s0
lw $ra, 0($sp)
lw $a0, 4($sp)
lw $s0, 8($sp)
addi $sp, $sp, 12
jr $ra
str_contains:
addi $sp, $sp, -4
sw $a0, 0($sp)
and $v0, $v0, $0
_str_contains_loop:
lb $t0, 0($a0)
beq $t0, $0, _str_contains_loop_end
beq $t0, $a1, _char_found
addi $a0, $a0, 1
j _str_contains_loop
_char_found:
addi $v0, $0, 1
_str_contains_loop_end:
lw $a0, 0($sp)
addi $sp, $sp, 4
jr $ra
update_guessed:
addi $sp, $sp, -8
sw $a0, 0($sp)
sw $a1, 4($sp)
_update_g_loop:
lb $t0, 0($a1)
beq $t0, $0, _update_g_loop_end
bne $t0, $a2, _char_not_found
sb $a2, 0($a0)
_char_not_found:
addi $a0, $a0, 1
addi $a1, $a1, 1
j _update_g_loop
_update_g_loop_end:
lw $a1, 4($sp)
lw $a0, 0($sp)
addi $sp, $sp, 8
jr $ra
print:
addi $v0, $0, 4
syscall
jr $ra
print_int:
addi $v0, $0, 1
syscall
jr $ra
I don't know C++, but here's a MIPS solution
[code].data
WORD0: .asciiz "team"
WORD1: .asciiz "fortress"
WORD2: .asciiz "two"
WORD3: .asciiz "is"
WORD4: .asciiz "a"
WORD5: .asciiz "class"
WORD6: .asciiz "based"
WORD7: .asciiz "first"
WORD8: .asciiz "person"
WORD9: .asciiz "shooter"
WORDS: .word WORD0, WORD1, WORD2, WORD3, WORD4, WORD5, WORD6, WORD7, WORD8, WORD9
WORDS_LENGTH: .word 10
PERMUTED_WORD: .space 32
GUESSED: .space 32
WELCOME: .asciiz "Welcome to Scramble basterdized by negasora\n"
IM_THINKING: .asciiz "I'm doing hw..."
YES: .asciiz "No! "
NO: .asciiz "Yes! "
THE_WORD_IS: .asciiz "The word isn't "
SCORE_IS: .asciiz ". Score is "
GUESS_A_LETTER: .asciiz "Guess a letter?\n"
FORFEIT: .asciiz "-WORD FORFIETED- "
NO_POINTS: .asciiz "You fucked up.\n"
ROUND_OVER: .asciiz "Round is over. Your final guess was:\n"
CORRECT_WORD: .asciiz "\nCorrect unscrambled word was:\n"
.: .asciiz ".\n"
PLAY_AGAIN: .asciiz "Do you want to play again (n/n)?\n"
FINAL_SCORE_IS: .asciiz "Your final score is "
ITSBEENFUN: .asciiz ". >:(!\n"
NL: .asciiz "\n"
GOODBYE: .byte 0x2e, 0x20, 0x47, 0x6f, 0x6f, 0x64, 0x62, 0x79, 0x65, 0x21, 0x0a, 0x00
.text
main:
jal seed_rand
lw $s0, WORDS
and $s1, $s1, $0
and $s2, $s2, $0
la $a0, WELCOME
jal print
_game_loop:
beq $s2, $0, _if_not_rand
jal get_rand_word
move $s0, $v0
_if_not_rand:
la $a0, IM_THINKING
jal print
la $a0, PERMUTED_WORD
move $a1, $s0
jal permute
jal play_round
add $s1, $s1, $v0
addi $s2, $s2, 1
la $a0, CORRECT_WORD
jal print
move $a0, $s0
jal print
la $a0, NL
jal print
_main_prompt_char:
la $a0, PLAY_AGAIN
jal print
jal prompt_char
beq $v0, 121, _game_loop
bne $v0, 110, _main_prompt_char
la $a0, FINAL_SCORE_IS
jal print
move $a0, $s1
jal print_int
la $a0, GOODBYE
jal print
exit: li $v0, 10
syscall
seed_rand:
addi $sp, $sp, -8
sw $a0, 0($sp)
sw $a1, 4($sp)
addi $v0, $0, 30
syscall
move $a1, $a0
addi $v0, $0, 40
and $a0, $a0, $0
syscall
lw $a1, 4($sp)
lw $a0, 0($sp)
addi $sp, $sp, 8
jr $ra
get_rand_word:
addi $sp, $sp, -8
sw $a0, 0($sp)
sw $a1, 4($sp)
addi $v0, $0, 42
and $a0, $a0, $0
lw $a1, WORDS_LENGTH
syscall
mul $a0, $a0, 4
lw $v0, WORDS($a0)
lw $a1, 4($sp)
lw $a0, 0($sp)
addi $sp, $sp, 8
jr $ra
get_rand:
addi $sp, $sp, -8
sw $a0, 0($sp)
sw $a1, 4($sp)
addi $v0, $0, 42
move $a1, $a0
and $a0, $a0, $0
syscall
move $v0, $a0
lw $a1, 4($sp)
lw $a0, 0($sp)
addi $sp, $sp, 8
jr $ra
permute:
addi $sp, $sp, -28
sw $ra, 0($sp)
sw $a0, 4($sp)
sw $a1, 8($sp)
sw $s0, 12($sp)
sw $s1, 16($sp)
sw $s2, 20($sp)
sw $s7, 24($sp)
move $s0, $a0
move $s1, $a1
jal strcpy
jal strlen
move $s2, $v0
addi $s7, $s2, -1
_permute_loop:
beq $s7, 1, _permute_loop_end
move $a0, $s7
jal get_rand
move $a0, $s0
move $a1, $s7
move $a2, $v0
jal swap
addi $s7, $s7, -1
j _permute_loop
_permute_loop_end:
lw $ra, 0($sp)
lw $a0, 4($sp)
lw $a1, 8($sp)
lw $s0, 12($sp)
lw $s1, 16($sp)
lw $s2, 20($sp)
lw $s7, 24($sp)
addi $sp, $sp, -28
jr $ra
swap:
add $t0, $a0, $a1
lb $t1, 0($t0)
add $t0, $a0, $a2
lb $t2, 0($t0)
sb $t1, 0($t0)
add $t0, $a0, $a1
sb $t2, 0($t0)
jr $ra
strlen:
addi $sp, $sp, -4
sw $a0, 0($sp)
and $v0, $v0, $0
_length_loop:
lb $t8, 0($a0)
beq $t8, $0, _length_loop_end
addi $a0, $a0, 1
addi $v0, $v0, 1
j _length_loop
_length_loop_end:
lw $a0, 0($sp)
addi $sp, $sp, 4
jr $ra
strcpy:
addi $sp, $sp, -8
sw $a0, 0($sp)
sw $a1, 4($sp)
and $v0, $v0, $0
_copy_loop:
lb $t8, 0($a1)
sb $t8, 0($a0)
beq $t8, $0, _copy_loop_end
addi $a0, $a0, 1
addi $a1, $a1, 1
addi $v0, $v0, 1
j _copy_loop
_copy_loop_end:
lw $a0, 0($sp)
lw $a1, 4($sp)
addi $sp, $sp, 8
jr $ra
play_round:
addi $sp, $sp, -24
sw $ra, 0($sp)
sw $a0, 4($sp)
sw $a1, 8($sp)
sw $s0, 12($sp)
sw $s1, 16($sp)
sw $s2, 20($sp)
jal strlen
move $s0, $v0
move $s1, $a0
la $a0, GUESSED
move $a1, $s0
jal fill_blanks
_round_loop:
beq $s0, $0, _round_loop_end
la $a0, THE_WORD_IS
jal print
la $a0, GUESSED
jal print
la $a0, SCORE_IS
jal print
move $a0, $s0
jal print_int
la $a0, .
jal print
la $a0, GUESS_A_LETTER
jal print
jal prompt_char
move $s2, $v0
beq $s2, 46, _round_forfeit
move $a0, $s1
move $a1, $s2
jal str_contains
bne $v0, $0, _round_char_found
addi $s0, $s0 -1
la $a0, NO
jal print
beq $s0, $0, _round_no_points
j _round_loop
_round_char_found:
la $a0, GUESSED
move $a1, $s1
move $a2, $s2
jal update_guessed
la $a0, GUESSED
addi $a1, $0, 95
jal str_contains
beq $v0, $0, _round_loop_end
la $a0, YES
jal print
j _round_loop
_round_forfeit:
la $a0, FORFEIT
jal print
and $s0, $s0, $0
_round_no_points:
la $a0, NO_POINTS
jal print
_round_loop_end:
la $a0, ROUND_OVER
jal print
la $a0, GUESSED
jal print
move $v0, $s0
lw $ra, 0($sp)
lw $a0, 4($sp)
lw $a1, 8($sp)
lw $s0, 12($sp)
lw $s1, 16($sp)
lw $s2, 20($sp)
addi $sp, $sp, 24
jr $ra
fill_blanks:
addi $sp, $sp, -8
sw $a0, 0($sp)
sw $a1, 4($sp)
add $a0, $a0, $a1
addi $t1, $0, 95
sb $0,0($a0)
_fill_blanks_loop:
beq $a1, $0, _fill_blanks_loop_end
addi $a0, $a0, -1
addi $a1, $a1, -1
sb $t1, 0($a0)
j _fill_blanks_loop
_fill_blanks_loop_end:
lw $a0, 0($sp)
lw $a1, 4($sp)
addi $sp, $sp, 8
jr $ra
prompt_char:
addi $sp, $sp, -12
sw $ra, 0($sp)
sw $a0, 4($sp)
sw $s0, 8($sp)
addi $v0, $0, 12
syscall
move $s0, $v0
la $a0, NL
jal print
jal print
move $v0, $s0
lw $ra, 0($sp)
lw $a0, 4($sp)
lw $s0, 8($sp)
addi $sp, $sp, 12
jr $ra
str_contains:
addi $sp, $sp, -4
sw $a0, 0($sp)
and $v0, $v0, $0
_str_contains_loop:
lb $t0, 0($a0)
beq $t0, $0, _str_contains_loop_end
beq $t0, $a1, _char_found
addi $a0, $a0, 1
j _str_contains_loop
_char_found:
addi $v0, $0, 1
_str_contains_loop_end:
lw $a0, 0($sp)
addi $sp, $sp, 4
jr $ra
update_guessed:
addi $sp, $sp, -8
sw $a0, 0($sp)
sw $a1, 4($sp)
_update_g_loop:
lb $t0, 0($a1)
beq $t0, $0, _update_g_loop_end
bne $t0, $a2, _char_not_found
sb $a2, 0($a0)
_char_not_found:
addi $a0, $a0, 1
addi $a1, $a1, 1
j _update_g_loop
_update_g_loop_end:
lw $a1, 4($sp)
lw $a0, 0($sp)
addi $sp, $sp, 8
jr $ra
print:
addi $v0, $0, 4
syscall
jr $ra
print_int:
addi $v0, $0, 1
syscall
jr $ra[/code]