Browse Source

documentation: algebraic_notation

master
parent
commit
b330cf15d1
  1. 6
      TODO
  2. 19
      src/algebraic_notation.c
  3. 12
      src/algebraic_notation.h

6
TODO

@ -1,4 +1,4 @@
1. Algebraic notation: notation_move_to_string, documentation
2. Board: board_is_move_legal, add other piece's moves
3. Chess: output special error message for each type of illegal move so it's clear what went wrong
4. board_get_pawn_moves - add en passant
2. Chess: output special error message for each type of illegal move so it's clear what went wrong
3. board_get_pawn_moves - add en passant
4. board_get_king_moves - add castling

19
src/algebraic_notation.c

@ -71,6 +71,7 @@ Position notation_tile_to_position(TileNotation notation) {
}
// Converts notated tile into its string representation
char* notation_tile_to_string(TileNotation tile) {
char* notation = (char*) malloc(sizeof(char) * 2);
if (!notation) {
@ -83,6 +84,8 @@ char* notation_tile_to_string(TileNotation tile) {
return notation;
}
// Converts notated tile into its string representation on dest
void notation_tile_to_string_cpy(TileNotation tile, char* dest) {
if (!dest) {
return;
@ -96,6 +99,7 @@ void notation_tile_to_string_cpy(TileNotation tile, char* dest) {
}
// Converts notated tile string into its corresponding structure
TileNotation notation_tile_from_string(const char* tile_string) {
if (!tile_string) {
return notation_tile_new('a', 1);
@ -109,6 +113,7 @@ TileNotation notation_tile_from_string(const char* tile_string) {
}
// Creates a new notation tile from given file and rank.
TileNotation notation_tile_new(char file, unsigned int rank) {
TileNotation tile;
tile.file = file;
@ -118,7 +123,7 @@ TileNotation notation_tile_new(char file, unsigned int rank) {
}
// Converts
// Converts position to a notated position
TileNotation notation_tile_from_pos(Position pos) {
TileNotation tile;
switch (pos.row) {
@ -263,6 +268,7 @@ Piece notation_piece_from_char(char character) {
}
// Converts notated move into its string representation
char* notation_move_to_string(MoveNotation move) {
char* move_notation = (char*) malloc(sizeof(char) * 10);
if (!move_notation) {
@ -371,7 +377,16 @@ MoveNotation* notation_move_from_string(const char* move_string) {
}
MoveNotation notation_move_new(Piece piece, TileNotation origin, TileNotation target, int move_type);
// Creates a new move notation from provided arguments
MoveNotation notation_move_new(Piece piece, TileNotation origin, TileNotation target, int move_type) {
MoveNotation move_new;
move_new.piece = piece;
move_new.origin = origin;
move_new.target = target;
move_new.move_type = move_type;
return move_new;
}
// Converts move notation to a move

12
src/algebraic_notation.h

@ -26,6 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "move.h"
// A notated tile representation
typedef struct TileNotation {
char file;
unsigned int rank;
@ -36,19 +37,23 @@ typedef struct TileNotation {
Position notation_tile_to_position(TileNotation notation);
// Converts notated tile into its string representation
char* notation_tile_to_string(TileNotation tile);
// Converts notated tile into its string representation on dest
void notation_tile_to_string_cpy(TileNotation tile, char* dest);
// Converts notated tile string into its corresponding structure
TileNotation notation_tile_from_string(const char* tile_string);
// Creates a new notation tile from given file and rank.
TileNotation notation_tile_new(char file, unsigned int rank);
// Converts
// Converts position to a notated position
TileNotation notation_tile_from_pos(Position pos);
@ -66,6 +71,7 @@ Big characters are for WHITE pieces, small for BLACK pieces.
Piece notation_piece_from_char(char character);
// A notated move representation
typedef struct MoveNotation {
Piece piece;
TileNotation origin;
@ -74,6 +80,7 @@ typedef struct MoveNotation {
} MoveNotation;
// Converts notated move into its string representation
char* notation_move_to_string(MoveNotation move);
@ -90,6 +97,9 @@ Returns NULL if technical errors were encountered, move_string does not contain
MoveNotation* notation_move_from_string(const char* move_string);
/*
Creates a new move notation from provided arguments
*/
MoveNotation notation_move_new(Piece piece, TileNotation origin, TileNotation target, int move_type);

Loading…
Cancel
Save