Skip to content

Commit

Permalink
Tincy bit of refactoring and TODOing
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhydian Jenkins committed Feb 17, 2024
1 parent 185b878 commit 52f437e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
13 changes: 5 additions & 8 deletions pkg/board/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,20 @@ func (board *Board) findLowestEntropyTiles() []*Tile {
for x := 0; x < BoardSize; x++ {
for y := 0; y < BoardSize; y++ {
tile := board.GetTile(x, y)
possibleValues := calculatePossibleValues(*board, x, y)
entropy := len(possibleValues)
tile.possibleValues = calculatePossibleValues(*board, x, y)
tileEntropy := tile.GetEntropy()

if entropy < lowestEntropy && entropy > 0 {
lowestEntropy = entropy
if tileEntropy < lowestEntropy && tileEntropy > 0 {
lowestEntropy = tileEntropy
}

tile.possibleValues = possibleValues
tile.entropy = entropy
}
}

for x := 0; x < BoardSize; x++ {
for y := 0; y < BoardSize; y++ {
tile := board.GetTile(x, y)

if tile.entropy == lowestEntropy {
if tile.GetEntropy() == lowestEntropy {
lowestEntropyTiles = append(lowestEntropyTiles, tile)
}
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/board/tile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package board
import "fmt"

const Empty int = 0
const InitialEntropy int = -1

type Tile struct {
x int
y int
value int
entropy int
possibleValues []int
}

Expand All @@ -18,7 +16,6 @@ func NewTile(x, y int) Tile {
x: x,
y: y,
value: Empty,
entropy: InitialEntropy,
possibleValues: []int{},
}
}
Expand All @@ -30,3 +27,7 @@ func (tile Tile) isEmpty() bool {
func (tile Tile) String() string {
return fmt.Sprintf("[ %d ]", tile.value)
}

func (tile Tile) GetEntropy() int {
return len(tile.possibleValues)
}
14 changes: 14 additions & 0 deletions pkg/board/utils.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
package board

func solveOneStep(board Board) {
panic("TODO: implement")

// 1. get slice of lowest entropy tiles
// 2. for each tile, get possible values
// 3. if only one possible value, set the value
// 4. if no possible value, return error
// 5. select random tile from lowest entropy tiles
// 6. select random value from possible values
// 7. set the value
// 8. ???
// 9. profit
}

func calculatePossibleValues(board Board, x, y int) []int {
tile := board.tiles[x][y]

Expand Down

0 comments on commit 52f437e

Please sign in to comment.