summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs
index 6c2f375..2b5f9b1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,6 +3,7 @@ use std::{
net::SocketAddr,
sync::Arc,
collections::HashMap,
+ num::NonZeroUsize,
};
mod types;
@@ -48,15 +49,16 @@ async fn tokio_main(conf: Config) -> Result<(), Box<dyn Error>> {
let rooms = rooms.clone();
let pubs = pubs.clone();
async move {
- if let (Some(w),Some(h),Some(num),Some(denom),access,limit) = (
- rinfo.get("rwidth").and_then(|wt| wt.parse::<usize>().ok()),
- rinfo.get("rheight").and_then(|ht| ht.parse::<usize>().ok()),
+ if let (Some(w),Some(h),Some(num),Some(denom),access,asfm,limit) = (
+ rinfo.get("rwidth").and_then(|wt| wt.parse::<NonZeroUsize>().ok()),
+ rinfo.get("rheight").and_then(|ht| ht.parse::<NonZeroUsize>().ok()),
rinfo.get("rration").and_then(|nt| nt.parse::<usize>().ok()),
- rinfo.get("rratiod").and_then(|dt| dt.parse::<usize>().ok()),
+ rinfo.get("rratiod").and_then(|dt| dt.parse::<NonZeroUsize>().ok()),
rinfo.get("raccess"),
+ rinfo.get("ralwayssafe1move"),
rinfo.get("rlimit").and_then(|l| l.parse::<usize>().ok()),
) {
- let board_conf = BoardConf { w, h, mine_ratio: (num,denom) };
+ let board_conf = minesweeper::BoardConf { w, h, mine_ratio: (num,denom), always_safe_first_move: asfm.is_some() };
let name = rinfo.get("rname").map(|r| r.to_owned()).unwrap_or(format!("{w}x{h} room"));
let mut rooms = rooms.write().await;
@@ -151,10 +153,9 @@ async fn tokio_main(conf: Config) -> Result<(), Box<dyn Error>> {
}
// If a move is made, broadcast new board, else just send current board
-async fn gameloop(mut move_rx: tokio::sync::mpsc::UnboundedReceiver<MetaMove>, players: PlayerMapData, bconf: BoardConf) {
+async fn gameloop(mut move_rx: tokio::sync::mpsc::UnboundedReceiver<MetaMove>, players: PlayerMapData, bconf: minesweeper::BoardConf) {
use minesweeper::*;
- let mine_cnt = (bconf.w * bconf.h * bconf.mine_ratio.0)/(bconf.mine_ratio.1);
- let mut game = Game::new(Board::new(bconf.w, bconf.h), mine_cnt);
+ let mut game = Game::new(bconf);
let mut latest_player_name = None;
while let Some(req) = move_rx.recv().await {
let done = game.phase == Phase::Die || game.phase == Phase::Win;
@@ -167,7 +168,7 @@ async fn gameloop(mut move_rx: tokio::sync::mpsc::UnboundedReceiver<MetaMove>, p
latest_player_name = players.read().await.get(&o).map(|p| p.name.clone());
},
MetaMove::Dump => (),
- MetaMove::Reset => { game = Game::new(Board::new(bconf.w, bconf.h), mine_cnt); },
+ MetaMove::Reset => { game = Game::new(bconf); },
}
use warp::ws::Message;
let mut reply = vec![Message::binary(game.board.render())];