-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
95 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,31 @@ | ||
# rustymind | ||
|
||
![CI](https://github.com/ondras/rustymind/workflows/CI/badge.svg) | ||
|
||
This is a hobby project to learn Rust. It is an implementation of the *Mastermind* game, including a game-solving AI. | ||
|
||
![screenshot](https://i.imgur.com/SXachN1.png) | ||
|
||
## Running | ||
|
||
```sh | ||
$ git clone https://github.com/ondras/rustymind.git && cd rustymind | ||
$ cargo run | ||
``` | ||
|
||
With an explicit code length: | ||
|
||
```sh | ||
$ cargo run -- 5 | ||
``` | ||
|
||
Tests: | ||
|
||
```sh | ||
$ cargo test | ||
``` | ||
|
||
## TODO | ||
|
||
- [X] GH Actions to lint, test, and release | ||
- [ ] the `--i-guess` option |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use std::env; | ||
|
||
pub struct Config { | ||
pub code_length: u8, | ||
pub ai: bool, | ||
} | ||
|
||
impl Config { | ||
pub fn parse() -> Result<Self, String> { | ||
let mut code_length = 4; | ||
let mut ai = true; | ||
let mut args: Vec<String> = env::args().skip(1).collect(); | ||
|
||
let iguess_idx = args.iter().position(|x| x == "--i-guess"); | ||
if let Some(idx) = iguess_idx { | ||
args.remove(idx); | ||
ai = false; | ||
} | ||
|
||
if let Some(last) = args.pop() { | ||
if let Ok(parsed) = last.parse::<u8>() { | ||
let range = 2..6 + 1; | ||
if range.contains(&parsed) { | ||
code_length = parsed; | ||
} else { | ||
return Err(format!( | ||
"Pick a value from {} to {} for code length", | ||
range.start, | ||
range.end - 1 | ||
)); | ||
} | ||
} else { | ||
return Err(format!("Cannot parse '{}' as a code length", last)); | ||
} | ||
} | ||
|
||
Ok(Self { code_length, ai }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters