Initial commit: it compiles?

This commit is contained in:
Madison Rye Progress
2025-08-25 23:02:06 -07:00
parent 9ab2fb22fb
commit 82e7f3b393
9 changed files with 408 additions and 0 deletions

27
go.mod Normal file
View File

@ -0,0 +1,27 @@
module git.makyo.dev/makyo/gogogogogram
go 1.24.6
require github.com/charmbracelet/bubbletea v1.3.6
require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
github.com/charmbracelet/lipgloss v1.1.0 // indirect
github.com/charmbracelet/x/ansi v0.9.3 // indirect
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/sync v0.15.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/text v0.3.8 // indirect
)

45
go.sum Normal file
View File

@ -0,0 +1,45 @@
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/charmbracelet/bubbletea v1.3.6 h1:VkHIxPJQeDt0aFJIsVxw8BQdh/F/L2KKZGsK6et5taU=
github.com/charmbracelet/bubbletea v1.3.6/go.mod h1:oQD9VCRQFF8KplacJLo28/jofOI2ToOfGYeFgBBxHOc=
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs=
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk=
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
github.com/charmbracelet/x/ansi v0.9.3 h1:BXt5DHS/MKF+LjuK4huWrC6NCvHtexww7dMayh6GXd0=
github.com/charmbracelet/x/ansi v0.9.3/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE=
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8=
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=

22
main.go Normal file
View File

@ -0,0 +1,22 @@
package main
import (
"fmt"
"os"
"git.makyo.dev/makyo/gogogogogram/model"
tea "github.com/charmbracelet/bubbletea"
)
func main() {
m, err := model.New(4, 4)
if err != nil {
fmt.Printf("Ah, drat — %v", err)
os.Exit(1)
}
p := tea.NewProgram(m)
if _, err := p.Run(); err != nil {
fmt.Printf("Ah drat. %v", err)
os.Exit(1)
}
}

57
model/cursor.go Normal file
View File

@ -0,0 +1,57 @@
package model
func (m Model) CursorCellUp() Model {
if m.cursor-m.size > 0 {
m.cursor -= m.size
}
return m
}
func (m Model) CursorCellDown() Model {
if m.cursor+m.size < m.size*m.size {
m.cursor += m.size
}
return m
}
func (m Model) CursorCellRight() Model {
if m.cursor%m.size < m.size {
m.cursor++
}
return m
}
func (m Model) CursorCellLeft() Model {
if m.cursor%m.size != 1 {
m.cursor--
}
return m
}
func (m Model) CursorSectionUp() Model {
if m.cursor > m.size*m.perSection {
m.cursor -= m.size * m.perSection
}
return m
}
func (m Model) CursorSectionDown() Model {
if m.cursor < m.size*m.perSection*(m.section-1) {
m.cursor += m.size * m.perSection
}
return m
}
func (m Model) CursorSectionRight() Model {
if m.cursor%m.perSection < m.section-1 {
m.cursor += m.section
}
return m
}
func (m Model) CursorSectionLeft() Model {
if m.cursor%m.perSection > 0 {
m.cursor -= m.section
}
return m
}

36
model/guessing.go Normal file
View File

@ -0,0 +1,36 @@
package model
import "fmt"
func (m Model) Mark() Model {
if m.marks&m.cursor != 0 {
m.marks |= m.cursor
m.flags = m.flags &^ m.cursor
} else {
m.marks = m.marks &^ m.cursor
}
m.history = append(m.history, fmt.Sprintf("m%d", m.cursor))
m = m.update()
return m
}
func (m Model) Flag() Model {
if m.flags&m.cursor != 0 {
m.flags |= m.cursor
m.marks = m.marks &^ m.cursor
} else {
m.flags = m.flags &^ m.cursor
}
m.history = append(m.history, fmt.Sprintf("f%d", m.cursor))
m = m.update()
return m
}
func (m Model) ClearGuess() Model {
m.marks = m.marks &^ m.cursor
m.flags = m.flags &^ m.cursor
m.correct = m.correct &^ m.cursor
m.history = append(m.history, fmt.Sprintf("c%d", m.cursor))
m = m.update()
return m
}

29
model/model.go Normal file
View File

@ -0,0 +1,29 @@
package model
type Model struct {
size, section, perSection int
field, view int
marks, flags int
correct, sections, completed int
clears, score, factor, track int
cursor int
columnStates, rowStates [][]int
columnsCorrect, rowsCorrect []bool
history []string
}
func New(section, perSection int) (Model, error) {
m := Model{
size: section * perSection,
section: section,
perSection: perSection,
}
for i := 0; i < section*section; i++ {
m = m.randomizeSection(i)
}
return m, nil
}

30
model/section.go Normal file
View File

@ -0,0 +1,30 @@
package model
import "math/rand"
func (m Model) randomizeSection(s int) Model {
m = m.clearSection(s)
for y := 0; y < m.section; y++ {
for x := 0; x < m.section; x++ {
cell := ((s/m.section)*m.size + y) + ((s%m.size)*m.section + x)
if rand.Int()%2 == 1 {
m.field |= cell
}
}
}
return m
}
func (m Model) clearSection(s int) Model {
m.sections = m.sections &^ s
for y := 0; y < m.section; y++ {
for x := 0; x < m.section; x++ {
cell := ((s/m.section)*m.size + y) + ((s%m.size)*m.section + x)
m.field = m.field &^ cell
m.marks = m.marks &^ cell
m.flags = m.flags &^ cell
m.correct = m.correct &^ cell
}
}
return m
}

63
model/tea.go Normal file
View File

@ -0,0 +1,63 @@
package model
import tea "github.com/charmbracelet/bubbletea"
func (m Model) Init() tea.Cmd {
return nil
}
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
// Quitting
case "ctrl+c":
return m, tea.Quit
// Movement by cell
case "up", "w":
m = m.CursorCellUp()
case "down", "s":
m = m.CursorCellDown()
case "right", "d":
m = m.CursorCellRight()
case "left", "a":
m = m.CursorCellLeft()
// Movement by section
case "ctrl+up", "ctrl+w", "shift+up", "shift+w":
m = m.CursorSectionUp()
case "ctrl+down", "ctrl+s", "shift+down", "shift+s":
m = m.CursorSectionDown()
case "ctrl+right", "ctrl+d", "shift+right", "shift+d":
m = m.CursorSectionRight()
case "ctrl+left", "ctrl+a", "shift+left", "shift+a":
m = m.CursorSectionRight()
// Marking/flagging
case " ", "enter":
m = m.Mark()
case "x":
m = m.Flag()
case "delete", "backspace":
m = m.ClearGuess()
}
}
return m, nil
}
func (m Model) View() string {
return ""
}

99
model/update.go Normal file
View File

@ -0,0 +1,99 @@
package model
func (m Model) update() Model {
// Reset sections to all true
m.sections = m.section*m.section - 1
// Update correctness/sections
for i := 0; i < m.size*m.size; i++ {
cell := m.field & i
marked := m.marks & i
flagged := m.flags & i
// Update the correctness of each cell
m.correct |= (cell & marked) | (flagged &^ cell)
// Update the correctness of each section
cellSection := ((i / (m.section * m.size)) * m.section) + (i/m.perSection)%m.section
m.sections &= m.correct & cellSection
}
// Check for complete sections, which are those where the row and column are both correct
completedIndices := map[int]bool{}
for i := 0; i < m.section*m.section; i++ {
if m.sections&i == 0 {
continue
}
mask := 0
x := i % m.section
y := i / m.section
for j := 0; j < m.section; j++ {
mask |= 1<<x + (j * m.section)
mask |= 1<<y + j
}
if m.sections&mask == mask {
completedIndices[i] = true
}
}
// Check for clears
clearedIndices := map[int]bool{}
clearedIncrease := 0
for i, _ := range completedIndices {
x := i % m.section
y := i / m.section
right := x + 1
if right == m.section {
right = -1
}
down := m.section
if y+1 == m.section {
down = -m.section
}
_, okRight := completedIndices[i+right]
_, okDown := completedIndices[i+down]
_, okDownRight := completedIndices[i+right+down]
if okRight && okDown && okDownRight {
clearedIndices[i] = true
clearedIndices[i+right] = true
clearedIndices[i+down] = true
clearedIndices[i+down+right] = true
clearedIncrease++
m.completed |= 1 << i
m.completed |= 1<<i + right
m.completed |= 1<<i + down
m.completed |= 1<<i + down + right
}
}
// Clear and bump scores
for i, _ := range clearedIndices {
m = m.randomizeSection(i)
}
if clearedIncrease > 0 {
m.score += clearedIncrease * (m.factor + 1)
m.clears++
}
// Check for blackout
if m.completed == m.section*m.section-1 {
m.completed = 0
m.factor++
}
// Update row/column states/correctness
for x := 0; x < m.size; x++ {
rowCorrect := true
columnCorrect := true
for y := 0; y < m.size; y++ {
cellCorrect := m.correct&y*m.size+x != 0
rowCorrect = rowCorrect && cellCorrect
columnCorrect = columnCorrect && cellCorrect
}
}
return m
}