1use std::collections::HashMap;
2
3use super::slab_def::*;
4
5const SKILL_NOOB: &str = "noob";
6const SKILL_EASY: &str = "easy";
7const SKILL_MEDIUM: &str = "medium";
8const SKILL_HARD: &str = "hard";
9const SKILL_EXPERT: &str = "expert";
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum Skill {
14 Noob,
15 Easy,
16 Medium,
17 Hard,
18 Expert,
19}
20
21impl Skill {
22 pub fn from_str(name: &str) -> Self {
23 match name {
24 SKILL_NOOB => Skill::Noob,
25 SKILL_EASY => Skill::Easy,
26 SKILL_MEDIUM => Skill::Medium,
27 SKILL_HARD => Skill::Hard,
28 SKILL_EXPERT => Skill::Expert,
29 &_ => Skill::default(),
30 }
31 }
32
33 pub fn as_str(&self) -> &'static str {
34 match self {
35 Skill::Noob => SKILL_NOOB,
36 Skill::Easy => SKILL_EASY,
37 Skill::Medium => SKILL_MEDIUM,
38 Skill::Hard => SKILL_HARD,
39 Skill::Expert => SKILL_EXPERT,
40 }
41 }
42
43 pub fn width(&self) -> usize {
44 match self {
45 Skill::Noob => 8,
46 Skill::Easy => 9,
47 Skill::Medium => 10,
48 Skill::Hard => 11,
49 Skill::Expert => 12,
50 }
51 }
52
53 pub fn def_density(self) -> HashMap<SlabDef, f64> {
54 let mut ret = HashMap::new();
55 match self {
56 Skill::Noob => {
57 ret.insert(SlabDef::Floor, 0.93);
58 ret.insert(SlabDef::Boost, 0.02);
59 }
60 Skill::Easy => {
61 ret.insert(SlabDef::Floor, 0.83);
62 ret.insert(SlabDef::Boost, 0.02);
63 }
64 Skill::Medium => {
65 ret.insert(SlabDef::Floor, 0.7);
66 ret.insert(SlabDef::Boost, 0.05);
67 }
68 Skill::Hard => {
69 ret.insert(SlabDef::Floor, 0.6);
70 ret.insert(SlabDef::Boost, 0.1);
71 }
72 Skill::Expert => {
73 ret.insert(SlabDef::Floor, 0.5);
74 ret.insert(SlabDef::Boost, 0.1);
75 }
76 }
77 ret
78 }
79
80 pub fn def_density0(self) -> HashMap<SlabDef, f64> {
81 let density = self.def_density();
82 let mut total: f64 = 0.0;
83 for (_, v) in density {
84 total += v;
85 }
86 let mut ret = HashMap::new();
87 ret.insert(SlabDef::Floor, total);
88 ret
89 }
90
91 pub fn mutability(&self) -> f64 {
92 match self {
93 Skill::Noob => 0.05,
94 Skill::Easy => 0.1,
95 Skill::Medium => 0.2,
96 Skill::Hard => 0.3,
97 Skill::Expert => 0.5,
98 }
99 }
100
101 pub fn time_to_complete(self) -> f64 {
102 match self {
103 Skill::Noob => 30.0,
104 Skill::Easy => 90.0,
105 Skill::Medium => 120.0,
106 Skill::Hard => 180.0,
107 Skill::Expert => 300.0,
108 }
109 }
110
111 pub fn begin_speed_factor(self) -> f64 {
112 match self {
113 Skill::Noob => 0.7,
114 Skill::Easy => 0.9,
115 Skill::Medium => 1.0,
116 Skill::Hard => 1.2,
117 Skill::Expert => 1.3,
118 }
119 }
120
121 pub fn end_speed_factor(self) -> f64 {
122 match self {
123 Skill::Noob => 0.7,
124 Skill::Easy => 1.0,
125 Skill::Medium => 1.2,
126 Skill::Hard => 1.4,
127 Skill::Expert => 1.7,
128 }
129 }
130}
131
132impl std::default::Default for Skill {
133 fn default() -> Self {
134 Skill::Medium
135 }
136}