maybe done

lul not tested yet
This commit is contained in:
Kistaro Windrider 2024-02-05 18:10:29 -08:00
parent cc3abb1fcf
commit de0b82e7d7
Signed by: kistaro
SSH Key Fingerprint: SHA256:TBE2ynfmJqsAf0CP6gsflA0q5X5wD5fVKWPsZ7eVUg8

62
uckf.go
View File

@ -5,7 +5,8 @@ package main
import (
"flag"
"fmt"
"math"
"log"
"math.rand"
)
var edgeSize = flag.Int("n", 8, "Cells per side")
@ -21,6 +22,9 @@ type fuckness [3][3]scanState
func main() {
flag.Parse()
if (*edgeSize < 4) {
log.Fatalf("can't fit a fuck into edge size %d", *edgeSize)
}
var board [][]byte
for i := 0; i < *edgeSize; i++ {
fuckingRow := make([]byte, *edgeSize)
@ -49,8 +53,11 @@ func main() {
dump(board, "Not a single fuck")
}
func onBoard(i, j) {
return i > 0 && j > 0 && i < *edgeSize && j < &edgeSize
}
func charAt(board [][]byte, i, j int) byte {
if i < 0 || j < 0 || i >= len(board) || j >= len(board[i]) {
if !onBoard(i, j) {
return 5
}
return board[i][j]
@ -126,7 +133,58 @@ func fuckUp(board [][]byte, evals [][]fuckness) {
var todo [][2]int
for i, row := range evals {
for j, e := range row {
if isFucked(e) {
todo = append(todo, [2]int{i, j})
} else if mightBeFucked(e) {
dump(board, "Oh fuck")
log.Fatalf("unevaluated fuckness at %d, %d: %v", i, j, e)
}
}
}
rand.Shuffle(len(todo), func(i, j int) {
todo[j], todo[i] = todo[i], todo[j]
})
// note: "head" moves frequently within this loop
for head := 0; head < len(todo); head++ {
item := todo[head]
i, j := item[0], item[1]
if(!isFucked(evals[i][j])) {
continue
}
i2, j2 := -1, -1
for(head++; head < len(todo); head++) {
item2 := todo(head)
itmp, jtmp := item2[0], item2[1]
if(isFucked(evals[itmp][jtmp])) {
i2, j2 = itmp, jtmp
break
}
}
if i2 == -1 {
// fuck it, swap randomly
i2 = rand.Intn(*edgeSize)
j2 = rand.Intn(*edgeSize)
}
if board[i][j] != board[i2][j2] {
unevaluate(evals, i, j)
unevaluate(evals, i2, j2)
board[i][j], board[i2][j2] = board[i2][j2], board[i][j]
}
}
}
func unevaluate(evals [][]fuckness, i, j) {
for dr := -1; dr <= 1; dr++ {
for dc := -1; dc <= 1; dc++ {
for x := -3; x < 4; x++ {
r := i + dr * x
c := j + dc * x
if onBoard(r, c) {
evals[r][c][dr+1][dc+1] = FuckIfIKnow
}
}
}
}
}