From 998d27764dfba1c503d647f97a2ef673134f8822 Mon Sep 17 00:00:00 2001 From: Markus Wagner Date: Wed, 20 Jan 2021 22:34:34 +0100 Subject: [PATCH] Randomize starting player, fixes #1 --- src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 543653d..a2ffe50 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ mod cards; use async_std::{prelude::*, sync::RwLock}; use cards::*; use itertools::Itertools; -use rand::{seq::SliceRandom, thread_rng}; +use rand::{seq::SliceRandom, Rng, thread_rng}; use serde::{Deserialize, Serialize}; use std::{collections::HashMap, sync::Arc}; use tide::{Body, Redirect, Request, Response}; @@ -255,6 +255,10 @@ impl Game { GameState::Setup => { self.state = GameState::InProgress; + if self.players.len() > 1 { + self.active_player = thread_rng().gen_range(0..self.players.len()); + } + for p in self.players.iter_mut() { (*p).discard_pile = self.setup.deck.clone(); p.draw(5);