2022-03-02 07:25:01 +00:00
|
|
|
use std::cell::Cell;
|
2022-03-02 06:18:10 +00:00
|
|
|
use std::rc::Rc;
|
|
|
|
use yew::prelude::*;
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
|
|
|
pub enum BoardState {
|
|
|
|
Empty,
|
|
|
|
Cyan,
|
|
|
|
Magenta,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for BoardState {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::Empty
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
|
|
|
pub enum Turn {
|
|
|
|
CyanPlayer,
|
|
|
|
MagentaPlayer,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
|
|
pub struct SharedState {
|
|
|
|
pub board: [Rc<Cell<BoardState>>; 56],
|
2022-03-02 07:25:01 +00:00
|
|
|
pub turn: Cell<Turn>,
|
2022-03-02 06:18:10 +00:00
|
|
|
pub info_text_ref: NodeRef,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for SharedState {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
// cannot use [<type>; 56] because Rc does not impl Copy
|
|
|
|
board: [
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
Rc::new(Cell::new(BoardState::default())),
|
|
|
|
],
|
2022-03-02 07:25:01 +00:00
|
|
|
turn: Cell::new(Turn::CyanPlayer),
|
2022-03-02 06:18:10 +00:00
|
|
|
info_text_ref: NodeRef::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|