forked from JungMinyong/Renju
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboard.c
More file actions
40 lines (33 loc) · 842 Bytes
/
board.c
File metadata and controls
40 lines (33 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include "board.h"
char board[SIZE][SIZE];
char current_stone = BLACK;
void initialize_board() {
for(int i = 0; i < SIZE; i++) {
for(int j = 0; j < SIZE; j++) {
board[i][j] = EMPTY;
}
}
}
void print_board() {
printf(" ");
for(int i = 0; i < SIZE; i++) {
printf("%c ", i+'a');
}
printf("\n");
for(int i = 0; i < SIZE; i++) {
printf("%2d ", i+1);
for(int j = 0; j < SIZE; j++) {
printf("%c ", board[i][j]);
}
printf("\n");
}
}
void add_stone(char column, int row) {
int x = column - 'a';
int y = row - 1;
if (x >= 0 && x < SIZE && y >= 0 && y < SIZE && board[y][x] == EMPTY) {
board[y][x] = current_stone;
current_stone = (current_stone == BLACK) ? WHITE : BLACK;
}
}