[−][src]Struct wordfeud_solver::Board
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 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]
self,
words: &[&str]
) -> Result<Board<'a>, Error>
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 with_state_from_strings(self, rows: &[&str]) -> Result<Board<'a>, Error>
[src]
Parse board state from a list of strings. 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 with_grid_from_strings(
self,
grid: Vec<Vec<String>>
) -> Result<Board<'a>, Error>
[src]
self,
grid: Vec<Vec<String>>
) -> Result<Board<'a>, Error>
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 state
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]
&mut self,
word: &str,
x: usize,
y: usize,
horizontal: bool,
modify: bool
) -> Result<String, Error>
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 validWord
. - 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]
&self,
word: &Word,
x: usize,
y: usize,
horizontal: bool,
include_crossing_words: bool
) -> Result<u32, Error>
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]
&self,
row: &Row,
horizontal: bool,
i: usize,
letters: Letters
) -> Vec<(usize, Word)>
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(
&self,
letters: &str
) -> Result<Vec<(usize, usize, bool, Word, u32)>, Error>
[src]
&self,
letters: &str
) -> Result<Vec<(usize, usize, bool, Word, u32)>, Error>
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]
pub fn decode<T: Item>(&self, word: ItemList<T>) -> String
[src]
Decode word to string with our codec
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>
impl<'a> Send for Board<'a>
impl<'a> Sync for Board<'a>
impl<'a> Unpin for Board<'a>
impl<'a> UnwindSafe for Board<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,