Fix warnings.

This commit is contained in:
hal8174 2024-03-23 23:52:46 +01:00
parent 8c29cb1e53
commit 1596bf180d
8 changed files with 54 additions and 71 deletions

4
Cargo.lock generated
View file

@ -456,9 +456,9 @@ dependencies = [
[[package]]
name = "regex"
version = "1.10.3"
version = "1.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15"
checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c"
dependencies = [
"aho-corasick",
"memchr",

View file

@ -13,7 +13,7 @@ where
loop {
input.clear();
std::io::stdin().read_line(&mut input);
let _ = std::io::stdin().read_line(&mut input);
let (cmd, arg) = input.trim().split_once(' ').unwrap_or((input.trim(), ""));
// dbg!(cmd, arg);

View file

@ -11,7 +11,7 @@ enum Mode {
#[derive(ValueEnum, Clone)]
enum ProblemCase {
simple,
Simple,
Level1,
Level2,
Level3,
@ -21,7 +21,7 @@ enum ProblemCase {
impl ProblemCase {
fn get_problem(&self) -> Problem {
match self {
ProblemCase::simple => problems::simple(),
ProblemCase::Simple => problems::simple(),
ProblemCase::Level1 => problems::belt_madness_level_1(),
ProblemCase::Level2 => problems::belt_madness_level_2(),
ProblemCase::Level3 => problems::belt_madness_level_3(),

View file

@ -1,5 +1,5 @@
use super::{
common::{print_map, Dimension, Direction, PathField, PositionType},
common::{print_map, Direction, PathField, PositionType},
Position, COLORS,
};
use crate::misc::Map;
@ -66,10 +66,6 @@ impl BruteforceBuilder {
pub fn build(self) -> Bruteforce {
// dbg!(&self);
let dimension = Dimension {
width: self.map.width,
height: self.map.height,
};
let mut b = Bruteforce {
map: self.map,
@ -77,7 +73,6 @@ impl BruteforceBuilder {
pointer_stack: vec![0],
solution_count: 0,
count: 0,
dimension,
};
for [start, end] in self.path {
@ -111,7 +106,6 @@ struct Problem {
#[derive(Clone)]
pub struct Bruteforce {
map: Map<BruteforceField>,
dimension: Dimension,
problems: Vec<Problem>,
pointer_stack: Vec<usize>,
solution_count: u128,
@ -654,7 +648,7 @@ impl Bruteforce {
// Print body
print_map(self.map.width as i32, self.map.height as i32, |x, y| {
let _ = print_map(self.map.width as i32, self.map.height as i32, |x, y| {
if let Some((i, c)) = m.get(x as usize, y as usize) {
let mut color = ColorSpec::new();
color.set_fg(Some(COLORS[*i]));

View file

@ -1,7 +1,6 @@
use core::panic;
use std::io::Write;
use std::io::{self, Write};
use base64::write;
use termcolor::{ColorSpec, StandardStream, WriteColor};
pub type PositionType = i32;
@ -203,7 +202,7 @@ impl PathField {
}
}
pub fn print_map<F>(width: i32, height: i32, f: F)
pub fn print_map<F>(width: i32, height: i32, f: F) -> io::Result<()>
where
F: Fn(i32, i32) -> (ColorSpec, &'static str),
{
@ -218,35 +217,35 @@ where
//padding
for _ in 0..height_digits {
write!(stdout, " ");
write!(stdout, " ")?;
}
for x in 0..width {
let digits = x / (i32::pow(10, d));
if digits == 0 && d > 0 {
write!(stdout, " ");
write!(stdout, " ")?;
} else {
write!(
stdout,
"{}",
char::from_u32((digits % 10) as u32 + 48).unwrap()
);
)?;
}
}
writeln!(stdout);
writeln!(stdout)?;
}
for y in 0..height {
write!(stdout, "{:1$}", y, height_digits as usize);
write!(stdout, "{:1$}", y, height_digits as usize)?;
for x in 0..width {
let (c, s) = f(x, y);
stdout.set_color(&c);
write!(stdout, "{:1}", s);
stdout.reset();
stdout.set_color(&c)?;
write!(stdout, "{:1}", s)?;
stdout.reset()?;
}
writeln!(stdout, "{:1$}", y, height_digits as usize);
writeln!(stdout, "{:1$}", y, height_digits as usize)?;
}
for i in 0..width_digits {
@ -254,21 +253,23 @@ where
//padding
for _ in 0..height_digits {
write!(stdout, " ");
write!(stdout, " ")?;
}
for x in 0..width {
let digits = x / (i32::pow(10, d));
if digits == 0 && d > 0 {
write!(stdout, " ");
write!(stdout, " ")?;
} else {
write!(
stdout,
"{}",
char::from_u32((digits % 10) as u32 + 48).unwrap()
);
)?;
}
}
writeln!(stdout);
writeln!(stdout)?;
}
Ok(())
}

View file

@ -76,7 +76,7 @@ impl ConflictAvoidance {
}
let mut belts = Vec::new();
for i in 0..problem.path.len() {
dbg!(&problem.path[i]);
// dbg!(&problem.path[i]);
let mut p = Vec::new();
p.push(PathField::Belt {
@ -87,7 +87,7 @@ impl ConflictAvoidance {
for (pos, dir) in &problem.path[i][1..] {
let start = p.last().unwrap().end_pos();
let start = start.0.in_direction(&start.1, 1);
dbg!(start, pos);
// dbg!(start, pos);
if &start == pos {
p.push(PathField::Belt {
pos: *pos,
@ -97,7 +97,10 @@ impl ConflictAvoidance {
p.push(PathField::Underground {
pos: start,
dir: *dir,
len: u8::max((start.x - pos.x).abs() as u8, (start.y - pos.y).abs() as u8),
len: u8::max(
(start.x - pos.x).unsigned_abs() as u8,
(start.y - pos.y).unsigned_abs() as u8,
),
})
}
}
@ -111,7 +114,6 @@ impl ConflictAvoidance {
// pos: problem.end[i].0,
// dir: problem.end[i].1,
// });
dbg!(&p);
belts.push(p);
}
@ -157,7 +159,7 @@ impl ConflictAvoidance {
let mut mapping = Vec::new();
let offset = Position::new(*xrange.start() as i32 - 1, *yrange.start() as i32 - 1);
dbg!(&xrange, &yrange);
// dbg!(&xrange, &yrange);
for (i, path) in self.belts.iter().enumerate() {
// index of first PathField where the next position is in the area
@ -181,8 +183,6 @@ impl ConflictAvoidance {
})
.map(|rev_i| path.len() - rev_i - 1);
dbg!(start_index, end_index);
if let Some((start_index, end_index)) = Option::zip(start_index, end_index) {
// dbg!(start_index, end_index, path[start_index], path[end_index]);
@ -268,7 +268,7 @@ impl ConflictAvoidance {
Some(
mapping
.into_iter()
.zip(solutions.into_iter())
.zip(solutions)
.map(|((path_id, start, end), path)| BruteForceEntry {
path_id,
start,
@ -305,16 +305,16 @@ impl ConflictAvoidance {
}
}
for y in 0..self.map.height {
for x in 0..self.map.width {
if *conflicts.get(x, y) > 1 {
print!("#");
} else {
print!(" ");
}
}
println!();
}
// for y in 0..self.map.height {
// for x in 0..self.map.width {
// if *conflicts.get(x, y) > 1 {
// print!("#");
// } else {
// print!(" ");
// }
// }
// println!();
// }
let mut candidates = Vec::new();
@ -506,7 +506,7 @@ impl ConflictAvoidance {
}
// Print body
print_map(self.map.width as i32, self.map.height as i32, |x, y| {
let _ = print_map(self.map.width as i32, self.map.height as i32, |x, y| {
let mut color = ColorSpec::new();
if let Some((xrange, yrange)) = &self.range {

View file

@ -1,13 +1,12 @@
use crate::graph::wheighted_graph::WheightedGraph;
use crate::misc::Map;
use crate::priority_queue::BinaryHeap;
use crate::{
graph::wheighted_graph::shortest_path::dijkstra, priority_queue::fibonacci_heap::FibonacciHeap,
};
use std::ops::Index;
use termcolor::{Color, ColorSpec};
use self::common::{print_map, Direction, PathField, Position, PositionType};
use self::common::{print_map, Direction, Position, PositionType};
pub mod brute_force;
pub mod common;
@ -89,7 +88,7 @@ impl Problem {
}
pub fn print(&self) {
print_map(self.map.width as i32, self.map.height as i32, |x, y| {
let _ = print_map(self.map.width as i32, self.map.height as i32, |x, y| {
let mut color = ColorSpec::new();
if let Some(i) = self
.start
@ -158,18 +157,13 @@ impl<'a> WheightedGraph for MapInternal<'a> {
fn edge(&self, node: &Self::Node, num: usize) -> Option<(Self::Node, f64)> {
let next = node.0.in_direction(&node.1, 1);
if next
.in_range(
&Position::new(0, 0),
&Position::new(
self.map.width as PositionType,
self.map.height as PositionType,
),
)
.is_none()
{
return None;
}
next.in_range(
&Position::new(0, 0),
&Position::new(
self.map.width as PositionType,
self.map.height as PositionType,
),
)?;
if self.map.get(next.x as usize, next.y as usize).blocked && self.end != (next, node.1) {
return None;
}
@ -183,17 +177,13 @@ impl<'a> WheightedGraph for MapInternal<'a> {
let mut count = 2;
for l in 2..=6 {
let n = node.0.in_direction(&node.1, l);
if n.in_range(
n.in_range(
&Position::new(0, 0),
&Position::new(
self.map.width as PositionType,
self.map.height as PositionType,
),
)
.is_none()
{
return None;
}
)?;
if !self.map.get(n.x as usize, n.y as usize).blocked {
count += 1;
if count == num {

View file

@ -1,7 +1,5 @@
use std::fmt::Debug;
use crate::misc::{Arena, ArenaKey};
use super::PriorityQueue;
type Index = u32;