#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define ROW 3
#define COL 3
void print_board(char board[ROW][COL]);
void generate_word(char word[], int length);
int check_row(char board[ROW][COL], char word, int row);
int check_col(char board[ROW][COL], char word, int col);
int main() {
char word[5];
char board[ROW][COL];
srand(time(0));
generate_word(word, 5);
printf("密语: %s\n", word);
// 生成谜布
for (int i = 0; i < ROW; i++) {
for (int j = 0; j < COL; j++) {
board[i][j] = '*';
}
}
print_board(board);
// 填入密语
for (int i = 0; i < 5; i++) {
int row = rand() % ROW;
int col = rand() % COL;
while (board[row][col] != '*') {
row = (row + 1) % ROW;
col = (col + 1) % COL;
}
board[row][col] = word[i];
}
print_board(board);
return 0;
}
void print_board(char board[ROW][COL]) {
for (int i = 0; i < ROW; i++) {
for (int j = 0; j < COL; j++) {
printf(" %c ", board[i][j]);
}
printf("\n");
}
}
void generate_word(char word[], int length) {
for (int i = 0; i < length; i++) {
word[i] = 'a' + rand() % 26;
}
word[length] = '\0';
}