cleaner screen init
This commit is contained in:
+4
-2
@@ -26,8 +26,9 @@ impl AI for Ant {
|
||||
} else {
|
||||
let pos = choice.unwrap();
|
||||
if w.cleared.contains(&pos) {
|
||||
let old_pos = self.pos;
|
||||
self.pos = pos;
|
||||
return BoardCommand::Noop;
|
||||
return BoardCommand::Move(old_pos, pos);
|
||||
} else {
|
||||
return BoardCommand::Dig(pos);
|
||||
}
|
||||
@@ -70,8 +71,9 @@ impl AI for Queen {
|
||||
self.egg_count += 1;
|
||||
return BoardCommand::LayEgg(pos, self.id);
|
||||
} else {
|
||||
let old_pos = self.pos;
|
||||
self.pos = pos;
|
||||
return BoardCommand::Noop;
|
||||
return BoardCommand::Move(old_pos, pos);
|
||||
}
|
||||
} else {
|
||||
return BoardCommand::Noop;
|
||||
|
||||
@@ -8,6 +8,20 @@ pub struct Screen {
|
||||
|
||||
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 {
|
||||
pub fn new(max_x: i32, max_y: i32) -> Screen {
|
||||
Screen {
|
||||
@@ -60,6 +74,7 @@ fn test_get_valid_movements_board() {
|
||||
|
||||
pub enum BoardCommand {
|
||||
Dig(Point),
|
||||
Move(Point, Point),
|
||||
LayEgg(Point, u32),
|
||||
Hatch(u32, u32),
|
||||
Noop,
|
||||
|
||||
+8
-14
@@ -15,7 +15,7 @@ mod lib {
|
||||
}
|
||||
|
||||
use lib::point::Point;
|
||||
use lib::screen::{BoardCommand, Screen};
|
||||
use lib::screen::{init_screen, BoardCommand, Screen};
|
||||
use lib::world::World;
|
||||
use lib::entity::{Queen, Entities};
|
||||
|
||||
@@ -38,6 +38,12 @@ fn simulate(e: &mut Entities, w: &mut World, b: &mut Screen) {
|
||||
|
||||
for cmd in cmds {
|
||||
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) => {
|
||||
w.clear(pos);
|
||||
}
|
||||
@@ -56,23 +62,11 @@ fn simulate(e: &mut Entities, w: &mut World, b: &mut Screen) {
|
||||
BoardCommand::Noop => {}
|
||||
}
|
||||
}
|
||||
w.occupied.clear();
|
||||
let _ = e.data.values().map(|p| w.occupied.insert(p.get_position()));
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
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);
|
||||
|
||||
let mut board = Screen::new(max_x, max_y);
|
||||
let mut board = init_screen();
|
||||
let mut world = World::new();
|
||||
|
||||
let mut entities = Entities::new();
|
||||
|
||||
Reference in New Issue
Block a user