atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
2176d9a94bd9f6eaed0b8222251bd637ca2fb4a7
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git
src/game/measure.rsRust49 lines1.2 KB
1
use axum::http::StatusCode;
2
use serde_json::json;
3
4
use super::{
5
    Outcome, Run,
6
    balance::{HONEST_TOLERANCE, PUT_GAIN},
7
};
8
use crate::problem::Problem;
9
10
pub fn round2(x: f64) -> f64 {
11
    (x * 100.0).round() / 100.0
12
}
13
14
pub(super) fn round3(x: f64) -> f64 {
15
    (x * 1000.0).round() / 1000.0
16
}
17
18
pub(super) fn honest(claimed: f64, actual: f64) -> bool {
19
    (claimed - actual).abs() < HONEST_TOLERANCE
20
}
21
22
/// A cylinder whose circumference is the girth.
23
pub fn volume(length: f64, girth: f64) -> f64 {
24
    girth * girth * length / (4.0 * std::f64::consts::PI)
25
}
26
27
pub fn shaft(mm: usize) -> String {
28
    format!("8{}D", "=".repeat(mm.saturating_sub(2)))
29
}
30
31
pub(super) fn exaggeration() -> Problem {
32
    Problem::new(
33
        StatusCode::BAD_REQUEST,
34
        "exaggeration",
35
        "The server has measured. Lying is not a technique.",
36
    )
37
}
38
39
impl Run {
40
    pub fn put(&mut self) -> Outcome {
41
        if self.body.put_applied {
42
            return Outcome::empty(StatusCode::NO_CONTENT);
43
        }
44
        self.body.put_applied = true;
45
        self.body.length += PUT_GAIN;
46
        self.touch();
47
        Outcome::json(StatusCode::OK, json!({ "detail": "Applied." }))
48
    }
49
}