Skip to content

Commit

Permalink
Adding lines and columns on board struct to facilitate navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
kbca committed Mar 16, 2022
1 parent 5c08324 commit 7f6abd4
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions domain/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,30 @@ import (
)

type cell struct {
coordX int
coordY int
line int
column int
number int
}

type Board struct {
cells [81]cell
cells [81]cell
lines [9][9]*cell
columns [9][9]*cell
}

func (board *Board) defineCoords() {
currentX, currentY := 1, 1
currentLine, currentColumn := 1, 1
for i := range board.cells {
board.cells[i].coordX = currentX
board.cells[i].coordY = currentY
board.cells[i].line = currentLine
board.cells[i].column = currentColumn

currentX++
if currentX > 9 {
currentX = 1
currentY++
board.lines[currentLine-1][currentColumn-1] = &board.cells[i]
board.columns[currentColumn-1][currentLine-1] = &board.cells[i]

currentLine++
if currentLine > 9 {
currentLine = 1
currentColumn++
}
}
}
Expand Down

0 comments on commit 7f6abd4

Please sign in to comment.