Skip to content

Commit

Permalink
style: Updated imports
Browse files Browse the repository at this point in the history
  • Loading branch information
cheatsnake committed Sep 22, 2022
1 parent a5a452e commit 9b7a861
Show file tree
Hide file tree
Showing 20 changed files with 79 additions and 79 deletions.
4 changes: 2 additions & 2 deletions pkg/anagram/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package anagram
import (
"path/filepath"

"github.com/cheatsnake/shadify/pkg/assists"
"github.com/cheatsnake/shadify/internal/helpers"
)

var wordsDB []string
var wordsDBSize int

func init() {
nouns, _ := assists.ReadFileLineByLine(filepath.Join("data", "nouns.txt"))
nouns, _ := helpers.ReadFileLineByLine(filepath.Join("data", "nouns.txt"))
wordsDB = nouns
wordsDBSize = len(nouns)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/anagram/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"path/filepath"
"testing"

"github.com/cheatsnake/shadify/pkg/assists"
"github.com/cheatsnake/shadify/internal/helpers"
)

func TestGenerate(t *testing.T) {
wordsDB, _ = assists.ReadFileLineByLine(filepath.Join("..", "..", "data", "nouns.txt"))
wordsDB, _ = helpers.ReadFileLineByLine(filepath.Join("..", "..", "data", "nouns.txt"))
wordsDBSize = len(wordsDB)
result := Generate()

Expand Down
4 changes: 2 additions & 2 deletions pkg/anagram/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"math/rand"
"strings"

"github.com/cheatsnake/shadify/pkg/assists"
"github.com/cheatsnake/shadify/internal/helpers"
)

func composingWords(word string) []string {
Expand All @@ -23,7 +23,7 @@ func composingWords(word string) []string {
}
}

result = assists.RemoveElement(result, assists.IndexOf(word, result))
result = helpers.RemoveElement(result, helpers.IndexOf(word, result))

return result
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/anagram/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package anagram

// Core struct of anagram module
type Core struct {
Task string `json:"task"`// Task is random word from which you need to make other words
Words []string `json:"words"`// Array of all possible words that can be made up from the Task
Task string `json:"task"` // Task is random word from which you need to make other words
Words []string `json:"words"` // Array of all possible words that can be made up from the Task
}
6 changes: 3 additions & 3 deletions pkg/countries/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"math/rand"
"strings"

"github.com/cheatsnake/shadify/pkg/assists"
"github.com/cheatsnake/shadify/internal/helpers"
)

func generateCapitalQuiz(variantsCount int) CapitalQuiz {
Expand All @@ -18,7 +18,7 @@ func generateCapitalQuiz(variantsCount int) CapitalQuiz {
randomIdx := rand.Intn(len(countriesDB))
capital := countriesDB[randomIdx].Capital

if assists.IndexOf(capital, variants) == -1 {
if helpers.IndexOf(capital, variants) == -1 {
variants[i] = countriesDB[randomIdx].Capital
i++
}
Expand Down Expand Up @@ -46,7 +46,7 @@ func generateCountryQuiz(variantsCount int) CountryQuiz {
randomIdx := rand.Intn(len(countriesDB))
country := countriesDB[randomIdx].Country

if assists.IndexOf(country, variants) == -1 {
if helpers.IndexOf(country, variants) == -1 {
variants[i] = countriesDB[randomIdx].Country
i++
}
Expand Down
24 changes: 12 additions & 12 deletions pkg/math/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"math"
"strconv"

"github.com/cheatsnake/shadify/pkg/assists"
"github.com/cheatsnake/shadify/internal/helpers"
)

// Get a random addition expression with a given range of numbers
func GetAddition(minFirst, maxFirst, minSecond, maxSecond int) BasicExpression {
operation := "+"
first := assists.GetRandomInteger(minFirst, maxFirst)
second := assists.GetRandomInteger(minSecond, maxSecond)
first := helpers.GetRandomInteger(minFirst, maxFirst)
second := helpers.GetRandomInteger(minSecond, maxSecond)
expression := strconv.Itoa(first) + " " + operation + " " + strconv.Itoa(second)
answer := first + second

Expand All @@ -23,8 +23,8 @@ func GetAddition(minFirst, maxFirst, minSecond, maxSecond int) BasicExpression {
// Get a random subtraction expression with a given range of numbers
func GetSubtraction(minFirst, maxFirst, minSecond, maxSecond int, allowNegative bool) BasicExpression {
operation := "-"
first := assists.GetRandomInteger(minFirst, maxFirst)
second := assists.GetRandomInteger(minSecond, maxSecond)
first := helpers.GetRandomInteger(minFirst, maxFirst)
second := helpers.GetRandomInteger(minSecond, maxSecond)

if second > first && !allowNegative {
second, first = first, second
Expand All @@ -41,8 +41,8 @@ func GetSubtraction(minFirst, maxFirst, minSecond, maxSecond int, allowNegative
// Get a random multiplication expression with a given range of numbers
func GetMultiplication(minFirst, maxFirst, minSecond, maxSecond int) BasicExpression {
operation := "*"
first := assists.GetRandomInteger(minFirst, maxFirst)
second := assists.GetRandomInteger(minSecond, maxSecond)
first := helpers.GetRandomInteger(minFirst, maxFirst)
second := helpers.GetRandomInteger(minSecond, maxSecond)
expression := strconv.Itoa(first) + " " + operation + " " + strconv.Itoa(second)
answer := first * second

Expand All @@ -54,7 +54,7 @@ func GetMultiplication(minFirst, maxFirst, minSecond, maxSecond int) BasicExpres
// Get a random division expression with a given range of numbers
func GetDivision(minFirst, maxFirst int) BasicExpression {
operation := "/"
first := assists.GetRandomInteger(minFirst, maxFirst)
first := helpers.GetRandomInteger(minFirst, maxFirst)

if first == 0 {
first = 1
Expand All @@ -66,7 +66,7 @@ func GetDivision(minFirst, maxFirst int) BasicExpression {
divisors = divisors[1 : len(divisors)-1]
}

index := assists.GetRandomInteger(0, len(divisors)-1)
index := helpers.GetRandomInteger(0, len(divisors)-1)
second := divisors[index]
expression := strconv.Itoa(first) + " " + operation + " " + strconv.Itoa(second)
answer := first / second
Expand All @@ -78,9 +78,9 @@ func GetDivision(minFirst, maxFirst int) BasicExpression {

// Get a random quadratic expression with a given range of coefficients
func GetQuadratic(minA, maxA, minB, maxB, minC, maxC int) QuadraticEquation {
a := assists.GetRandomInteger(minA, maxA)
b := assists.GetRandomInteger(minB, maxB)
c := assists.GetRandomInteger(minC, maxC)
a := helpers.GetRandomInteger(minA, maxA)
b := helpers.GetRandomInteger(minB, maxB)
c := helpers.GetRandomInteger(minC, maxC)

equation := strconv.Itoa(a) + "x^2 + " + strconv.Itoa(b) + "x + " + strconv.Itoa(c) + " = 0"

Expand Down
6 changes: 3 additions & 3 deletions pkg/minesweeper/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strconv"
"strings"

"github.com/cheatsnake/shadify/pkg/assists"
"github.com/cheatsnake/shadify/internal/helpers"
)

func generator(startX, startY, w, h, mines int) [][]string {
Expand All @@ -16,8 +16,8 @@ func generator(startX, startY, w, h, mines int) [][]string {
}

for i := 0; i < mines; i++ {
x := assists.GetRandomInteger(0, w-1)
y := assists.GetRandomInteger(0, h-1)
x := helpers.GetRandomInteger(0, w-1)
y := helpers.GetRandomInteger(0, h-1)
if board[y][x] == "x" || isProtectedPosition(x, y, startX, startY) {
i--
} else {
Expand Down
6 changes: 4 additions & 2 deletions pkg/schulte/core.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package schulte

import "github.com/cheatsnake/shadify/pkg/assists"
import (
"github.com/cheatsnake/shadify/internal/helpers"
)

// Generate a Schulte numerical grid with a given size
func GenerateNumeric(size int) Core[int] {
if size > 100 || size < -100 {
size = 100
}
values := assists.GetNumbers(size*size, 1)
values := helpers.GetNumbers(size*size, 1)
grid := generateGrid(values)

return Core[int]{Grid: grid}
Expand Down
6 changes: 3 additions & 3 deletions pkg/schulte/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package schulte
import (
"math"

"github.com/cheatsnake/shadify/pkg/assists"
"github.com/cheatsnake/shadify/internal/helpers"
)

func generateGrid[T int | string](values []T) [][]T {
Expand All @@ -18,9 +18,9 @@ func generateGrid[T int | string](values []T) [][]T {

for i := 0; i < size; i++ {
for j := 0; j < size; j++ {
index := assists.GetRandomInteger(0, available)
index := helpers.GetRandomInteger(0, available)
grid[i][j] = values[index]
values = assists.RemoveElement(values, index)
values = helpers.RemoveElement(values, index)
available -= 1
}
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/set/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"strconv"

"github.com/cheatsnake/shadify/pkg/assists"
"github.com/cheatsnake/shadify/internal/helpers"
)

// Create a new instance of Set Core
Expand All @@ -29,7 +29,7 @@ func (sc *Core) RemoveSet(set []int) error {
}

for _, id := range set {
if !assists.SliceContains(layoutId, id) {
if !helpers.SliceContains(layoutId, id) {
return errors.New("the card with id:" + strconv.Itoa(id) + " was not found in the current layout")
}
}
Expand All @@ -40,9 +40,9 @@ func (sc *Core) RemoveSet(set []int) error {

for _, id := range set {
sc.WonCards = append(sc.WonCards, Deck[id])
index := assists.IndexOf(id, layoutId)
sc.Layout = assists.RemoveElement(sc.Layout, index)
layoutId = assists.RemoveElement(layoutId, index)
index := helpers.IndexOf(id, layoutId)
sc.Layout = helpers.RemoveElement(sc.Layout, index)
layoutId = helpers.RemoveElement(layoutId, index)
}

if len(sc.Layout) < StartLayoutSize && len(sc.FreeCards) >= SetSize {
Expand All @@ -66,9 +66,9 @@ func (sc *Core) AddCards() error {
}

for i := 0; i < SetSize; i++ {
index := assists.GetRandomInteger(0, len(sc.FreeCards)-1)
index := helpers.GetRandomInteger(0, len(sc.FreeCards)-1)
sc.Layout = append(sc.Layout, sc.FreeCards[index])
sc.FreeCards = assists.RemoveElement(sc.FreeCards, index)
sc.FreeCards = helpers.RemoveElement(sc.FreeCards, index)
}

sc.PossibleSets = [][]Card{}
Expand Down
8 changes: 4 additions & 4 deletions pkg/set/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package set
import (
"sort"

"github.com/cheatsnake/shadify/pkg/assists"
"github.com/cheatsnake/shadify/internal/helpers"
)

func startGame() ([]Card, []Card) {
cardIndexes := assists.GetNumbers(DeckSize, 0)
cardIndexes := helpers.GetNumbers(DeckSize, 0)
layout := make([]Card, StartLayoutSize)
freeCards := make([]Card, 0, DeckSize-StartLayoutSize)

for j := range layout {
cardIndex := assists.GetRandomInteger(0, len(cardIndexes)-1)
cardIndex := helpers.GetRandomInteger(0, len(cardIndexes)-1)
layout[j] = Deck[cardIndexes[cardIndex]]
cardIndexes = assists.RemoveElement(cardIndexes, cardIndex)
cardIndexes = helpers.RemoveElement(cardIndexes, cardIndex)
}

sort.Slice(cardIndexes, func(i, j int) bool {
Expand Down
14 changes: 7 additions & 7 deletions pkg/set/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strconv"
"strings"

"github.com/cheatsnake/shadify/pkg/assists"
"github.com/cheatsnake/shadify/internal/helpers"
)

func updateState(layout []Card, wonCards []Card) string {
Expand Down Expand Up @@ -64,7 +64,7 @@ func loadState(state string) ([]Card, []Card, []Card, error) {
usedCardsId := append(layoutId, wonCardsId...)

for i := range Deck {
if !assists.SliceContains(usedCardsId, i) {
if !helpers.SliceContains(usedCardsId, i) {
freeCards = append(freeCards, Deck[i])
}
}
Expand All @@ -74,8 +74,8 @@ func loadState(state string) ([]Card, []Card, []Card, error) {

func parseStateString(state string) ([]int, []int, error) {
splitedState := strings.Split(state, stateSeparator)
layoutIdStr := assists.RemoveDuplicateStrings(strings.Split(splitedState[0], "-"))
layoutId, err := assists.SliceStringToInt(layoutIdStr)
layoutIdStr := helpers.RemoveDuplicateStrings(strings.Split(splitedState[0], "-"))
layoutId, err := helpers.SliceStringToInt(layoutIdStr)
if err != nil {
return nil, nil, err
}
Expand All @@ -90,8 +90,8 @@ func parseStateString(state string) ([]int, []int, error) {
return layoutId, nil, nil
}

wonCardsIdStr := assists.RemoveDuplicateStrings(strings.Split(splitedState[1], "-"))
wonCardsId, err := assists.SliceStringToInt(wonCardsIdStr)
wonCardsIdStr := helpers.RemoveDuplicateStrings(strings.Split(splitedState[1], "-"))
wonCardsId, err := helpers.SliceStringToInt(wonCardsIdStr)
if err != nil {
return nil, nil, err
}
Expand All @@ -100,7 +100,7 @@ func parseStateString(state string) ([]int, []int, error) {
if id >= DeckSize {
return nil, nil, errors.New("entered not exist id: " + strconv.Itoa(id))
}
if assists.SliceContains(layoutId, id) {
if helpers.SliceContains(layoutId, id) {
return nil, nil, errors.New("layout must not contain won card id: " + strconv.Itoa(id))
}
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/sudoku/core.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package sudoku

import (
"github.com/cheatsnake/shadify/pkg/assists"
)
import "github.com/cheatsnake/shadify/internal/helpers"

// Create a new instance of Sudoku Core
func NewCore() *Core {
Expand All @@ -12,7 +10,7 @@ func NewCore() *Core {
// Generate a new Sudoku 9x9 grid
func (sc *Core) Generate() {
sc.Grid = basicGrid
numberOfSwaps := assists.GetRandomInteger(10, 50)
numberOfSwaps := helpers.GetRandomInteger(10, 50)

for i := 0; i < numberOfSwaps; i++ {
sc.Grid = swapRows(sc.Grid)
Expand Down
6 changes: 3 additions & 3 deletions pkg/sudoku/preparation.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sudoku

import "github.com/cheatsnake/shadify/pkg/assists"
import "github.com/cheatsnake/shadify/internal/helpers"

func prepare(grid [9][9]int, fillFactor int) [9][9]int {
if fillFactor > 99 {
Expand All @@ -14,8 +14,8 @@ func prepare(grid [9][9]int, fillFactor int) [9][9]int {
task := getEmptyGrid()

for filled < fillFactor {
randRow := assists.GetRandomInteger(0, 8)
randCol := assists.GetRandomInteger(0, 8)
randRow := helpers.GetRandomInteger(0, 8)
randCol := helpers.GetRandomInteger(0, 8)

if task[randRow][randCol] == 0 {
task[randRow][randCol] = grid[randRow][randCol]
Expand Down
Loading

0 comments on commit 9b7a861

Please sign in to comment.