Display priorities.

This commit is contained in:
Juergen Stuber 2018-12-02 15:55:51 +01:00
parent 00e5e4fcf8
commit 4c5d693dfd
2 changed files with 48 additions and 16 deletions

View File

@ -39,7 +39,15 @@ fn send<T: Write>(w: &mut T, board: &Board) -> std::io::Result<()> {
for square in line { for square in line {
let c = match square { let c = match square {
Square::Unused => Color::black(), Square::Unused => Color::black(),
Square::Unknown { .. } => Color::black(), Square::Unknown { prio } => {
if *prio == 0 {
Color::black()
} else if *prio < 0 {
Color::lightblue()
} else {
Color::darkyellow()
}
}
Square::Corridor => Color::yellow(), Square::Corridor => Color::yellow(),
Square::Wall => Color::darkblue(), Square::Wall => Color::darkblue(),
Square::Start => Color::red(), Square::Start => Color::red(),
@ -91,19 +99,27 @@ impl Board {
fn set_orientation(&mut self, desired: Orientation, pos: Point2d) { fn set_orientation(&mut self, desired: Orientation, pos: Point2d) {
let sq = self.get(pos); let sq = self.get(pos);
let actual;
match sq { match sq {
Square::Unknown { .. } => { Square::Unknown { .. } => {
// determine wall orientation let prio;
if pos.x % 2 == 0 && pos.y % 2 != 0 { if pos.x % 2 == 0 && pos.y % 2 != 0 {
actual = Orientation::Vertical; // horizontal corridor, vertical wall
prio = if desired == Orientation::Vertical {
10
} else {
-10
};
} else if pos.x % 2 != 0 && pos.y % 2 == 0 { } else if pos.x % 2 != 0 && pos.y % 2 == 0 {
actual = Orientation::Horizontal; // vertical corridor, horizontal wall
prio = if desired == Orientation::Horizontal {
10
} else {
-10
};
} else { } else {
// not a potential wall, unused // always corridor at the end
actual = Orientation::Horizontal; prio = 0;
} }
let prio = if actual == desired { 10 } else { -10 };
self.set(pos, Square::Unknown { prio }); self.set(pos, Square::Unknown { prio });
} }
_ => (), _ => (),

View File

@ -39,7 +39,15 @@ fn send<T: Write>(w: &mut T, board: &Board) -> std::io::Result<()> {
for square in line { for square in line {
let c = match square { let c = match square {
Square::Unused => Color::black(), Square::Unused => Color::black(),
Square::Unknown { .. } => Color::black(), Square::Unknown { prio } => {
if *prio == 0 {
Color::black()
} else if *prio < 0 {
Color::lightblue()
} else {
Color::darkyellow()
}
}
Square::Corridor => Color::yellow(), Square::Corridor => Color::yellow(),
Square::Wall => Color::darkblue(), Square::Wall => Color::darkblue(),
Square::Start => Color::red(), Square::Start => Color::red(),
@ -93,19 +101,27 @@ impl Board {
fn set_orientation(&mut self, desired: Orientation, pos: Point2d) { fn set_orientation(&mut self, desired: Orientation, pos: Point2d) {
let sq = self.get(pos); let sq = self.get(pos);
let actual;
match sq { match sq {
Square::Unknown { .. } => { Square::Unknown { .. } => {
// determine corridor orientation let prio;
if pos.x % 2 == 0 && pos.y % 2 != 0 { if pos.x % 2 == 0 && pos.y % 2 != 0 {
actual = Orientation::Horizontal; // horizontal corridor, vertical wall
prio = if desired == Orientation::Horizontal {
10
} else {
-10
};
} else if pos.x % 2 != 0 && pos.y % 2 == 0 { } else if pos.x % 2 != 0 && pos.y % 2 == 0 {
actual = Orientation::Vertical; // vertical corridor, horizontal wall
prio = if desired == Orientation::Vertical {
10
} else {
-10
};
} else { } else {
// not a potential wall, unused // always corridor at the end
actual = Orientation::Horizontal; prio = 0;
} }
let prio = if actual == desired { 10 } else { -10 };
self.set(pos, Square::Unknown { prio }); self.set(pos, Square::Unknown { prio });
} }
_ => (), _ => (),