Example #1
0
func (board *Board) SelectWordPosition(orientation Orientation, wordLength int) (int, int) {
	x := helpers.Random(0, board.size)
	y := helpers.Random(0, board.size)
	if orientation == S || orientation == N || orientation == SE || orientation == NW {
		totalLength := y + wordLength
		for totalLength > board.size {
			y--
			totalLength = y + wordLength
		}
	}

	if orientation == E || orientation == W || orientation == SE || orientation == NW {
		totalLength := x + wordLength
		for totalLength > board.size {
			x--
			totalLength = x + wordLength
		}
	}

	return x, y
}
Example #2
0
func (orm *ORM) FindWord(query string) (string, error) {
	rows, err := orm.db.Query("select value from words where value like ?", query)
	if err != nil {
		log.Fatal(err)
	}
	var words []string
	var value string
	for rows.Next() {
		rows.Scan(&value)
		words = append(words, value)
	}
	if len(words) > 0 {
		return words[helpers.Random(0, len(words))], nil
	} else {
		return "", fmt.Errorf("Unable to find a word corresponding to the query: %v", query)
	}
}
Example #3
0
func (board *Board) SelectWordLength() int {
	length := helpers.Random(3, board.size)
	return length
}
Example #4
0
func (board *Board) SelectOrientation() Orientation {
	nbOrientations := len(orientations)
	return Orientation(helpers.Random(1, nbOrientations+1))
}