Fix warnings.
This commit is contained in:
parent
8c29cb1e53
commit
1596bf180d
8 changed files with 54 additions and 71 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
|
@ -456,9 +456,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.10.3"
|
version = "1.10.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15"
|
checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aho-corasick",
|
"aho-corasick",
|
||||||
"memchr",
|
"memchr",
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ where
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
input.clear();
|
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(), ""));
|
let (cmd, arg) = input.trim().split_once(' ').unwrap_or((input.trim(), ""));
|
||||||
// dbg!(cmd, arg);
|
// dbg!(cmd, arg);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ enum Mode {
|
||||||
|
|
||||||
#[derive(ValueEnum, Clone)]
|
#[derive(ValueEnum, Clone)]
|
||||||
enum ProblemCase {
|
enum ProblemCase {
|
||||||
simple,
|
Simple,
|
||||||
Level1,
|
Level1,
|
||||||
Level2,
|
Level2,
|
||||||
Level3,
|
Level3,
|
||||||
|
|
@ -21,7 +21,7 @@ enum ProblemCase {
|
||||||
impl ProblemCase {
|
impl ProblemCase {
|
||||||
fn get_problem(&self) -> Problem {
|
fn get_problem(&self) -> Problem {
|
||||||
match self {
|
match self {
|
||||||
ProblemCase::simple => problems::simple(),
|
ProblemCase::Simple => problems::simple(),
|
||||||
ProblemCase::Level1 => problems::belt_madness_level_1(),
|
ProblemCase::Level1 => problems::belt_madness_level_1(),
|
||||||
ProblemCase::Level2 => problems::belt_madness_level_2(),
|
ProblemCase::Level2 => problems::belt_madness_level_2(),
|
||||||
ProblemCase::Level3 => problems::belt_madness_level_3(),
|
ProblemCase::Level3 => problems::belt_madness_level_3(),
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use super::{
|
use super::{
|
||||||
common::{print_map, Dimension, Direction, PathField, PositionType},
|
common::{print_map, Direction, PathField, PositionType},
|
||||||
Position, COLORS,
|
Position, COLORS,
|
||||||
};
|
};
|
||||||
use crate::misc::Map;
|
use crate::misc::Map;
|
||||||
|
|
@ -66,10 +66,6 @@ impl BruteforceBuilder {
|
||||||
|
|
||||||
pub fn build(self) -> Bruteforce {
|
pub fn build(self) -> Bruteforce {
|
||||||
// dbg!(&self);
|
// dbg!(&self);
|
||||||
let dimension = Dimension {
|
|
||||||
width: self.map.width,
|
|
||||||
height: self.map.height,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut b = Bruteforce {
|
let mut b = Bruteforce {
|
||||||
map: self.map,
|
map: self.map,
|
||||||
|
|
@ -77,7 +73,6 @@ impl BruteforceBuilder {
|
||||||
pointer_stack: vec![0],
|
pointer_stack: vec![0],
|
||||||
solution_count: 0,
|
solution_count: 0,
|
||||||
count: 0,
|
count: 0,
|
||||||
dimension,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for [start, end] in self.path {
|
for [start, end] in self.path {
|
||||||
|
|
@ -111,7 +106,6 @@ struct Problem {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Bruteforce {
|
pub struct Bruteforce {
|
||||||
map: Map<BruteforceField>,
|
map: Map<BruteforceField>,
|
||||||
dimension: Dimension,
|
|
||||||
problems: Vec<Problem>,
|
problems: Vec<Problem>,
|
||||||
pointer_stack: Vec<usize>,
|
pointer_stack: Vec<usize>,
|
||||||
solution_count: u128,
|
solution_count: u128,
|
||||||
|
|
@ -654,7 +648,7 @@ impl Bruteforce {
|
||||||
|
|
||||||
// Print body
|
// 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) {
|
if let Some((i, c)) = m.get(x as usize, y as usize) {
|
||||||
let mut color = ColorSpec::new();
|
let mut color = ColorSpec::new();
|
||||||
color.set_fg(Some(COLORS[*i]));
|
color.set_fg(Some(COLORS[*i]));
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
use core::panic;
|
use core::panic;
|
||||||
use std::io::Write;
|
use std::io::{self, Write};
|
||||||
|
|
||||||
use base64::write;
|
|
||||||
use termcolor::{ColorSpec, StandardStream, WriteColor};
|
use termcolor::{ColorSpec, StandardStream, WriteColor};
|
||||||
|
|
||||||
pub type PositionType = i32;
|
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
|
where
|
||||||
F: Fn(i32, i32) -> (ColorSpec, &'static str),
|
F: Fn(i32, i32) -> (ColorSpec, &'static str),
|
||||||
{
|
{
|
||||||
|
|
@ -218,35 +217,35 @@ where
|
||||||
|
|
||||||
//padding
|
//padding
|
||||||
for _ in 0..height_digits {
|
for _ in 0..height_digits {
|
||||||
write!(stdout, " ");
|
write!(stdout, " ")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for x in 0..width {
|
for x in 0..width {
|
||||||
let digits = x / (i32::pow(10, d));
|
let digits = x / (i32::pow(10, d));
|
||||||
if digits == 0 && d > 0 {
|
if digits == 0 && d > 0 {
|
||||||
write!(stdout, " ");
|
write!(stdout, " ")?;
|
||||||
} else {
|
} else {
|
||||||
write!(
|
write!(
|
||||||
stdout,
|
stdout,
|
||||||
"{}",
|
"{}",
|
||||||
char::from_u32((digits % 10) as u32 + 48).unwrap()
|
char::from_u32((digits % 10) as u32 + 48).unwrap()
|
||||||
);
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writeln!(stdout);
|
writeln!(stdout)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for y in 0..height {
|
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 {
|
for x in 0..width {
|
||||||
let (c, s) = f(x, y);
|
let (c, s) = f(x, y);
|
||||||
stdout.set_color(&c);
|
stdout.set_color(&c)?;
|
||||||
write!(stdout, "{:1}", s);
|
write!(stdout, "{:1}", s)?;
|
||||||
stdout.reset();
|
stdout.reset()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeln!(stdout, "{:1$}", y, height_digits as usize);
|
writeln!(stdout, "{:1$}", y, height_digits as usize)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in 0..width_digits {
|
for i in 0..width_digits {
|
||||||
|
|
@ -254,21 +253,23 @@ where
|
||||||
|
|
||||||
//padding
|
//padding
|
||||||
for _ in 0..height_digits {
|
for _ in 0..height_digits {
|
||||||
write!(stdout, " ");
|
write!(stdout, " ")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for x in 0..width {
|
for x in 0..width {
|
||||||
let digits = x / (i32::pow(10, d));
|
let digits = x / (i32::pow(10, d));
|
||||||
if digits == 0 && d > 0 {
|
if digits == 0 && d > 0 {
|
||||||
write!(stdout, " ");
|
write!(stdout, " ")?;
|
||||||
} else {
|
} else {
|
||||||
write!(
|
write!(
|
||||||
stdout,
|
stdout,
|
||||||
"{}",
|
"{}",
|
||||||
char::from_u32((digits % 10) as u32 + 48).unwrap()
|
char::from_u32((digits % 10) as u32 + 48).unwrap()
|
||||||
);
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writeln!(stdout);
|
writeln!(stdout)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ impl ConflictAvoidance {
|
||||||
}
|
}
|
||||||
let mut belts = Vec::new();
|
let mut belts = Vec::new();
|
||||||
for i in 0..problem.path.len() {
|
for i in 0..problem.path.len() {
|
||||||
dbg!(&problem.path[i]);
|
// dbg!(&problem.path[i]);
|
||||||
let mut p = Vec::new();
|
let mut p = Vec::new();
|
||||||
|
|
||||||
p.push(PathField::Belt {
|
p.push(PathField::Belt {
|
||||||
|
|
@ -87,7 +87,7 @@ impl ConflictAvoidance {
|
||||||
for (pos, dir) in &problem.path[i][1..] {
|
for (pos, dir) in &problem.path[i][1..] {
|
||||||
let start = p.last().unwrap().end_pos();
|
let start = p.last().unwrap().end_pos();
|
||||||
let start = start.0.in_direction(&start.1, 1);
|
let start = start.0.in_direction(&start.1, 1);
|
||||||
dbg!(start, pos);
|
// dbg!(start, pos);
|
||||||
if &start == pos {
|
if &start == pos {
|
||||||
p.push(PathField::Belt {
|
p.push(PathField::Belt {
|
||||||
pos: *pos,
|
pos: *pos,
|
||||||
|
|
@ -97,7 +97,10 @@ impl ConflictAvoidance {
|
||||||
p.push(PathField::Underground {
|
p.push(PathField::Underground {
|
||||||
pos: start,
|
pos: start,
|
||||||
dir: *dir,
|
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,
|
// pos: problem.end[i].0,
|
||||||
// dir: problem.end[i].1,
|
// dir: problem.end[i].1,
|
||||||
// });
|
// });
|
||||||
dbg!(&p);
|
|
||||||
|
|
||||||
belts.push(p);
|
belts.push(p);
|
||||||
}
|
}
|
||||||
|
|
@ -157,7 +159,7 @@ impl ConflictAvoidance {
|
||||||
let mut mapping = Vec::new();
|
let mut mapping = Vec::new();
|
||||||
let offset = Position::new(*xrange.start() as i32 - 1, *yrange.start() as i32 - 1);
|
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() {
|
for (i, path) in self.belts.iter().enumerate() {
|
||||||
// index of first PathField where the next position is in the area
|
// 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);
|
.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) {
|
if let Some((start_index, end_index)) = Option::zip(start_index, end_index) {
|
||||||
// dbg!(start_index, end_index, path[start_index], path[end_index]);
|
// dbg!(start_index, end_index, path[start_index], path[end_index]);
|
||||||
|
|
||||||
|
|
@ -268,7 +268,7 @@ impl ConflictAvoidance {
|
||||||
Some(
|
Some(
|
||||||
mapping
|
mapping
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.zip(solutions.into_iter())
|
.zip(solutions)
|
||||||
.map(|((path_id, start, end), path)| BruteForceEntry {
|
.map(|((path_id, start, end), path)| BruteForceEntry {
|
||||||
path_id,
|
path_id,
|
||||||
start,
|
start,
|
||||||
|
|
@ -305,16 +305,16 @@ impl ConflictAvoidance {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for y in 0..self.map.height {
|
// for y in 0..self.map.height {
|
||||||
for x in 0..self.map.width {
|
// for x in 0..self.map.width {
|
||||||
if *conflicts.get(x, y) > 1 {
|
// if *conflicts.get(x, y) > 1 {
|
||||||
print!("#");
|
// print!("#");
|
||||||
} else {
|
// } else {
|
||||||
print!(" ");
|
// print!(" ");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
println!();
|
// println!();
|
||||||
}
|
// }
|
||||||
|
|
||||||
let mut candidates = Vec::new();
|
let mut candidates = Vec::new();
|
||||||
|
|
||||||
|
|
@ -506,7 +506,7 @@ impl ConflictAvoidance {
|
||||||
}
|
}
|
||||||
// Print body
|
// 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();
|
let mut color = ColorSpec::new();
|
||||||
|
|
||||||
if let Some((xrange, yrange)) = &self.range {
|
if let Some((xrange, yrange)) = &self.range {
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
use crate::graph::wheighted_graph::WheightedGraph;
|
use crate::graph::wheighted_graph::WheightedGraph;
|
||||||
use crate::misc::Map;
|
use crate::misc::Map;
|
||||||
use crate::priority_queue::BinaryHeap;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
graph::wheighted_graph::shortest_path::dijkstra, priority_queue::fibonacci_heap::FibonacciHeap,
|
graph::wheighted_graph::shortest_path::dijkstra, priority_queue::fibonacci_heap::FibonacciHeap,
|
||||||
};
|
};
|
||||||
use std::ops::Index;
|
use std::ops::Index;
|
||||||
use termcolor::{Color, ColorSpec};
|
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 brute_force;
|
||||||
pub mod common;
|
pub mod common;
|
||||||
|
|
@ -89,7 +88,7 @@ impl Problem {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print(&self) {
|
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();
|
let mut color = ColorSpec::new();
|
||||||
if let Some(i) = self
|
if let Some(i) = self
|
||||||
.start
|
.start
|
||||||
|
|
@ -158,18 +157,13 @@ impl<'a> WheightedGraph for MapInternal<'a> {
|
||||||
|
|
||||||
fn edge(&self, node: &Self::Node, num: usize) -> Option<(Self::Node, f64)> {
|
fn edge(&self, node: &Self::Node, num: usize) -> Option<(Self::Node, f64)> {
|
||||||
let next = node.0.in_direction(&node.1, 1);
|
let next = node.0.in_direction(&node.1, 1);
|
||||||
if next
|
next.in_range(
|
||||||
.in_range(
|
&Position::new(0, 0),
|
||||||
&Position::new(0, 0),
|
&Position::new(
|
||||||
&Position::new(
|
self.map.width as PositionType,
|
||||||
self.map.width as PositionType,
|
self.map.height as PositionType,
|
||||||
self.map.height as PositionType,
|
),
|
||||||
),
|
)?;
|
||||||
)
|
|
||||||
.is_none()
|
|
||||||
{
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
if self.map.get(next.x as usize, next.y as usize).blocked && self.end != (next, node.1) {
|
if self.map.get(next.x as usize, next.y as usize).blocked && self.end != (next, node.1) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
@ -183,17 +177,13 @@ impl<'a> WheightedGraph for MapInternal<'a> {
|
||||||
let mut count = 2;
|
let mut count = 2;
|
||||||
for l in 2..=6 {
|
for l in 2..=6 {
|
||||||
let n = node.0.in_direction(&node.1, l);
|
let n = node.0.in_direction(&node.1, l);
|
||||||
if n.in_range(
|
n.in_range(
|
||||||
&Position::new(0, 0),
|
&Position::new(0, 0),
|
||||||
&Position::new(
|
&Position::new(
|
||||||
self.map.width as PositionType,
|
self.map.width as PositionType,
|
||||||
self.map.height as PositionType,
|
self.map.height as PositionType,
|
||||||
),
|
),
|
||||||
)
|
)?;
|
||||||
.is_none()
|
|
||||||
{
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
if !self.map.get(n.x as usize, n.y as usize).blocked {
|
if !self.map.get(n.x as usize, n.y as usize).blocked {
|
||||||
count += 1;
|
count += 1;
|
||||||
if count == num {
|
if count == num {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
use crate::misc::{Arena, ArenaKey};
|
|
||||||
|
|
||||||
use super::PriorityQueue;
|
use super::PriorityQueue;
|
||||||
|
|
||||||
type Index = u32;
|
type Index = u32;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue