cleaner screen init
This commit is contained in:
+4
-2
@@ -26,8 +26,9 @@ impl AI for Ant {
|
|||||||
} else {
|
} else {
|
||||||
let pos = choice.unwrap();
|
let pos = choice.unwrap();
|
||||||
if w.cleared.contains(&pos) {
|
if w.cleared.contains(&pos) {
|
||||||
|
let old_pos = self.pos;
|
||||||
self.pos = pos;
|
self.pos = pos;
|
||||||
return BoardCommand::Noop;
|
return BoardCommand::Move(old_pos, pos);
|
||||||
} else {
|
} else {
|
||||||
return BoardCommand::Dig(pos);
|
return BoardCommand::Dig(pos);
|
||||||
}
|
}
|
||||||
@@ -70,8 +71,9 @@ impl AI for Queen {
|
|||||||
self.egg_count += 1;
|
self.egg_count += 1;
|
||||||
return BoardCommand::LayEgg(pos, self.id);
|
return BoardCommand::LayEgg(pos, self.id);
|
||||||
} else {
|
} else {
|
||||||
|
let old_pos = self.pos;
|
||||||
self.pos = pos;
|
self.pos = pos;
|
||||||
return BoardCommand::Noop;
|
return BoardCommand::Move(old_pos, pos);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return BoardCommand::Noop;
|
return BoardCommand::Noop;
|
||||||
|
|||||||
@@ -8,6 +8,20 @@ pub struct Screen {
|
|||||||
|
|
||||||
use ncurses::*;
|
use ncurses::*;
|
||||||
|
|
||||||
|
pub fn init_screen() -> Screen {
|
||||||
|
initscr();
|
||||||
|
|
||||||
|
/* Invisible cursor. */
|
||||||
|
curs_set(CURSOR_VISIBILITY::CURSOR_INVISIBLE);
|
||||||
|
|
||||||
|
let mut max_x = 0;
|
||||||
|
let mut max_y = 0;
|
||||||
|
|
||||||
|
getmaxyx(stdscr(), &mut max_y, &mut max_x);
|
||||||
|
|
||||||
|
Screen::new(max_x, max_y)
|
||||||
|
}
|
||||||
|
|
||||||
impl Screen {
|
impl Screen {
|
||||||
pub fn new(max_x: i32, max_y: i32) -> Screen {
|
pub fn new(max_x: i32, max_y: i32) -> Screen {
|
||||||
Screen {
|
Screen {
|
||||||
@@ -60,6 +74,7 @@ fn test_get_valid_movements_board() {
|
|||||||
|
|
||||||
pub enum BoardCommand {
|
pub enum BoardCommand {
|
||||||
Dig(Point),
|
Dig(Point),
|
||||||
|
Move(Point, Point),
|
||||||
LayEgg(Point, u32),
|
LayEgg(Point, u32),
|
||||||
Hatch(u32, u32),
|
Hatch(u32, u32),
|
||||||
Noop,
|
Noop,
|
||||||
|
|||||||
+8
-14
@@ -15,7 +15,7 @@ mod lib {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use lib::point::Point;
|
use lib::point::Point;
|
||||||
use lib::screen::{BoardCommand, Screen};
|
use lib::screen::{init_screen, BoardCommand, Screen};
|
||||||
use lib::world::World;
|
use lib::world::World;
|
||||||
use lib::entity::{Queen, Entities};
|
use lib::entity::{Queen, Entities};
|
||||||
|
|
||||||
@@ -38,6 +38,12 @@ fn simulate(e: &mut Entities, w: &mut World, b: &mut Screen) {
|
|||||||
|
|
||||||
for cmd in cmds {
|
for cmd in cmds {
|
||||||
match cmd {
|
match cmd {
|
||||||
|
BoardCommand::Move(old_pos, pos) => {
|
||||||
|
// still makes no difference
|
||||||
|
// occupied needs to be updated as soon as the move is made...
|
||||||
|
w.occupied.remove(&old_pos);
|
||||||
|
w.occupied.insert(pos);
|
||||||
|
}
|
||||||
BoardCommand::Dig(pos) => {
|
BoardCommand::Dig(pos) => {
|
||||||
w.clear(pos);
|
w.clear(pos);
|
||||||
}
|
}
|
||||||
@@ -56,23 +62,11 @@ fn simulate(e: &mut Entities, w: &mut World, b: &mut Screen) {
|
|||||||
BoardCommand::Noop => {}
|
BoardCommand::Noop => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
w.occupied.clear();
|
|
||||||
let _ = e.data.values().map(|p| w.occupied.insert(p.get_position()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
initscr();
|
let mut board = init_screen();
|
||||||
|
|
||||||
/* Invisible cursor. */
|
|
||||||
curs_set(CURSOR_VISIBILITY::CURSOR_INVISIBLE);
|
|
||||||
|
|
||||||
let mut max_x = 0;
|
|
||||||
let mut max_y = 0;
|
|
||||||
|
|
||||||
getmaxyx(stdscr(), &mut max_y, &mut max_x);
|
|
||||||
|
|
||||||
let mut board = Screen::new(max_x, max_y);
|
|
||||||
let mut world = World::new();
|
let mut world = World::new();
|
||||||
|
|
||||||
let mut entities = Entities::new();
|
let mut entities = Entities::new();
|
||||||
|
|||||||
Reference in New Issue
Block a user