Make the code ever so slightly less stupid.
This commit is contained in:
parent
3a02a0ee8a
commit
60d8f9bc31
20
boot.c
20
boot.c
@ -2,14 +2,14 @@
|
||||
#include <stdbool.h>
|
||||
#include "hedley.h"
|
||||
|
||||
#define BOARD ((Cell*)0x7F00)
|
||||
|
||||
typedef enum : char {
|
||||
NONE = ' ',
|
||||
CROSS = 'X',
|
||||
NOT = 'O'
|
||||
} Cell;
|
||||
|
||||
Cell* board = ((Cell*)0x7F00);
|
||||
|
||||
HEDLEY_ALWAYS_INLINE char readchar(void);
|
||||
HEDLEY_ALWAYS_INLINE bool checkwin(Cell c);
|
||||
HEDLEY_NEVER_INLINE void putchar(char);
|
||||
@ -26,7 +26,7 @@ void _start(void) {
|
||||
Cell cur = CROSS;
|
||||
for (char i = 0; i < 3; i++)
|
||||
for (char j = 0; j < 3; j++)
|
||||
BOARD[i * 3 + j] = NONE;
|
||||
board[i * 3 + j] = NONE;
|
||||
while (1) {
|
||||
printboard();
|
||||
char k = readchar();
|
||||
@ -40,9 +40,9 @@ void _start(void) {
|
||||
else
|
||||
o = (0x2C - 8);
|
||||
size_t c = numpadkeys[k - o];
|
||||
if (BOARD[c] != NONE)
|
||||
if (board[c] != NONE)
|
||||
continue;
|
||||
BOARD[c] = cur;
|
||||
board[c] = cur;
|
||||
if (checkwin(cur))
|
||||
break;
|
||||
if (cur == CROSS)
|
||||
@ -73,7 +73,7 @@ void printboard(void) {
|
||||
);
|
||||
for (char i = 0; i < 3; i++) {
|
||||
for (char j = 0; j < 3; j++) {
|
||||
putchar(BOARD[i * 3 + j]);
|
||||
putchar(board[i * 3 + j]);
|
||||
}
|
||||
putchar('\n');
|
||||
putchar('\r');
|
||||
@ -83,14 +83,14 @@ void printboard(void) {
|
||||
HEDLEY_ALWAYS_INLINE
|
||||
bool checkwin(Cell c) {
|
||||
for (size_t i = 0; i <= 2; i++)
|
||||
if ((BOARD[i] == c) && (BOARD[i + 3] == c) && (BOARD[i + 6] == c))
|
||||
if ((board[i] == c) && (board[i + 3] == c) && (board[i + 6] == c))
|
||||
return true;
|
||||
for (size_t i = 0; i <= 2; i++)
|
||||
if ((BOARD[3*i] == c) && (BOARD[3*i + 1] == c) && (BOARD[3*i + 2] == c))
|
||||
if ((board[3*i] == c) && (board[3*i + 1] == c) && (board[3*i + 2] == c))
|
||||
return true;
|
||||
if (BOARD[0] == c && BOARD[4] == c && BOARD[8] == c)
|
||||
if (board[0] == c && board[4] == c && board[8] == c)
|
||||
return true;
|
||||
if (BOARD[2] == c && BOARD[4] == c && BOARD[6] == c)
|
||||
if (board[2] == c && board[4] == c && board[6] == c)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user