upkeep bug
This commit is contained in:
parent
7c7554dc8e
commit
b33eb4d106
@ -1,12 +1,13 @@
|
||||
use uuid::Uuid;
|
||||
use rand::prelude::*;
|
||||
use rand::distributions::{Normal, WeightedIndex};
|
||||
|
||||
use std::f64;
|
||||
use std::fs::copy;
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
use std::char::from_u32;
|
||||
|
||||
use uuid::Uuid;
|
||||
use rand::prelude::*;
|
||||
use rand::distributions::{Normal, WeightedIndex};
|
||||
|
||||
use failure::Error;
|
||||
use failure::err_msg;
|
||||
|
||||
@ -36,8 +37,8 @@ pub fn invader_write(id: Uuid) -> Result<Uuid, Error> {
|
||||
// filters ?
|
||||
|
||||
// distribution for lightness
|
||||
// bellcurve around 50%
|
||||
let l_dist = Normal::new(50.0, 10.0);
|
||||
// bellcurve around 75%
|
||||
let l_dist = Normal::new(75.0, 10.0);
|
||||
let s_dist = Normal::new(25.0, 10.0);
|
||||
|
||||
let mut colours = std::iter
|
||||
@ -83,7 +84,104 @@ pub fn invader_write(id: Uuid) -> Result<Uuid, Error> {
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
fn hieroglyph() -> String {
|
||||
enum ConstructShape {
|
||||
Square,
|
||||
Triangle,
|
||||
Circle,
|
||||
Line,
|
||||
V,
|
||||
Tri,
|
||||
Plus,
|
||||
Blank,
|
||||
}
|
||||
|
||||
// default ? shape
|
||||
pub fn construct(id: Uuid) -> Result<Uuid, Error> {
|
||||
let mut rng = thread_rng();
|
||||
let mut svg = Vec::new();
|
||||
|
||||
// distribution for lightness
|
||||
// bellcurve around 75%
|
||||
let l_dist = Normal::new(50.0, 10.0);
|
||||
let s_dist = Normal::new(25.0, 10.0);
|
||||
|
||||
// 8 6 or 4 points in shape
|
||||
// 1 head point
|
||||
// n / 2 shapes with a colour each
|
||||
// random size/radius props for each
|
||||
|
||||
// add up to 100 for %
|
||||
let shapes = [
|
||||
(ConstructShape::Square, 100),
|
||||
// (ConstructShape::Triangle, 10),
|
||||
// (ConstructShape::Circle, 10),
|
||||
// (ConstructShape::Line, 10),
|
||||
// (ConstructShape::V, 10),
|
||||
// (ConstructShape::Tri, 3),
|
||||
// (ConstructShape::Plus, 5),
|
||||
// (ConstructShape::Blank, 1),
|
||||
];
|
||||
let shape_dist = WeightedIndex::new(shapes.iter().map(|v| v.1))?;
|
||||
|
||||
let n_shapes = rng.gen_range(2, 10);
|
||||
|
||||
write!(&mut svg, "<svg xmlns='http://www.w3.org/2000/svg' version='1.1' viewBox='-500 -500 1000 1000' width='1000' height='1000'><g>")?;
|
||||
for i in 0..n_shapes - 1 {
|
||||
let h = rng.gen_range(0, 360);
|
||||
let s = s_dist.sample(&mut rng) as usize;
|
||||
let l = l_dist.sample(&mut rng) as usize;
|
||||
let colour = format!("hsl({:}, {:}%, {:}%)", h, s, l);
|
||||
|
||||
let fraction: f64 = (1.0 / n_shapes as f64) * i as f64;
|
||||
let angle: f64 = (fraction * 180.0) / f64::consts::PI;
|
||||
|
||||
match shapes[shape_dist.sample(&mut rng)].0 {
|
||||
ConstructShape::Square => {
|
||||
let size = rng.gen_range(5, 50);
|
||||
let distance = rng.gen_range(50, 200);
|
||||
let rotation = rng.gen_range(0, 180);
|
||||
write!(&mut svg, "<rect fill=\"{}\" x=\"-{}\" y=\"{}\" width=\"{}\" height=\"{}\" transform=\"rotate({}) translate(0, {}) rotate({})\" />",
|
||||
colour, size / 2, size / 2, size, size, rotation, distance, angle)?;
|
||||
write!(&mut svg, "<rect fill=\"{}\" x=\"-{}\" y=\"{}\" width=\"{}\" height=\"{}\" transform=\"rotate({}) translate(0, {}) rotate({})\" />",
|
||||
colour, size / 2, size / 2, size, size, rotation, distance, angle + 180.0)?;
|
||||
},
|
||||
ConstructShape::Triangle => {
|
||||
|
||||
},
|
||||
ConstructShape::Circle => {
|
||||
|
||||
},
|
||||
ConstructShape::Line => {
|
||||
|
||||
},
|
||||
ConstructShape::V => {
|
||||
|
||||
},
|
||||
ConstructShape::Tri => {
|
||||
|
||||
},
|
||||
ConstructShape::Plus => {
|
||||
|
||||
},
|
||||
ConstructShape::Blank => {
|
||||
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
write!(&mut svg, "</g></svg>")?;
|
||||
|
||||
let dest = format!("/var/lib/mnml/public/imgs/{}.svg", id);
|
||||
println!("default dest={:?}", dest);
|
||||
|
||||
let mut file = File::create(dest)?;
|
||||
file.write_all(&svg)?;
|
||||
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
|
||||
fn _hieroglyph() -> String {
|
||||
let mut rng = thread_rng();
|
||||
|
||||
let mut s = String::new();
|
||||
@ -99,7 +197,6 @@ fn hieroglyph() -> String {
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@ -111,9 +208,16 @@ mod tests {
|
||||
// }
|
||||
// }
|
||||
|
||||
// #[test]
|
||||
// fn hieroglyph_test() {
|
||||
// hieroglyph();
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn hieroglyph_test() {
|
||||
hieroglyph();
|
||||
fn construct_img_test() {
|
||||
for i in 0..100 {
|
||||
construct(Uuid::new_v4()).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,7 +228,7 @@ mod tests {
|
||||
// var h = Math.floor(rand() * 360);
|
||||
// //saturation goes from 40 to 100, it avoids greyish colors
|
||||
// var s = ((rand() * 60) + 40) + '%';
|
||||
// //lightness can be anything from 0 to 100, but probabilities are a bell curve around 50%
|
||||
// //lightness can be anything from 0 to 100, but probabilities are a bell curve around 75%
|
||||
// var l = ((rand()+rand()+rand()+rand()) * 25) + '%';
|
||||
|
||||
// var color = 'hsl(' + h + ',' + s + ',' + l + ')';
|
||||
|
||||
@ -271,6 +271,9 @@ impl Instance {
|
||||
let mut game = Game::new();
|
||||
current_round.game_id = Some(game.id);
|
||||
|
||||
// disable upkeep until players finish their game
|
||||
self.phase_end = None;
|
||||
|
||||
game
|
||||
.set_player_num(2)
|
||||
.set_player_constructs(3)
|
||||
@ -303,7 +306,6 @@ impl Instance {
|
||||
self.phase_start = Utc::now();
|
||||
self.phase_end = self.time_control.vbox_phase_end();
|
||||
|
||||
|
||||
self.players.iter_mut().for_each(|p| {
|
||||
p.set_ready(false);
|
||||
p.vbox.fill();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user