solved wrong index bug

This commit is contained in:
Odweta
2026-02-18 23:19:21 +01:00
parent 51ff3b37d8
commit 465398f210
2 changed files with 8 additions and 7 deletions
+6 -5
View File
@@ -5,7 +5,7 @@
void init_board(board_t board) { void init_board(board_t board) {
for (int i = 0; i < BOARD_VERTICAL; i++) { for (int i = 0; i < BOARD_VERTICAL; i++) {
for (int j = 0; j < BOARD_HORIZONTAL; j++) { for (int j = 0; j < BOARD_HORIZONTAL; j++) {
board[j][i] = BOARD_DEFAULT_CONFIG[i][j]; board[i][j] = BOARD_DEFAULT_CONFIG[i][j];
} }
} }
} }
@@ -175,10 +175,14 @@ bool is_dest_opponent(board_t board, player_e player, move_t move) {
* 2b. it could be capturable x non-capturable * 2b. it could be capturable x non-capturable
* 2c. it could be out of bounds * 2c. it could be out of bounds
*/ */
/** FIXME: does not work -> b1 a3 says 0 */
bool validate_move(board_t board, player_e player, move_t move) { bool validate_move(board_t board, player_e player, move_t move) {
bool none = is_dest_none(board, move.to); bool none = is_dest_none(board, move.to);
bool dest_is_opponent = is_dest_opponent(board, player, move); bool dest_is_opponent = is_dest_opponent(board, player, move);
bool move_legal = is_move_legal(move); bool move_legal = is_move_legal(move);
printf("move.from = {%d,%d}; move.to = {%d,%d}\n", move.from.x, move.from.y, move.to.x, move.to.y);
printf("from.piece = %d; to.piece = %d\n", board[move.from.y][move.from.x], board[move.to.y][move.to.x]);
printf("dest is none? %d; dest is opp? %d; legal? %d\n", none, dest_is_opponent, move_legal);
if (none && move_legal) { if (none && move_legal) {
// free ability to move // free ability to move
return true; return true;
@@ -363,7 +367,6 @@ bool is_king_endangered(board_t board, player_e player, move_t move) {
} }
// checks for mates // checks for mates
/** FIXME: unimplemented */
end_condition_e check_end(board_t board, player_e player, move_t move) { end_condition_e check_end(board_t board, player_e player, move_t move) {
// here 'is_move_legal' is used as a determinator if a piece can move // here 'is_move_legal' is used as a determinator if a piece can move
if (is_king_endangered(board, player, move) && !is_move_legal(move)) { if (is_king_endangered(board, player, move) && !is_move_legal(move)) {
@@ -376,9 +379,7 @@ end_condition_e check_end(board_t board, player_e player, move_t move) {
} }
end_condition_e perform_move(board_t *board, player_e player, captured_t *captured, move_t move) { end_condition_e perform_move(board_t *board, player_e player, captured_t *captured, move_t move) {
bool valid = validate_move(*board, player, move); if (validate_move(*board, player, move)) {
printf("move valid? %d", valid);
if (valid) {
if ( if (
*board[move.to.y][move.to.x] != WKING || // accounting for both players *board[move.to.y][move.to.x] != WKING || // accounting for both players
*board[move.to.y][move.to.x] != BKING // you cannot capture a king *board[move.to.y][move.to.x] != BKING // you cannot capture a king
+2 -2
View File
@@ -11,9 +11,9 @@ void show_board(board_t board, player_e player) {
for (int i = 0; i < BOARD_VERTICAL; i++) { for (int i = 0; i < BOARD_VERTICAL; i++) {
printf("%-2d [", i+1); printf("%-2d [", i+1);
for (int j = 0; j < BOARD_HORIZONTAL-1; j++) { for (int j = 0; j < BOARD_HORIZONTAL-1; j++) {
printf("%-2d ", board[j][i]); printf("%-2d ", board[i][j]);
} }
printf("%d]\n", board[BOARD_HORIZONTAL-1][i]); printf("%d]\n", board[i][BOARD_HORIZONTAL-1]);
} }
printf("\ncurrently plays: "); printf("\ncurrently plays: ");