Skip to content

Commit

Permalink
gofmt all
Browse files Browse the repository at this point in the history
  • Loading branch information
semi committed Sep 4, 2021
1 parent 979bb39 commit 184179b
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 66 deletions.
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func ReadWeights() {
}

var dat map[string]interface{}

err = hjson.Unmarshal(b, &dat)
if err != nil {
panic(err)
Expand Down
6 changes: 3 additions & 3 deletions generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func Score(l Layout) float64 {
if s.IndexBalance != 0 {
left, right := IndexUsage(l)
score += s.IndexBalance * math.Abs(right-left)
}
}

Analyzed++

Expand Down Expand Up @@ -126,7 +126,7 @@ func Populate(n int) Layout {
}
analyzed := 0
for runtime.NumGoroutine() > 1 {
fmt.Printf("%d greedy improving at %d analyzed/s \r", runtime.NumGoroutine()-1, Analyzed - analyzed)
fmt.Printf("%d greedy improving at %d analyzed/s \r", runtime.NumGoroutine()-1, Analyzed-analyzed)
analyzed = Analyzed
time.Sleep(time.Second)
}
Expand All @@ -148,7 +148,7 @@ func Populate(n int) Layout {
go fullImprove(&layouts[i].l)
}
for runtime.NumGoroutine() > 1 {
fmt.Printf("%d fully improving at %d analyzed/s \r", runtime.NumGoroutine()-1, Analyzed - analyzed)
fmt.Printf("%d fully improving at %d analyzed/s \r", runtime.NumGoroutine()-1, Analyzed-analyzed)
analyzed = Analyzed
time.Sleep(time.Second)
}
Expand Down
33 changes: 17 additions & 16 deletions interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ func printtrigrams(l *Layout) {
} else if i == 1 {
c = *c.Color(162, 136, 227)
} else if i == 2 {
c = *c.Color(217, 90, 120)
c = *c.Color(217, 90, 120)
} else if i == 3 {
c = *c.Color(45, 167, 130)
}
for pc := math.Ceil(100*float64(v) / total);pc > 0;pc-=1 {

for pc := math.Ceil(100 * float64(v) / total); pc > 0; pc -= 1 {
//s := c.Sprint("█")
s := c.Sprint("=")
tm.Printf(s)
Expand All @@ -124,7 +124,7 @@ func printtrigrams(l *Layout) {
}
}
}

}
}

Expand Down Expand Up @@ -198,7 +198,7 @@ func worsen(l Layout, is33 bool) {
if x < 12 {
xrow = 0
xcol = x
} else if x < 12 + 11 {
} else if x < 12+11 {
xrow = 1
xcol = x - 12
} else {
Expand All @@ -208,7 +208,7 @@ func worsen(l Layout, is33 bool) {
if y < 12 {
yrow = 0
ycol = y
} else if y < 12 + 11 {
} else if y < 12+11 {
yrow = 1
ycol = y - 12
} else {
Expand All @@ -229,11 +229,11 @@ func worsen(l Layout, is33 bool) {
}
px := pins[xrow][xcol]
py := pins[yrow][ycol]
if (px == "#" || py == "#") {
if px == "#" || py == "#" {
continue
}
kx := l.Keys[xrow][xcol]
ky := l.Keys[yrow][ycol]
kx := l.Keys[xrow][xcol]
ky := l.Keys[yrow][ycol]
if px == kx || px == ky || py == kx || py == ky {
continue
}
Expand All @@ -245,6 +245,7 @@ func worsen(l Layout, is33 bool) {
}

var threshold float64

func SuggestSwaps(l Layout, depth int, maxdepth int, p *psbl, wg *sync.WaitGroup) psbl {
s1 := Score(l)

Expand Down Expand Up @@ -335,9 +336,9 @@ func Interactive(l Layout) {
}()

pins = [][]string{
{"@","#","#","#","@","@","#","#","#","@","#","#",},
{"#","#","#","#","@","@","#","#","#","#","#","@",},
{"@","@","@","@","@","@","@","@","@","@","@","@",},
{"@", "#", "#", "#", "@", "@", "#", "#", "#", "@", "#", "#"},
{"#", "#", "#", "#", "@", "@", "#", "#", "#", "#", "#", "@"},
{"@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@"},
}

start := time.Now()
Expand Down Expand Up @@ -366,9 +367,9 @@ func Interactive(l Layout) {
if key == keyboard.KeyEnter {
break
} else if key == keyboard.KeyBackspace || key == keyboard.KeyBackspace2 {
if len (runes) > 0 {
runes = runes[:len(runes)-1]
if len(runes) > 0 {
runes = runes[:len(runes)-1]

tm.MoveCursorBackward(1)
tm.Printf(" ")
}
Expand All @@ -386,7 +387,7 @@ func Interactive(l Layout) {
tm.Flush()
}
input := strings.TrimSpace(string(runes))

args := strings.Split(input, " ")

start = time.Now()
Expand Down
41 changes: 20 additions & 21 deletions layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func MinimizeLayout(init *Layout, pins [][]string, count int, top bool, is33 boo
bestScore := Score(*init)
bestLayout := CopyLayout(*init)
var tot int
var r1len int
var r1len int
var r2len int
if is33 {
tot = 33
Expand All @@ -58,12 +58,12 @@ func MinimizeLayout(init *Layout, pins [][]string, count int, top bool, is33 boo
}
var foundBetter bool
for {
foundBetter = false
foundBetter = false
bestSoFarScore := bestScore
bestSoFarLayout := bestLayout

for i := 0; i < tot-1; i++ {
for j := i+1; j < tot; j++ {
for j := i + 1; j < tot; j++ {
var irow int
var icol int
if i < r1len {
Expand Down Expand Up @@ -103,16 +103,16 @@ func MinimizeLayout(init *Layout, pins [][]string, count int, top bool, is33 boo
}
pi := pins[irow][icol]
pj := pins[jrow][jcol]
if (pi == "#" || pj == "#") {
if pi == "#" || pj == "#" {
continue
}
swapped := CopyLayout(bestLayout)
ki := swapped.Keys[irow][icol]
kj := swapped.Keys[jrow][jcol]
ki := swapped.Keys[irow][icol]
kj := swapped.Keys[jrow][jcol]
if pi == ki || pi == kj || pj == ki || pj == kj {
continue
}

// NewKeys := make([][]string, len(bestLayout.Keys))
// for k := range bestLayout.Keys {
// NewKeys[k] = make([]string, len(bestLayout.Keys[k]))
Expand All @@ -128,7 +128,7 @@ func MinimizeLayout(init *Layout, pins [][]string, count int, top bool, is33 boo
// swapped.Keys[jrow][jcol] = tmp
var swappedScore float64
if count != 0 {
MinimizeLayout(&swapped, pins, count - 1, false, is33, noCross)
MinimizeLayout(&swapped, pins, count-1, false, is33, noCross)
recBestScore := Score(swapped)
if recBestScore < bestSoFarScore {
bestSoFarScore = recBestScore
Expand Down Expand Up @@ -156,7 +156,7 @@ func MinimizeLayout(init *Layout, pins [][]string, count int, top bool, is33 boo
break
}
}
*init = bestLayout
*init = bestLayout
}

func LoadLayout(f string) Layout {
Expand Down Expand Up @@ -264,22 +264,22 @@ func FingerSpeed(l *Layout, weighted bool) []float64 {
p2 := &posits[j]
k1 := &l.Keys[p1.Row][p1.Col]
k2 := &l.Keys[p2.Row][p2.Col]

sfb := float64(Data.Bigrams[*k1+*k2])
dsfb := Data.Skipgrams[*k1+*k2]
if i != j {
sfb += float64(Data.Bigrams[*k2+*k1])
dsfb += Data.Skipgrams[*k2+*k1]
}

dist := twoKeyDist(*p1, *p2) + (2*Weight.FSpeed.KeyTravel)
dist := twoKeyDist(*p1, *p2) + (2 * Weight.FSpeed.KeyTravel)
speeds[f] += ((sfbweight * sfb) + (dsfbweight * dsfb)) * dist
}
}
if weighted {
speeds[f] /= Weight.FSpeed.KPS[f]
}
speeds[f] = 800 * speeds[f]/l.Total
speeds[f] = 800 * speeds[f] / l.Total
}
return speeds
}
Expand All @@ -299,11 +299,11 @@ func DynamicFingerSpeed(l *Layout, weighted bool) []float64 {
p2 := &posits[j]
k1 := &l.Keys[p1.Row][p1.Col]
k2 := &l.Keys[p2.Row][p2.Col]

sfb := float64(Data.Bigrams[*k1+*k2])
dsfb := Data.Skipgrams[*k1+*k2]
dist := twoKeyDist(*p1, *p2) + (2*Weight.FSpeed.KeyTravel)

dist := twoKeyDist(*p1, *p2) + (2 * Weight.FSpeed.KeyTravel)
speed := ((sfbweight * sfb) + (dsfbweight * dsfb)) * dist
if sfb > highestsfb {
highestsfb = sfb
Expand All @@ -320,7 +320,7 @@ func DynamicFingerSpeed(l *Layout, weighted bool) []float64 {
if weighted {
speeds[f] /= Weight.FSpeed.KPS[f]
}
speeds[f] = 800 * speeds[f]/l.Total
speeds[f] = 800 * speeds[f] / l.Total
}
return speeds
}
Expand Down Expand Up @@ -434,7 +434,6 @@ func ListDynamic(l Layout) ([]FreqPair, []FreqPair) {
return escaped, real
}


func ListWorstBigrams(l Layout) []FreqPair {
var bigrams []FreqPair
sfbweight := Weight.FSpeed.SFB
Expand All @@ -453,9 +452,9 @@ func ListWorstBigrams(l Layout) []FreqPair {
dsfb += Data.Skipgrams[*k2+*k1]
}

dist := twoKeyDist(*p1, *p2) + (2*Weight.FSpeed.KeyTravel)
cost := 100* (((sfbweight * sfb) + (dsfbweight * dsfb)) * dist) / Weight.FSpeed.KPS[f]
bigrams = append(bigrams, FreqPair{*k1+*k2,cost})
dist := twoKeyDist(*p1, *p2) + (2 * Weight.FSpeed.KeyTravel)
cost := 100 * (((sfbweight * sfb) + (dsfbweight * dsfb)) * dist) / Weight.FSpeed.KPS[f]
bigrams = append(bigrams, FreqPair{*k1 + *k2, cost})
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,13 @@ func main() {
}
} else if args[0] == "g" {
best := Populate(1000)

optimal := Score(best)

type x struct {
name string
score float64
}


var sorted []x

Expand Down
Loading

0 comments on commit 184179b

Please sign in to comment.