[][src]Struct wordfeud_solver::Board

pub struct Board<'a> { /* fields omitted */ }

Represents the state of a wordfeud board.

  • A grid of 15x15 squares with possible letter/word bonus,
  • The tile distribution for language used (number of letters, and value of each letter),
  • The wordlist used for the game.

Implementations

impl<'a> Board<'a>[src]

#[must_use]pub fn new(language: Language) -> Board<'a>[src]

Create a new empty wordfeud board, with 15x15 squares. The language is used to specify the tile distribution used in the game. See Wordfeud Help: Tile Distribution. Currently supported:

  • EN (english),
  • NL (dutch),
  • SE (swedish)

Examples

Basic usage:

 use wordfeud_solver::{Board, Language};

 let board = Board::new(Language::NL);

Additional builder functions can be used to set the wordlist, grid and state of the board. See also:

pub fn set_wordlist(&mut self, wordlist: Wordlist)[src]

Set the wordlist for the board.

pub fn with_wordlist_from_file(self, wordfile: &str) -> Result<Board<'a>, Error>[src]

Specify the wordlist by reading it from wordfile, and returns the modified board.

The wordfile must contain one word per line, and the words should be from language specified in the board.

Errors

This function will give an error if the wordfile does not exist, or cannot be encoded.

Examples

let board = Board::default().with_wordlist_from_file("../wordlists/words.txt")?;

pub fn with_wordlist_from_words(
    self,
    words: &[&str]
) -> Result<Board<'a>, Error>
[src]

Specify the wordlist by a list of words, and returns the modified board.

Errors

If the words can not be encoded.

Example

use wordfeud_solver::Board;
let board = Board::default().with_wordlist_from_words(&["aardvark", "zebra"]);

pub fn state_from_strings<S: AsRef<str>>(
    &mut self,
    rows: &[S]
) -> Result<[Row; 15], Error>
[src]

Parse board state from list of string-like.

See also:

pub fn set_state_from_strings<S: AsRef<str>>(
    &mut self,
    rows: &[S]
) -> Result<(), Error>
[src]

Set board state from list of string-like. Mutates board.

pub fn with_state_from_strings<S: AsRef<str>>(
    self,
    rows: &[S]
) -> Result<Board<'a>, Error>
[src]

Parse board state from a list of string-like. The list must contain 15 rows of 15 characters.

Errors

If the list of strings has wrong dimensions or cannot be parsed as rows.

Examples

use wordfeud_solver::Board;
let state = &[
"    t     c   f",
"    e    he   o",
"    r   bis g k",
"    u  bol te v",
"    gepof dimme",
"      la vree e",
"    qua   ene  ",
"      Spoelen  ",
"     s a   n   ",
"     c d we    ",
"     hadden    ",
"    nu o   y   ",
"  wrat siJzen  ",
"    k     os   ",
"   zerk   g    ",
];
let board = Board::default().with_state_from_strings(state);

pub fn set_state(&mut self, rows: &[Row; 15])[src]

Set board state from a list of rows.

pub fn set_grid_from_strings<S: AsRef<str>>(
    &mut self,
    grid: &[S]
) -> Result<(), Error>
[src]

Set board cells from string representation

Errors

If the grid has wrong dimensions or cannot be parsed as valid board cells.

pub fn with_grid_from_strings<S: AsRef<str>>(
    self,
    grid: &[S]
) -> Result<Board<'a>, Error>
[src]

Set board cells from string representation

Errors

If the grid has wrong dimensions or cannot be parsed as valid board cells.

pub fn wordlist(&self) -> &Wordlist[src]

Return reference to our wordlist

pub fn horizontal(&self) -> [Row; 15][src]

Return the board horizontal state

pub fn vertical(&self) -> [Row; 15][src]

Return the board vertical state

pub fn grid(&self) -> Grid[src]

Return the grid

pub fn tileset(&self) -> &'a TileSet<'_>[src]

Return tileset

pub fn is_occupied(&self, x: usize, y: usize) -> bool[src]

Check if cell at x, y is occupied.

Examples

let mut board = Board::default();
board.play_word("aardvark", 7, 7, true, true)?;
assert!(board.is_occupied(7,7));

pub fn play_word(
    &mut self,
    word: &str,
    x: usize,
    y: usize,
    horizontal: bool,
    modify: bool
) -> Result<String, Error>
[src]

Play word at x, y on the board in given direction. Modifies the board state if modify is true. Returns the used letters, in the order of use. Letters in word that are already on the board are not included.
NOTE: if a letter in word is placed on the board in a position where a different letter is already used, the letter on the board is silently overwritten.

Errors

  • If word cannot be encoded to valid Word.
  • If the placed word does not on the board.

Examples

let mut board = Board::default();
let word = "aardvark";
let used = board.play_word(word, 7,7,true, true)?;
assert_eq!(used, word);

pub fn calc_word_points(
    &self,
    word: &Word,
    x: usize,
    y: usize,
    horizontal: bool,
    include_crossing_words: bool
) -> Result<u32, Error>
[src]

Calculates the score of word placed at x0, y0, horizontal that has not yet been played on the board. If include_crossing_words is true the points for words that are created or extended in the crossing direction are included in the points. include_crossing_words should be set to true for normal use. It is set to false when calc_word_points calls itself recursively.

Errors

  • If the placed word would cross the right or bottom boarder.

Examples

let board = Board::default();
let word = board.encode("wordfeud")?;
let points = board.calc_word_points(&word, 7, 7, true, true)?;
assert_eq!(points, 78);

In this example, the values of the letters are: w:4 o:1, r:1, d:2, f:4, u:2. The f is on 2x word bonus, and the last d is on 2x letter bonus. The total value of the word is 2 x (4 + 1 + 1 + 2 + 4 + 1 +2 + (2 x 2)) = 2 x 19 = 38. Because all 7 letters are played we get an extra "bingo" bonus of 40 points.

pub fn words(
    &self,
    row: &Row,
    horizontal: bool,
    i: usize,
    letters: Letters
) -> Vec<(usize, Word)>
[src]

Returns a list with (pos, word) tuples for all words that can be played on row with index i, in direction horizontal, given letters. In the returned tuples, pos is the start index of the word in row.

Examples

use wordfeud_solver::{Board, Letters, Row};
let board = Board::default().with_wordlist_from_words(&["the", "quick", "brown", "fox"]).unwrap();
let row = board.encode("               ").unwrap();
let letters = board.encode("befnrowx").unwrap();
let res = board.words(&row, true, 7, letters);
assert_eq!(res.len(),8);

In this example, we start with an empty board. The first word must have one of its letters on the centre square (7,7). The word "brown" can be placed at 3,4,5,6,7, and the word "fox" can be played at 5,6,7.

pub fn calc_all_word_scores<T: TryIntoLetters>(
    &self,
    letters: T
) -> Result<Vec<Score>, Error>
[src]

Calculate the score for each word that can be played on the board with letters. Return a list of (x, y, horizontal, word, score) tuples.

Examples

let board = Board::default().with_wordlist_from_words(&["the", "quick", "brown", "fox"])?;
let res = board.calc_all_word_scores("befnrowx")?;
assert_eq!(res.len(),16);

In this example 16 results are returned: 8 in horizontal and 8 in vertical direction. See also Board::words.

pub fn tile_at(&self, y: usize, x: usize) -> Option<Tile>[src]

Return tile at x,y or None if empty cell or outside grid.

pub fn encode<T: Item>(&self, word: &str) -> Result<ItemList<T>, Error>[src]

Encode string to Word with our codec

Errors

If word can not be encoded

pub fn decode<T: Item>(&self, word: ItemList<T>) -> String[src]

Decode word to string with our codec

pub fn sample_scores<T: TryIntoLetters + Copy>(
    &self,
    racks: &[T],
    our_tile_score: u32,
    in_endgame: bool
) -> Result<Vec<(u32, bool)>, Error>
[src]

Trait Implementations

impl<'a> Clone for Board<'a>[src]

impl<'a> Debug for Board<'a>[src]

impl<'a> Default for Board<'a>[src]

impl<'a> Display for Board<'a>[src]

Display the board state as 15 lines of 15 squares. Empty squares show as ".".

Auto Trait Implementations

impl<'a> RefUnwindSafe for Board<'a>[src]

impl<'a> Send for Board<'a>[src]

impl<'a> Sync for Board<'a>[src]

impl<'a> Unpin for Board<'a>[src]

impl<'a> UnwindSafe for Board<'a>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,