Skip to content

Commit

Permalink
Upgrade termion and replace rand with fastrand
Browse files Browse the repository at this point in the history
  • Loading branch information
crazymerlyn committed Apr 14, 2024
1 parent 6f2e2dd commit 78f183c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 29 deletions.
48 changes: 31 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["CrazyMerlyn <crazy.d.merlyn@gmail.com>"]
name = "sudoku-tty"
version = "0.1.3"
version = "0.1.4"
description = "Play sudoku in terminal"
repository = "https://github.com/crazymerlyn/sudoku"

Expand All @@ -11,8 +11,8 @@ categories = ["games", "command-line-utilities"]
keywords = ["sudoku", "puzzle", "tty", "tui"]

[dependencies]
rand = "0.3.15"
termion = "1.3.0"
fastrand = "2.0.2"
termion = "3.0.0"

[[bin]]
name = "sudoku"
Expand Down
10 changes: 4 additions & 6 deletions src/grid/generator.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::convert::Into;
use std::fmt;

use rand::{random, thread_rng, Rng};

use super::Grid;

const VERY_EASY: &str = include_str!("./seeds/veasy.csv");
Expand All @@ -18,17 +16,17 @@ impl Generator {
let puzzles_str = diff.into().puzzles();
let puzzles = read_puzzles(puzzles_str);

let mut puzzle = puzzles[random::<usize>() % puzzles.len()].clone();
let mut puzzle = puzzles[fastrand::usize(..puzzles.len())].clone();

let mut permutation: Vec<_> = (1..10).collect();
thread_rng().shuffle(&mut permutation);
fastrand::shuffle(&mut permutation);
puzzle.permute(&permutation);

if random() {
if fastrand::bool() {
puzzle.flip_horizontally();
}

if random() {
if fastrand::bool() {
puzzle.flip_vertically();
}

Expand Down
10 changes: 7 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#![allow(dead_code)]

extern crate rand;
extern crate fastrand;
extern crate termion;

use std::io;
use termion::input::MouseTerminal;
use termion::raw::IntoRawMode;
use termion::screen::AlternateScreen;
use termion::screen::IntoAlternateScreen;

mod grid;

Expand All @@ -15,7 +15,11 @@ use game::Game;

fn main() {
let stdin = io::stdin();
let screen = AlternateScreen::from(io::stdout().into_raw_mode().unwrap());
let screen = io::stdout()
.into_raw_mode()
.unwrap()
.into_alternate_screen()
.unwrap();
let stdout = MouseTerminal::from(screen);

let mut game = Game::new(stdin, stdout);
Expand Down

0 comments on commit 78f183c

Please # to comment.