summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRaúl Benencia <rul@kalgan.cc>2015-05-12 13:33:18 -0300
committerRaúl Benencia <rul@kalgan.cc>2015-05-12 13:33:18 -0300
commitd64fd8708f1ca39fe523513998559c3602dad897 (patch)
treee576da7e9b8e36475c7197e213316e6df8a90420 /lib
parentd8d0ce0654ee8400162b536c580b74aab843132b (diff)
use coordinate notation for inputHEADmaster
Diffstat (limited to 'lib')
-rw-r--r--lib/input.c53
1 files changed, 25 insertions, 28 deletions
diff --git a/lib/input.c b/lib/input.c
index 8b696e1..ea5f368 100644
--- a/lib/input.c
+++ b/lib/input.c
@@ -7,40 +7,37 @@
#define LENGTH 80
-static Coord _input_coord() {
- char line[LENGTH];
- int done = 0;
+Move input_move() {
+ Coord orig, dest;
+ char line[LENGTH], orig_line[3], dest_line[3];
+ int done = 0;
+ printf("Please, enter your movement: ");
while (!done) {
fgets(line, LENGTH, stdin);
- if (strnlen(line, LENGTH) == 3 && line[2] == '\n')
- line[2] = 0;
-
- if (!coord_is_valid(line))
- printf("Invalid coordinate. Write something like \"e2\": ");
+ if (strnlen(line, LENGTH) == 6 && line[2] == '-' && line[5] == '\n') {
+ orig_line[0] = line[0];
+ orig_line[1] = line[1];
+ orig_line[2] = 0;
+
+ dest_line[0] = line[3];
+ dest_line[1] = line[4];
+ dest_line[2] = 0;
+
+ printf("Coordinates %s-%s\n", orig_line, dest_line);
+
+ if (!coord_is_valid(orig_line) || !coord_is_valid(dest_line))
+ printf("Invalid coordinate, try again: ");
+ else {
+ orig = coord_init(orig_line);
+ dest = coord_init(dest_line);
+ done = 1;
+ }
+ }
else
- done = 1;
+ printf("Invalid movement. Write something like \"e2-e4\": ");
}
- return coord_init(line);
-}
-
-static Coord _input_orig_coord() {
- printf("Orig coordinate: ");
-
- return _input_coord();
-}
-
-static Coord _input_dest_coord() {
- printf("Dest coordinate: ");
-
- return _input_coord();
-}
-
-Move input_move() {
- Coord orig = _input_orig_coord();
- Coord dest = _input_dest_coord();
-
return move_init(orig, dest);
}
nihil fit ex nihilo