Zwischenstand

This commit is contained in:
Karl Spickermann 2021-12-24 13:31:48 +01:00
parent 737b2a9376
commit 6f91c0b535

View File

@ -30,13 +30,15 @@ var enterableCorridorPos = [7]int{0, 1, 3, 5, 7, 9, 10}
func main() {
playBoard := board{
[11]rune{'.', '.', '.', '.', '.', '.', '.', '.', '.', '.'},
[4][4]rune{{'D', 'D', 'D', 'B'}, {'D', 'C', 'B', 'A'}, {'C', 'B', 'A', 'A'}, {'B', 'A', 'C', 'C'}}}
currentBoards := []board
endBoards := []board
[11]rune{'.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.'},
[4][4]rune{{'D', 'D', 'D', 'B'}, {'D', 'C', 'B', 'A'}, {'C', 'B', 'A', 'A'}, {'B', 'A', 'C', 'C'}}, 0}
currentBoards := []board{}
endBoards := []board{}
currentBoards = append(currentBoards, playBoard)
for len(currentBoards) > 0 {
step(&currentBoards, &endBoards)
fmt.Println(len(currentBoards))
fmt.Println(len(endBoards))
}
fmt.Println(len(endBoards))
minEnergy := 9999999
@ -53,7 +55,7 @@ func main() {
func checkWinner(board board) bool {
for amphoidType, room := range destX {
for _, val := range board.rooms[room] {
if val != amphoidType && val != '.' {
if val != amphoidType {
return false
}
}
@ -62,27 +64,24 @@ func checkWinner(board board) bool {
}
func step(currentBoards *[]board, endBoards *[]board) {
fmt.Print("hll")
for selectedBoard, selectedEnergy := range *currentBoards {
var newBoards []board
for _, selectedBoard := range *currentBoards {
possibleMoves := getPossibleMoves(selectedBoard)
if len(possibleMoves) == 0 {
if (*endBoards)[selectedBoard] == 0 || selectedEnergy < (*endBoards)[selectedBoard] {
(*endBoards)[selectedBoard] = selectedEnergy
}
*endBoards = append(*endBoards, selectedBoard)
}
for start, targets := range possibleMoves {
for _, target := range targets {
tmpNewBoard, tmpNewErnergy := useMove(selectedBoard, [2][2]int{start, target}, selectedEnergy)
if (*currentBoards)[tmpNewBoard] == 0 || tmpNewErnergy < (*currentBoards)[tmpNewBoard] {
(*currentBoards)[tmpNewBoard] = tmpNewErnergy
}
tmpNewBoard := useMove(selectedBoard, [2][2]int{start, target})
newBoards = append(newBoards, tmpNewBoard)
}
}
}
*currentBoards = newBoards
return
}
func useMove(board board, move [2][2]int, ernergy int) (board, int) {
func useMove(board board, move [2][2]int) board {
//Remove moved Amphoid
var amphoidType rune
if move[0][0] == 0 {
@ -109,8 +108,8 @@ func useMove(board board, move [2][2]int, ernergy int) (board, int) {
traveledDistance += Abs(move[1][1] - (move[0][0]*2 + 2))
traveledDistance += move[0][1] + 1
}
ernergy += costs[amphoidType] * (traveledDistance)
return board, ernergy
board.energy += costs[amphoidType] * (traveledDistance)
return board
}
func getPossibleMoves(board board) map[[2]int][][2]int {