110 lines
3.1 KiB
Rust
110 lines
3.1 KiB
Rust
use crate::{
|
|
consts::*,
|
|
piece::*,
|
|
util::Hex,
|
|
};
|
|
|
|
#[derive(Clone, Copy)]
|
|
pub struct Column {
|
|
pub militia:[bool; 2],
|
|
pub extent:[u8; 2],
|
|
}
|
|
impl Column {
|
|
pub fn new() -> Self
|
|
{
|
|
Self {
|
|
militia:[false; 2],
|
|
extent:[0, 8],
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Copy)]
|
|
pub struct Tile {
|
|
pub piece:Option<u8>,
|
|
pub threat:[bool; 2],
|
|
}
|
|
impl Tile {
|
|
pub fn new() -> Self
|
|
{
|
|
Self {
|
|
piece:None,
|
|
threat:[false; 2],
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct Board {
|
|
pub tiles:[Tile; 61],
|
|
pub columns:[Column; 9],
|
|
pub pieces:[Option<Piece>; PIECES_TOTAL],
|
|
}
|
|
impl Board {
|
|
pub fn new() -> Self
|
|
{
|
|
Self {
|
|
tiles:[Tile::new(); 61],
|
|
columns:[Column::new(); 9],
|
|
pieces:[None; PIECES_TOTAL],
|
|
}
|
|
}
|
|
|
|
pub fn init(&mut self) {
|
|
self.tiles = [Tile::new(); 61];
|
|
self.columns = [Column::new(); 9];
|
|
self.pieces = [None; PIECES_TOTAL];
|
|
|
|
let layout = [
|
|
(Piece::new(PIECE_MILITIA, PLAYER_DAWN), Hex::from_hex(0, 1)),
|
|
(Piece::new(PIECE_MILITIA, PLAYER_DAWN), Hex::from_hex(1, 1)),
|
|
(Piece::new(PIECE_MILITIA, PLAYER_DAWN), Hex::from_hex(2, 2)),
|
|
(Piece::new(PIECE_MILITIA, PLAYER_DAWN), Hex::from_hex(3, 2)),
|
|
(Piece::new(PIECE_MILITIA, PLAYER_DAWN), Hex::from_hex(4, 3)),
|
|
(Piece::new(PIECE_MILITIA, PLAYER_DAWN), Hex::from_hex(5, 3)),
|
|
(Piece::new(PIECE_MILITIA, PLAYER_DAWN), Hex::from_hex(6, 4)),
|
|
(Piece::new(PIECE_MILITIA, PLAYER_DAWN), Hex::from_hex(7, 4)),
|
|
(Piece::new(PIECE_MILITIA, PLAYER_DAWN), Hex::from_hex(8, 5)),
|
|
|
|
(Piece::new(PIECE_TOWER, PLAYER_DAWN), Hex::from_hex(0, 0)),
|
|
(Piece::new(PIECE_TOWER, PLAYER_DAWN), Hex::from_hex(8, 4)),
|
|
|
|
(Piece::new(PIECE_KNIGHT, PLAYER_DAWN), Hex::from_hex(1, 0)),
|
|
(Piece::new(PIECE_KNIGHT, PLAYER_DAWN), Hex::from_hex(7, 3)),
|
|
|
|
(Piece::new(PIECE_LANCE, PLAYER_DAWN), Hex::from_hex(2, 0)),
|
|
(Piece::new(PIECE_LANCE, PLAYER_DAWN), Hex::from_hex(6, 2)),
|
|
|
|
(Piece::new(PIECE_CASTLE, PLAYER_DAWN), Hex::from_hex(3, 0)),
|
|
(Piece::new(PIECE_CASTLE, PLAYER_DAWN), Hex::from_hex(5, 1)),
|
|
|
|
(Piece::new(PIECE_DRAGON, PLAYER_DAWN), Hex::from_hex(4, 2)),
|
|
(Piece::new(PIECE_BEHEMOTH, PLAYER_DAWN), Hex::from_hex(4, 1)),
|
|
|
|
(Piece::new(PIECE_OMEN, PLAYER_DAWN), Hex::from_hex(4, 0)),
|
|
];
|
|
|
|
for (piece, hex) in &layout {
|
|
self.set_piece(piece.clone(), hex.tile);
|
|
}
|
|
|
|
for (piece, hex) in &layout {
|
|
let mut piece = piece.clone();
|
|
piece.player = 1;
|
|
let hex = Hex::from_hex(8 - hex.x, 8 - hex.y);
|
|
self.set_piece(piece, hex.tile);
|
|
}
|
|
}
|
|
|
|
pub fn set_piece(&mut self, mut piece:Piece, tile:u8) -> u8
|
|
{
|
|
let mut index = 0;
|
|
while self.pieces[index as usize].is_some() { index += 1; }
|
|
|
|
piece.tile = tile;
|
|
self.tiles[tile as usize].piece = Some(index);
|
|
self.pieces[index as usize] = Some(piece);
|
|
index
|
|
}
|
|
}
|