Skip to content

Commit

Permalink
Checkpoint: solve one step first stap
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhydian Jenkins committed Feb 17, 2024
1 parent 52f437e commit 4df1b0d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
12 changes: 12 additions & 0 deletions pkg/board/board_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package board

import (
"fmt"
"reflect"
"testing"
)
Expand Down Expand Up @@ -54,3 +55,14 @@ func TestFindLowestEntropyTiles(t *testing.T) {
t.Errorf("Expected %v, got %v", expected, returned)
}
}

// TODO
func TestSolveOneStep(t *testing.T) {
board := New()
solveOneStep(&board)
solveOneStep(&board)
solveOneStep(&board)

// is random /really/ random?
fmt.Println(board)
}
23 changes: 21 additions & 2 deletions pkg/board/utils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package board

func solveOneStep(board Board) {
panic("TODO: implement")
import (
"math/rand"
"time"
)

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

// 1. get slice of lowest entropy tiles
// 2. for each tile, get possible values
Expand All @@ -12,6 +17,20 @@ func solveOneStep(board Board) {
// 7. set the value
// 8. ???
// 9. profit

lowestEntropyTiles := board.findLowestEntropyTiles()

if len(lowestEntropyTiles) == 0 {
panic("No solution found. TODO backgrack")
}

rand.Seed(time.Now().Unix())
randomTileIndex := rand.Intn(len(lowestEntropyTiles))
randomTile := lowestEntropyTiles[randomTileIndex]
randomValueIndex := rand.Intn(len(randomTile.possibleValues))
randomValue := randomTile.possibleValues[randomValueIndex]

randomTile.value = randomValue
}

func calculatePossibleValues(board Board, x, y int) []int {
Expand Down

0 comments on commit 4df1b0d

Please sign in to comment.