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