Skip to content

Commit

Permalink
Checkpoint: failing test with some issues with setting tile entropies
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhydian Jenkins committed Feb 16, 2024
1 parent 14f554e commit b670070
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 9 deletions.
35 changes: 35 additions & 0 deletions pkg/board/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,41 @@ func New() Board {
}
}

func (board Board) findLowestEntropyTiles() []Tile {
lowestEntropy := NumValues
lowestEntropyTiles := []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)

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

tile.entropy = entropy
tile.possibleValues = possibleValues

fmt.Println("board.GetTile(0,1) in first loop:", board.GetTile(0, 1).entropy)
fmt.Println("tile.enropy in first loop:", tile.entropy)
}
}

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

if tile.entropy == lowestEntropy {
lowestEntropyTiles = append(lowestEntropyTiles, tile)
}
}
}

return lowestEntropyTiles
}

func (board Board) String() string {
return fmt.Sprintf("%v", board.tiles)
}
Expand Down
14 changes: 12 additions & 2 deletions pkg/board/board_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ func TestGetCol(t *testing.T) {
tiles := b.GetTiles()

for i := 0; i < BoardSize; i++ {
if col[i] != tiles[i][colNum] {
if col[i].x != tiles[i][colNum].x || col[i].y != tiles[i][colNum].y {
t.Errorf("Expected 0, got %v", col[i])
}
}
}

func TestCalculatePossibleValuesWithNonEmptyVal(t *testing.T) {
returned := calculatePossibleValues(New(), 0, 0)
expected := []int{1}
expected := []int{}

if !reflect.DeepEqual(expected, returned) {
t.Errorf("Expected %v, got %v", expected, returned)
Expand All @@ -44,3 +44,13 @@ func TestFilterEmpty(t *testing.T) {
t.Errorf("Expected %v, got %v", expected, returned)
}
}

func TestFindLowestEntropyTiles(t *testing.T) {
board := New()
returned := board.findLowestEntropyTiles()
expected := []Tile{board.GetTile(0, 1), board.GetTile(1, 0)}

if !reflect.DeepEqual(expected, returned) {
t.Errorf("Expected %v, got %v", expected, returned)
}
}
17 changes: 11 additions & 6 deletions pkg/board/tile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ package board
import "fmt"

const Empty int = 0
const InitialEntropy int = -1

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

func NewTile(x, y int) Tile {
return Tile{
x: x,
y: y,
value: Empty,
x: x,
y: y,
value: Empty,
entropy: InitialEntropy,
possibleValues: []int{},
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/board/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ func calculatePossibleValues(board Board, x, y int) []int {
tile := board.tiles[x][y]

if !tile.isEmpty() {
return []int{tile.value}
return []int{}
}

row := board.GetRow(tile.x)
Expand Down

0 comments on commit b670070

Please sign in to comment.