move prompt + help
This commit is contained in:
+44
-1
@@ -1,3 +1,4 @@
|
||||
#include <stdio.h>
|
||||
#include "chess.h"
|
||||
#include "util.h"
|
||||
|
||||
@@ -22,7 +23,49 @@ void select_player(player_e *player, unsigned int round_count) {
|
||||
}
|
||||
}
|
||||
|
||||
bool get_move(move_t *move);
|
||||
void show_help() {
|
||||
puts(
|
||||
"movement help:\n\
|
||||
there is a prompt asking for where to move a piece every turn\n\
|
||||
format: e.g. you want to move a knight from b1 to a3:\n\
|
||||
you'd type -> b1 a3 <- (without the arrows)\n"
|
||||
);
|
||||
}
|
||||
|
||||
// returns false if the numbers of letters are out of bounds
|
||||
bool is_move_in_bounds(move_t move) {
|
||||
if (
|
||||
is_int_in_range(move.from.x, 0, 7) &&
|
||||
is_int_in_range(move.from.y, 0, 7) &&
|
||||
is_int_in_range(move.to.x, 0, 7) &&
|
||||
is_int_in_range(move.to.y, 0, 7)
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool get_move(move_t *move) {
|
||||
clear_stdin();
|
||||
|
||||
char _x_from, _x_to;
|
||||
int _y_from, _y_to;
|
||||
scanf("%c%d %c%d",
|
||||
&_x_from,
|
||||
&_y_from,
|
||||
&_x_to,
|
||||
&_y_to
|
||||
);
|
||||
|
||||
move->from.x = _x_from-96-1; // char to int conversion
|
||||
move->from.y = _y_from-1;
|
||||
|
||||
move->to.x = _x_to-96-1;
|
||||
move->to.y = _y_to-1;
|
||||
|
||||
return is_move_in_bounds(*move);
|
||||
}
|
||||
|
||||
bool perform_move(player_e player, move_t move);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user