我正在将一些Java代码移植到Google的Go语言中,并转换所有代码,但在平滑的移植之后,我只停留在一部分上。我的Go代码如下所示,并且我正在谈论的部分已被注释掉:func main() { var puzzleHistory * vector.Vector; puzzleHistory = vector.New(0); var puzzle PegPuzzle; puzzle.InitPegPuzzle(3,2); puzzleHistory.Push(puzzle); var copyPuzzle PegPuzzle; var currentPuzzle PegPuzzle; currentPuzzle = puzzleHistory.At(0).(PegPuzzle); isDone := false; for !isDone { currentPuzzle = puzzleHistory.At(0).(PegPuzzle); currentPuzzle.findAllValidMoves(); for i := 0; i < currentPuzzle.validMoves.Len(); i++ { copyPuzzle.NewPegPuzzle(currentPuzzle.holes, currentPuzzle.movesAlreadyDone); copyPuzzle.doMove(currentPuzzle.validMoves.At(i).(Move)); // There is no function in Go's Vector that will remove an element like Java's Vector //puzzleHistory.removeElement(currentPuzzle); copyPuzzle.findAllValidMoves(); if copyPuzzle.validMoves.Len() != 0 { puzzleHistory.Push(copyPuzzle); } if copyPuzzle.isSolutionPuzzle() { fmt.Printf("Puzzle Solved"); copyPuzzle.show(); isDone = true; } } }}如果没有可用的版本(我相信没有),没有人知道我将如何独自实现这样的事情吗?
- 2 回答
- 0 关注
- 190 浏览
添加回答
举报
0/150
提交
取消