-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7e252b
commit 3f7faf1
Showing
4 changed files
with
102 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,51 @@ | ||
use std::net::SocketAddr; | ||
|
||
pub(crate) type Position = (u32, u32); | ||
|
||
#[derive(Debug, Default, Clone)] | ||
pub(crate) struct Board; | ||
pub(crate) struct Board { | ||
tiles: Vec<Tile>, | ||
pub(crate) width: u16, | ||
pub(crate) height: u16, | ||
} | ||
|
||
impl Board { | ||
pub(crate) fn place(&mut self, x: u32, y: u32, addr: SocketAddr) { | ||
todo!() | ||
pub(crate) fn new(width: u16, height: u16) -> Self { | ||
Board { | ||
tiles: vec![Tile::Empty; usize::from(width) * usize::from(height)], | ||
width, | ||
height, | ||
} | ||
} | ||
|
||
pub(crate) fn place(&mut self, x: u16, y: u16, id: u8) { | ||
let x = usize::from(x.min(self.width)); | ||
let y = usize::from(y.min(self.height)); | ||
self.tiles[x + usize::from(self.width) * y] = Tile::Player(id); | ||
} | ||
|
||
pub(crate) fn serialize(&self) -> String { | ||
format!("BOARD") | ||
self.tiles.iter().map(Tile::to_char).collect() | ||
} | ||
} | ||
|
||
pub enum GoError { | ||
OutOfBounds, | ||
Suicide, | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, Default)] | ||
enum Tile { | ||
#[default] | ||
Empty, | ||
Wall, | ||
Player(u8), | ||
} | ||
|
||
impl Tile { | ||
fn to_char(&self) -> char { | ||
match self { | ||
Tile::Empty => '.', | ||
Tile::Wall => '/', | ||
Tile::Player(c) => *c as char, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters