Some optimizations.
This commit is contained in:
parent
b569aa3984
commit
e1e670abdf
18
boot.c
18
boot.c
@ -8,7 +8,7 @@ typedef enum : char {
|
|||||||
NOT = 'O'
|
NOT = 'O'
|
||||||
} Cell;
|
} Cell;
|
||||||
|
|
||||||
Cell* board = ((Cell*)0x7F00);
|
Cell* const board = (Cell*)0x7F00;
|
||||||
|
|
||||||
HEDLEY_ALWAYS_INLINE char readchar(void);
|
HEDLEY_ALWAYS_INLINE char readchar(void);
|
||||||
HEDLEY_ALWAYS_INLINE bool checkwin(Cell c);
|
HEDLEY_ALWAYS_INLINE bool checkwin(Cell c);
|
||||||
@ -24,9 +24,8 @@ void _start(void) {
|
|||||||
"start:\n"
|
"start:\n"
|
||||||
);
|
);
|
||||||
Cell cur = CROSS;
|
Cell cur = CROSS;
|
||||||
for (char i = 0; i < 3; i++)
|
for (unsigned char i = 0; i < 9; i++)
|
||||||
for (char j = 0; j < 3; j++)
|
board[i] = NONE;
|
||||||
board[i * 3 + j] = NONE;
|
|
||||||
while (1) {
|
while (1) {
|
||||||
printboard();
|
printboard();
|
||||||
char k = readchar();
|
char k = readchar();
|
||||||
@ -45,10 +44,7 @@ void _start(void) {
|
|||||||
board[c] = cur;
|
board[c] = cur;
|
||||||
if (checkwin(cur))
|
if (checkwin(cur))
|
||||||
break;
|
break;
|
||||||
if (cur == CROSS)
|
cur ^= (CROSS ^ NOT);
|
||||||
cur = NOT;
|
|
||||||
else
|
|
||||||
cur = CROSS;
|
|
||||||
}
|
}
|
||||||
putchar(cur);
|
putchar(cur);
|
||||||
printboard();
|
printboard();
|
||||||
@ -83,10 +79,8 @@ void printboard(void) {
|
|||||||
HEDLEY_ALWAYS_INLINE
|
HEDLEY_ALWAYS_INLINE
|
||||||
bool checkwin(Cell c) {
|
bool checkwin(Cell c) {
|
||||||
for (size_t i = 0; i <= 2; i++)
|
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;
|
((board[3*i] == c) && (board[3*i + 1] == c) && (board[3*i + 2] == c)))
|
||||||
for (size_t i = 0; i <= 2; i++)
|
|
||||||
if ((board[3*i] == c) && (board[3*i + 1] == c) && (board[3*i + 2] == c))
|
|
||||||
return true;
|
return true;
|
||||||
if (board[0] == c && board[4] == c && board[8] == c)
|
if (board[0] == c && board[4] == c && board[8] == c)
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user