resolved clippy issues
This commit is contained in:
@@ -157,12 +157,7 @@ fn draw_piece(
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_score_bar(
|
||||
cr: &CairoContext,
|
||||
board: &Rectangle,
|
||||
draughts_game: &DraughtsGame,
|
||||
xform: &Matrix,
|
||||
) {
|
||||
fn draw_score_bar(cr: &CairoContext, board: &Rectangle, draughts_game: &DraughtsGame) {
|
||||
let score_bar = Rectangle::new(
|
||||
board.tl().x() - board.width() / 10.0,
|
||||
board.tl().y(),
|
||||
@@ -171,17 +166,7 @@ fn draw_score_bar(
|
||||
);
|
||||
let score_percentage = draughts_game.relative_score(Player::White) as f64;
|
||||
let tl = score_bar.tl();
|
||||
let br = score_bar.br();
|
||||
{
|
||||
let (tlx, tly) = xform.transform_point(tl.x(), tl.y());
|
||||
let (brx, bry) = xform.transform_point(br.x(), br.y());
|
||||
println!(
|
||||
"tl: ({}, {}), br: ({}, {}), score: {}",
|
||||
tlx, tly, brx, bry, score_percentage
|
||||
);
|
||||
}
|
||||
cr.save().unwrap();
|
||||
//cr.set_matrix(*xform);
|
||||
cr.set_source_rgb(1.0, 1.0, 1.0);
|
||||
cr.rectangle(
|
||||
score_bar.tl().x(),
|
||||
@@ -195,7 +180,7 @@ fn draw_score_bar(
|
||||
tl.x(),
|
||||
tl.y() + score_bar.height() * score_percentage,
|
||||
score_bar.width(),
|
||||
score_bar.height(),
|
||||
score_bar.height() * (1.0 - score_percentage),
|
||||
);
|
||||
cr.fill().unwrap();
|
||||
cr.restore().unwrap();
|
||||
@@ -226,6 +211,10 @@ fn on_activate(application: >k::Application) {
|
||||
let board_width = SQUARE_SIZE * DraughtsBoard::rows() as f64;
|
||||
let board_height = SQUARE_SIZE * DraughtsBoard::columns() as f64;
|
||||
let board = Rectangle::from_points(Point::new(0.0, 0.0), Point::new(board_width, board_height));
|
||||
let board_with_bar = Rectangle::from_points(
|
||||
Point::new(-board_width / 10.0, 0.0),
|
||||
Point::new(board_width, board_height),
|
||||
);
|
||||
let board_clone = board;
|
||||
let crown_red_handle = {
|
||||
let stream = gio::MemoryInputStream::from_bytes(&glib::Bytes::from_static(CROWN_RED));
|
||||
@@ -267,11 +256,11 @@ fn on_activate(application: >k::Application) {
|
||||
Point::new(width as f64, height as f64),
|
||||
);
|
||||
let f = f64::min(
|
||||
screen.width() / board.width(),
|
||||
screen.height() / board.height(),
|
||||
screen.width() / board_with_bar.width(),
|
||||
screen.height() / board_with_bar.height(),
|
||||
);
|
||||
let screen_center = screen.center();
|
||||
let board_center = board.center();
|
||||
let board_center = board_with_bar.center();
|
||||
let mut xform = xform.borrow_mut();
|
||||
*xform = Matrix::multiply(
|
||||
&Matrix::multiply(
|
||||
@@ -389,7 +378,7 @@ fn on_activate(application: >k::Application) {
|
||||
cr.restore().unwrap();
|
||||
}
|
||||
}
|
||||
draw_score_bar(&cr, &board, &draughts_game.borrow(), &xform);
|
||||
draw_score_bar(cr, &board, &draughts_game.borrow());
|
||||
});
|
||||
}
|
||||
let gesture = gtk::GestureClick::new();
|
||||
|
@@ -105,8 +105,8 @@ impl DraughtsBoard {
|
||||
Board::<Piece, 8, 8>::columns()
|
||||
}
|
||||
|
||||
pub fn pieces<'a, const PIECES: usize>(
|
||||
&'a self,
|
||||
pub fn pieces<const PIECES: usize>(
|
||||
&self,
|
||||
pieces: Vec<Piece, PIECES>,
|
||||
) -> impl Iterator<Item = Position> {
|
||||
self.0
|
||||
@@ -420,7 +420,7 @@ impl DraughtsGame {
|
||||
let pos = mv.get_start_position();
|
||||
let piece = self.board.get_piece(&pos);
|
||||
let moving_player = piece.player().unwrap();
|
||||
self.apply_move(&mv).unwrap();
|
||||
self.apply_move(mv).unwrap();
|
||||
if depth != 0 {
|
||||
let mut best_score = None;
|
||||
for mv in self.available_moves() {
|
||||
@@ -428,11 +428,9 @@ impl DraughtsGame {
|
||||
let score = clone.move_score(&mv, player, depth - 1);
|
||||
if best_score.is_none() {
|
||||
best_score = Some(score);
|
||||
} else {
|
||||
if let Some(bs) = best_score {
|
||||
if bs < score {
|
||||
best_score = Some(bs);
|
||||
}
|
||||
} else if let Some(bs) = best_score {
|
||||
if bs < score {
|
||||
best_score = Some(bs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -442,7 +440,7 @@ impl DraughtsGame {
|
||||
}
|
||||
}
|
||||
|
||||
fn available_moves<'a>(&'a self) -> impl Iterator<Item = Move> {
|
||||
fn available_moves(&self) -> impl Iterator<Item = Move> {
|
||||
let mut pieces = Vec::<Piece, 2>::new();
|
||||
match self.next_move {
|
||||
Player::White => {
|
||||
@@ -459,36 +457,6 @@ impl DraughtsGame {
|
||||
.flat_map(|pos| self.moves_for_piece(pos))
|
||||
}
|
||||
|
||||
fn find_best_move_rec<const MAX_HEAP_SIZE: usize>(
|
||||
&self,
|
||||
ranking: &mut MoveRanking<MAX_HEAP_SIZE>,
|
||||
current_depth: u32,
|
||||
max_depth: u32,
|
||||
) {
|
||||
let mut pieces = Vec::<Piece, 2>::new();
|
||||
match self.next_move {
|
||||
Player::White => {
|
||||
pieces.push(Piece::SimpleWhitePawn).unwrap();
|
||||
pieces.push(Piece::CrownedWhitePawn).unwrap();
|
||||
}
|
||||
Player::Red => {
|
||||
pieces.push(Piece::SimpleRedPawn).unwrap();
|
||||
pieces.push(Piece::CrownedRedPawn).unwrap();
|
||||
}
|
||||
}
|
||||
self.board.pieces(pieces).for_each(|pos| {
|
||||
self.moves_for_piece(pos).for_each(|mv| {
|
||||
let mut game = self.clone();
|
||||
game.apply_move(&mv).unwrap();
|
||||
let new_score = game.score_for_player(self.next_move);
|
||||
ranking.push(MoveHeapEntry {
|
||||
mv,
|
||||
score: new_score,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pub fn get_best_move(&self, max_depth: u32) -> Option<Move> {
|
||||
let mut result: Option<(Move, f32)> = None;
|
||||
let available_moves = self.available_moves().count();
|
||||
@@ -500,11 +468,9 @@ impl DraughtsGame {
|
||||
let score = self.clone().move_score(&mv, self.next_move, max_depth - 1);
|
||||
if result.is_none() {
|
||||
result = Some((mv, score));
|
||||
} else {
|
||||
if let Some((_, best_score)) = result {
|
||||
if score > best_score {
|
||||
result = Some((mv, score));
|
||||
}
|
||||
} else if let Some((_, best_score)) = result {
|
||||
if score > best_score {
|
||||
result = Some((mv, score));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -521,7 +487,7 @@ struct MoveHeapEntry {
|
||||
|
||||
impl PartialOrd for MoveHeapEntry {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
|
||||
self.score.partial_cmp(&other.score)
|
||||
Some(self.score.cmp(&other.score))
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user