iterator fixes

This commit is contained in:
2025-02-06 16:13:11 -05:00
parent 1bed0b61ad
commit 3681fd7e41
4 changed files with 35 additions and 41 deletions

View File

@@ -1,5 +1,5 @@
use crate::{
board::{Board, BOARD_SIZE},
board::Board,
piece::Piece,
};
use rand::prelude::*;
@@ -59,14 +59,7 @@ pub struct RandomAgent {
impl Agent for RandomAgent {
fn next_move(&mut self, board: &Board) -> Option<(usize, usize)> {
(0..BOARD_SIZE)
.flat_map(|i| {
(0..BOARD_SIZE)
.map(|j| (i, j))
.collect::<Vec<(usize, usize)>>()
})
.flat_map(|(i, j)| board.what_if(i, j, self.color).map(|_| (i, j)))
.choose(&mut rand::rng())
board.possible_moves(self.color).choose(&mut rand::rng())
}
fn name(&self) -> &'static str {