blob: 2dc0215c260c6724a5d2055fde09f3a5ea8f3934 (
plain)
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
|
#include <ctype.h>
#include <string.h>
#include "coordinate.h"
static int _valid_coord(char col, char row) {
if (col >= 'a' && col <= 'h' && row >= '1' && row <= '8')
return 0;
return 1;
}
int coord_init(Coord* c, char col, char row) {
char lower_col = tolower(col);
char lower_row = tolower(row);
if (! _valid_coord(lower_col, lower_row))
return 1;
c->row = row;
c->col = col;
return 0;
}
int coord_init_from_str(Coord* c, char* s) {
if (strlen(s) != 2)
return 1;
return coord_init(c, s[0], s[1]);
}
|