Skip to content

Legal move caching limit #2

Open
@prawnydagrate

Description

@prawnydagrate

The below program

use rschess::Board;

fn main() {
    for i in 1..=5 {
        println!("positions after {i} ply: {}", count_positions(Board::default(), i));
    }
}

fn count_positions(board: Board, depth: usize) -> usize {
    if depth == 0 {
        return 1;
    }
    let mut positions = 0;
    for m in board.gen_legal_moves() {
        let mut new = board.clone();
        new.make_move(m).unwrap();
        positions += count_positions(new, depth - 1);
    }
    positions
}

outputs

positions after 1 ply: 20
positions after 2 ply: 400
positions after 3 ply: 8902
positions after 4 ply: 197281
positions after 5 ply: 4865609

as expected. However in the process it uses 1.26 GiB of memory, because of the recently implemented legal move caching. It may be a good idea to set a limit for this cache, and implement a sort of 'garbage collector' which deletes unused cache. Further discussion is needed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions