-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rhydian Jenkins
committed
Feb 16, 2024
1 parent
0b51d76
commit 14f554e
Showing
4 changed files
with
47 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package board | ||
|
||
func calculatePossibleValues(board Board, x, y int) []int { | ||
tile := board.tiles[x][y] | ||
|
||
if !tile.isEmpty() { | ||
return []int{tile.value} | ||
} | ||
|
||
row := board.GetRow(tile.x) | ||
col := board.GetCol(tile.y) | ||
possibleValues := []int{} | ||
|
||
for i := 1; i <= NumValues; i++ { | ||
possibleValues = append(possibleValues, i) | ||
} | ||
|
||
for i := 0; i < BoardSize; i++ { | ||
if !row[i].isEmpty() { | ||
possibleValues[row[i].value-1] = Empty | ||
} | ||
|
||
if !col[i].isEmpty() { | ||
possibleValues[col[i].value-1] = Empty | ||
} | ||
} | ||
|
||
return filterEmpty(possibleValues) | ||
} | ||
|
||
func filterEmpty(slice []int) []int { | ||
var filtered []int | ||
for _, value := range slice { | ||
if value != Empty { | ||
filtered = append(filtered, value) | ||
} | ||
} | ||
return filtered | ||
} |