Skip to content

Commit

Permalink
Start field can be disambiguation.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmlacak committed Nov 20, 2023
1 parent c18f74c commit 3a6b91c
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ converted to UTC for easier comparison.
**Application** and **library versions** can be seen in an application, using `version` command. \
The latest versions are:

Application: 0.0.1.414:846+20231120.192246 <!--- readme-new-app-version-major-minor-feature-commit+meta~breaks-place-marker --> \
Library: 0.0.1.414:846+20231120.192246 <!--- readme-new-lib-version-major-minor-feature-commit+meta~breaks-place-marker -->
Application: 0.0.1.415:847+20231120.200002 <!--- readme-new-app-version-major-minor-feature-commit+meta~breaks-place-marker --> \
Library: 0.0.1.415:847+20231120.200002 <!--- readme-new-lib-version-major-minor-feature-commit+meta~breaks-place-marker -->

Versioning used is [Natural Versioning 1.2](https://croatian-chess.blogspot.com/p/natver.html),
with meta data containing the same format as the book version.
Expand Down
2 changes: 1 addition & 1 deletion ws/crochess/src/crochess.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "crochess.h"


char const CROCHESS_VERSION[] = "0.0.1.414:846+20231120.192246"; // source-new-crochess-version-major-minor-feature-commit+meta~breaks-place-marker
char const CROCHESS_VERSION[] = "0.0.1.415:847+20231120.200002"; // source-new-crochess-version-major-minor-feature-commit+meta~breaks-place-marker

#ifdef __WITH_LINE_NOISE__
char const CROCHESS_HISTORY_FILE_NAME[] = "history_crochess.txt";
Expand Down
26 changes: 26 additions & 0 deletions ws/libcrochess/inc/cc_chessboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ bool cc_chessboard_is_coord_on_board( CcChessboard * restrict cb, int coord );
*/
bool cc_chessboard_is_pos_on_board( CcChessboard * restrict cb, int i, int j );

/**
Function returning if at least one coordinate of given disambiguation belongs to a board.
@param cb Chessboard.
@param i File, position along horizontal axis.
@param j Rank, position along vertical axis.
@return `true` if disambiguation is on-board, `false` otherwise.
*/
bool cc_chessboard_is_disambiguation_on_board( CcChessboard * restrict cb, int i, int j );

/**
Function checks if given coordinate is within safe off-board boundaries.
Expand Down Expand Up @@ -168,6 +179,21 @@ bool cc_chessboard_is_coord_safe_off_board( CcChessboard * restrict cb, int coor
*/
bool cc_chessboard_is_pos_safe_off_board( CcChessboard * restrict cb, int i, int j );

/**
Function returning if at least one coordinate of given disambiguation is within safe off-board boundaries.
@param cb Chessboard.
@param i File, position along horizontal axis.
@param j Rank, position along vertical axis.
@note
Coordinate is safely off-board if there could be a movement (e.g. trance-journey),
which would place piece back on-board.
@return `true` if disambiguation is safe off-board, `false` otherwise.
*/
bool cc_chessboard_is_disambiguation_safe_off_board( CcChessboard * restrict cb, int i, int j );

/**
Function returning if given position is on a light side of board.
Expand Down
14 changes: 14 additions & 0 deletions ws/libcrochess/src/cc_chessboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ bool cc_chessboard_is_pos_on_board( CcChessboard * restrict cb, int i, int j ) {
return CC_IS_POS_ON_BOARD( cb->size, i, j );
}

bool cc_chessboard_is_disambiguation_on_board( CcChessboard * restrict cb, int i, int j ) {
if ( !cc_chessboard_is_size_valid( cb ) ) return false;
return CC_IS_COORD_ON_BOARD( cb->size, i ) || CC_IS_COORD_ON_BOARD( cb->size, j );
}

bool cc_chessboard_is_coord_safe_off_board( CcChessboard * restrict cb, int coord ) {
if ( !cc_chessboard_is_size_valid( cb ) ) return false;

Expand All @@ -167,6 +172,15 @@ bool cc_chessboard_is_pos_safe_off_board( CcChessboard * restrict cb, int i, int
( (int)(-diag) <= j ) && ( j <= (int)( cb->size + diag ) ) );
}

bool cc_chessboard_is_disambiguation_safe_off_board( CcChessboard * restrict cb, int i, int j ) {
if ( !cc_chessboard_is_size_valid( cb ) ) return false;

size_t diag = cc_diagonal( cb->size );

return ( ( ( (int)(-diag) <= i ) && ( i <= (int)( cb->size + diag ) ) ) || \
( ( (int)(-diag) <= j ) && ( j <= (int)( cb->size + diag ) ) ) );
}

bool cc_chessboard_is_field_on_light_side( CcChessboard * restrict cb, int j ) {
if ( !cc_chessboard_is_size_valid( cb ) ) return false;
return CC_IS_FIELD_ON_LIGHT_SIDE( cb->size, j );
Expand Down
2 changes: 1 addition & 1 deletion ws/libcrochess/src/cc_path_gens.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ CcPathLink * cc_find_paths_all_pieces__new( CcChessboard * restrict cb,
if ( CC_PIECE_IS_NONE( piece ) ) return NULL;
if ( CC_PIECE_IS_WAVE( piece ) && CC_PIECE_IS_NONE( activator ) ) return NULL;

bool is_start_on_board = cc_chessboard_is_pos_on_board( cb, start__d.i, start__d.j );
bool is_start_on_board = cc_chessboard_is_disambiguation_on_board( cb, start__d.i, start__d.j );
bool is_end_on_board = cc_chessboard_is_pos_on_board( cb, end__d.i, end__d.j );

if ( !is_start_on_board && !is_end_on_board ) return NULL; // <1>
Expand Down
2 changes: 1 addition & 1 deletion ws/libcrochess/src/cc_version.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
*/


char const CC_LIB_VERSION[] = "0.0.1.414:846+20231120.192246"; // source-new-libcrochess-version-major-minor-feature-commit+meta~breaks-place-marker
char const CC_LIB_VERSION[] = "0.0.1.415:847+20231120.200002"; // source-new-libcrochess-version-major-minor-feature-commit+meta~breaks-place-marker
2 changes: 1 addition & 1 deletion ws/tests/src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "tests.h"


char const CROCHESS_TESTS_VERSION[] = "0.0.1.414:846+20231120.192246"; // source-new-crochess-tests-version-major-minor-feature-commit+meta~breaks-place-marker
char const CROCHESS_TESTS_VERSION[] = "0.0.1.415:847+20231120.200002"; // source-new-crochess-tests-version-major-minor-feature-commit+meta~breaks-place-marker

#ifdef __WITH_LINE_NOISE__
char const CROCHESS_TESTS_HISTORY_FILE_NAME[] = "history_tests.txt";
Expand Down

0 comments on commit 3a6b91c

Please sign in to comment.