i'm taking a break

This commit is contained in:
2022-12-03 01:32:10 +01:00
parent 3cdb4b991d
commit 8186283cf6
3 changed files with 53 additions and 30 deletions

View File

@@ -7,5 +7,3 @@ edition = "2021"
[dependencies]
rfd = "0.10.0"
phf = { version = "0.11", default-features = false }

View File

@@ -56,3 +56,28 @@ static COUNTRIES: phf::Map<&'static str, &'static str> = phf_map! {
"UK" => "United Kingdom",
};
```
this gave some issues when trying to import the crate (something with the macro's).
I couldn't find the fix for this in the documentation so i decided in the end to go back to the ugly but native solution
example of the errors:
```
error[E0432]: unresolved import `phf::phf_map`
--> src\main.rs:5:5
|
5 | use phf::phf_map;
| ^^^^^^^^^^^^ no `phf_map` in the root
```
```
error: cannot determine resolution for the macro `phf_map`
--> src\main.rs:7:49
|
7 | pub static scores: phf::Map<&'static str, u8> = phf_map! (
| ^^^^^^^
|
= note: import resolution is stuck, try simplifying macro imports
```

View File

@@ -1,14 +1,14 @@
use std::collections::HashMap;
use std::fs::File;
use std::io::{BufRead, BufReader};
use phf::phf_map;
use std::iter::Iterator;
static scores: phf::Map<&'static str, u8> = phf_map! (
"A" => 1, //rock
"B" => 2, //paper
"C" => 3, //scizzors
);
pub const scores:HashMap<&str, u32> = HashMap::from([
("A",1), //rock
("B",2), //paper
("C",3) //scizzors
]);
// figuring out a way to do this :/
// 1 2 = lose
@@ -18,27 +18,27 @@ static scores: phf::Map<&'static str, u8> = phf_map! (
// 3 1 = lose
// 3 2 = win
static possibilities: phf::Map<&'static u8, &'static u8> = phf_map! {
12 => 0,
13 => 6,
21 => 6,
23 => 0,
31 => 0,
32 => 6,
11 => 3,
22 => 3,
33 => 3,
};
static possibilities: HashMap<u32,u32> = HashMap::from([
(12,0),
(13,6),
(21,6),
(23,0),
(31,0),
(32,6),
(11,3),
(22,3),
(33,3)
]);
static shape_map: phf::Map<&'static String, &'static String> = phf_map! {
"X" => "A",
"Y" => "B",
"Z" => "C",
};
static shape_map: HashMap<&str, &str> = [
("X","A"),
("Y","B"),
("Z","C")
].iter().cloned().collect();
struct Play {
them: u8,
you: u8
them: u32,
you: u32
}
@@ -63,9 +63,9 @@ fn main() {
fn parse_line(line: String) -> Play {
let mut temp = line.split(' ').collect::<Vec<&str>>();
return Play {them: scores[temp[0].parse().unwrap()], you: scores[temp[1].parse().unwrap()] }
return Play {them: scores[temp[0]].clone(), you: scores[temp[1]].clone() }
}
fn get_score(p: Play) -> u8 {
return possibilities[p.you*10+p.them]+scores[p.you];
fn get_score(p: Play) -> u32 {
return possibilities[&(p.you*10+p.them)]+&p.you;
}