36 lines
1.1 KiB
Go
36 lines
1.1 KiB
Go
package formation
|
|
|
|
// Cell returns one cell by row col index
|
|
// row is from 1, col is from 1
|
|
// If idx is over range, auto fix with symbols of 0
|
|
// compatible with reel's range is not equals to matrix's form
|
|
func Cell(row, col int64, symbols []int64, form []int64) int64 {
|
|
pos := Coords{row - 1, col - 1}.ToPos(form)
|
|
if pos >= int64(len(symbols)) {
|
|
return 0
|
|
}
|
|
return symbols[pos]
|
|
}
|
|
|
|
// FormatSymbols distribute symbols into form
|
|
func FormatSymbols(symbols []int64, form []int64) [][]int64 {
|
|
formattedSymbols := make([][]int64, 0)
|
|
for col, sz := range form {
|
|
colSymbols := make([]int64, 0)
|
|
for row := 0; row < int(sz); row++ {
|
|
colSymbols = append(colSymbols, Cell(int64(row)+1, int64(col)+1, symbols, form))
|
|
}
|
|
formattedSymbols = append(formattedSymbols, colSymbols)
|
|
}
|
|
return formattedSymbols
|
|
}
|
|
|
|
// DeformatSymbols puts symbols together
|
|
func DeformatSymbols(symbols [][]int64) []int64 {
|
|
deformattedSymbols := make([]int64, 0)
|
|
for _, colSymbols := range symbols {
|
|
deformattedSymbols = append(deformattedSymbols, colSymbols...)
|
|
}
|
|
return deformattedSymbols
|
|
}
|