63 lines
973 B
C
63 lines
973 B
C
/*
|
|
* Copyright (c) Camden Dixie O'Brien
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
#include "puzz.h"
|
|
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/time.h>
|
|
|
|
enum { UNKNOWN = 0xfe, KILLER = 0xfd };
|
|
|
|
int main(void)
|
|
{
|
|
struct timeval tv;
|
|
if (gettimeofday(&tv, NULL) != 0) {
|
|
perror("Failed to get time");
|
|
exit(1);
|
|
}
|
|
srand(tv.tv_usec);
|
|
|
|
gen();
|
|
print();
|
|
|
|
puzz_t field;
|
|
memset(field, UNKNOWN, sizeof(field));
|
|
|
|
const int x = rand() % WIDTH;
|
|
const int y = rand() % HEIGHT;
|
|
if (probe(x, y, field) == DEAD) {
|
|
field[x][y] = KILLER;
|
|
fprintf(stderr, "Dead\n");
|
|
}
|
|
|
|
putchar('\n');
|
|
for (int y = 0; y < HEIGHT; ++y) {
|
|
for (int x = 0; x < WIDTH; ++x) {
|
|
char c;
|
|
switch (field[x][y]) {
|
|
case UNKNOWN:
|
|
c = '?';
|
|
break;
|
|
case KILLER:
|
|
c = '!';
|
|
break;
|
|
case MINE:
|
|
c = 'x';
|
|
break;
|
|
default:
|
|
c = '0' + field[x][y];
|
|
break;
|
|
}
|
|
putchar(c);
|
|
}
|
|
putchar('\n');
|
|
}
|
|
|
|
return 0;
|
|
}
|