wemyss / rustikub

Rummikub solver written in Rust
MIT License
4 stars 0 forks source link

Parse more sophisticated tiles #3

Closed wemyss closed 7 years ago

wemyss commented 7 years ago

Currently can only parse single number/color tiles e.g. b11

It would be nice to parse tiles such as blry7 and y1-9 https://github.com/wemyss/rustikub/blob/c0b066a449fc28968dda62a9aaf401b3eb3846a3/src/game/mod.rs#L22

wemyss commented 7 years ago

Possible solutions:

  1. Create two vectors of colors and numbers and then using nested loops create each tile
  2. Similar but use an iterator for colors substring
  3. Use an iterator for both (generate number range for values)

Code solution for 3 (untested)

let tiles = tiles.split_whitespace()
    .map(|tile| tile.splitn(2, |c: char| c.is_digit(10)))
    .flat_map(|tile| {
        let colors = tile[0];
        let nums = parse_number_range(tile[1]);

        colors.chars().flat_map(|c| nums.map(|num| Tile::new(c, num)))
    })
wemyss commented 7 years ago

Added feature now in master. Derived from the solution above using a more imperative programming approach due to rust compilation issues