diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-09-08 14:35:12 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-09-08 14:43:51 +0300 |
commit | 909f073d9eb9ddcedc04cd9915c22b717d14768d (patch) | |
tree | 33dc0e2fccc8172453439442bc65dea7863fa5a8 | |
parent | daf0a82f1e45a182be05eef5a2fcc4b24d61bcca (diff) | |
download | c-chess-909f073d9eb9ddcedc04cd9915c22b717d14768d.tar.gz |
refactor: rename to proper terminology
-rw-r--r-- | src/main.c | 44 |
1 files changed, 22 insertions, 22 deletions
@@ -188,7 +188,7 @@ Move input_move(FILE* stream) { return move; }; -int list_moves_with_destination(Move* moves, int* board, int color, int destination); +int generate_moves_with_destination(Move* moves, int* board, int color, int destination); int validate_move(Move move, int color, int* board) { // Null move means player is checkmated @@ -256,29 +256,29 @@ int validate_move(Move move, int color, int* board) { if ((piece & NO_COLOR) == KING) { if (piece % 2 == WHITE && move.origin == 4) { if (move.destination == 2 && board[0] == (ROOK | WHITE)) { - if (list_moves_with_destination(NULL, board, color ^ 1, move.origin)) return -5; + if (generate_moves_with_destination(NULL, board, color ^ 1, move.origin)) return -5; for (int i = 1; i < 4; i++) { - if (board[i] != EMPTY || list_moves_with_destination(NULL, board, color ^ 1, i)) return -5; + if (board[i] != EMPTY || generate_moves_with_destination(NULL, board, color ^ 1, i)) return -5; } return 0; } else if (move.destination == 6 && board[7] == (ROOK | WHITE)) { - if (list_moves_with_destination(NULL, board, color ^ 1, move.origin)) return -5; + if (generate_moves_with_destination(NULL, board, color ^ 1, move.origin)) return -5; for (int i = 5; i < 7; i++) { - if (board[i] != EMPTY || list_moves_with_destination(NULL, board, color ^ 1, i)) return -5; + if (board[i] != EMPTY || generate_moves_with_destination(NULL, board, color ^ 1, i)) return -5; } return 0; } } else if (piece % 2 == BLACK && move.origin == 116) { if (move.destination == 114 && board[112] == (ROOK | BLACK)) { - if (list_moves_with_destination(NULL, board, color ^ 1, move.origin)) return -5; + if (generate_moves_with_destination(NULL, board, color ^ 1, move.origin)) return -5; for (int i = 113; i < 116; i++) { - if (board[i] != EMPTY || list_moves_with_destination(NULL, board, color ^ 1, i)) return -5; + if (board[i] != EMPTY || generate_moves_with_destination(NULL, board, color ^ 1, i)) return -5; } return 0; } else if (move.destination == 118 && board[119] == (ROOK | BLACK)) { - if (list_moves_with_destination(NULL, board, color ^ 1, move.origin)) return -5; + if (generate_moves_with_destination(NULL, board, color ^ 1, move.origin)) return -5; for (int i = 117; i < 119; i++) { - if (board[i] != EMPTY || list_moves_with_destination(NULL, board, color ^ 1, i)) return -5; + if (board[i] != EMPTY || generate_moves_with_destination(NULL, board, color ^ 1, i)) return -5; } return 0; } @@ -443,7 +443,7 @@ int compute_material_advantage(int* board, int color) { return counter; } -int list_moves_with_destination(Move* moves, int* board, int color, int destination) { +int generate_moves_with_destination(Move* moves, int* board, int color, int destination) { int moves_count = 0; for (int rank = 7; rank >= 0; rank--) { @@ -463,14 +463,14 @@ int list_moves_with_destination(Move* moves, int* board, int color, int destinat return moves_count; } -int list_available_moves(Move* moves, int* board, int color) { +int generate_pseudolegal_moves(Move* moves, int* board, int color) { int moves_count = 0; for (int rank = 7; rank >= 0; rank--) { for (int file = 0; file < 8; file++) { int destination = rank * 16 + file; Move* next_ptr = moves ? moves + moves_count : NULL; - moves_count += list_moves_with_destination(next_ptr, board, color, destination); + moves_count += generate_moves_with_destination(next_ptr, board, color, destination); } } @@ -517,14 +517,14 @@ int count_bad_pawns(int* board, int color) { * for WHITE, meaining WHITE tries to maximize this * value and BLACK tries to minimize it. */ -int evaluate_position(int* board, int precomputed_mobility, int mobility_color) { +int static_evaluate(int* board, int precomputed_mobility, int mobility_color) { Move dummy[MAX_AVAILABLE_MOVES]; int white_material_advantage = compute_material_advantage(board, WHITE); // If pre-computed mobility has not been passed, compute it - int mobility = precomputed_mobility ? precomputed_mobility : list_available_moves(NULL, board, mobility_color); - int opponent_mobility = list_available_moves(NULL, board, mobility_color ^ 1); + int mobility = precomputed_mobility ? precomputed_mobility : generate_pseudolegal_moves(NULL, board, mobility_color); + int opponent_mobility = generate_pseudolegal_moves(NULL, board, mobility_color ^ 1); int white_mobility_advantage = (mobility - opponent_mobility) * (mobility_color == WHITE ? 1 : -1); @@ -591,20 +591,20 @@ Move minimax_search(int* board, int color, int depth, int alpha, int beta, int* // You only have available moves if your king hasn't been taken if (compute_material_advantage(board, color) > -INFINITY / 2) { - Move available_moves[MAX_AVAILABLE_MOVES]; - int available_moves_count = list_available_moves(available_moves, board, color); - int cache_hits = order_moves(available_moves, available_moves_count, board, hash, transposition_table, zobrist_seed); + Move pseudolegal_moves[MAX_AVAILABLE_MOVES]; + int pseudolegal_moves_count = generate_pseudolegal_moves(pseudolegal_moves, board, color); + int cache_hits = order_moves(pseudolegal_moves, pseudolegal_moves_count, board, hash, transposition_table, zobrist_seed); - for (int i = 0; i < available_moves_count; i++) { + for (int i = 0; i < pseudolegal_moves_count; i++) { *metrics += 1; - Move move = available_moves[i]; + Move move = pseudolegal_moves[i]; long move_hash = hash_after_move(move, board, zobrist_seed, hash); int captured_piece = make_move(move, board); move.value = depth > 0 ? minimax_search(board, 1 - color, depth - 1, alpha, beta, metrics, move_hash, transposition_table, zobrist_seed, deadline).value - : evaluate_position(board, available_moves_count, color); + : static_evaluate(board, pseudolegal_moves_count, color); if (transposition_table[move_hash].depth < depth) { if (transposition_table[move_hash].depth == -1) TRANSPOSITION_TABLE_CARDINALITY++; @@ -700,7 +700,7 @@ int main() { while (1) { int color = ply % 2; printf("##### Ply %i #####\n", ply); - printf("Current evaluation: %.2f\n", (double)evaluate_position(board, 0, WHITE) / 10); + printf("Current evaluation: %.2f\n", (double)static_evaluate(board, 0, WHITE) / 10); if (is_reading) { move = input_move(record); |