2009-11-26 2 views
1

일부 Java 코드를 Google Go 언어로 이식하고 놀랍게도 매끄러운 포트를 사용한 후에 하나의 파트에만 붙어있는 것을 제외하고는 모든 코드를 변환합니다. 내 이동 코드는 다음과 같습니다 내가 이야기하고있는 부분은 주석 : 나는이없는 생각 가능한 버전이없는 경우Vector 클래스에서 Vector Package와 같은 removeElement 함수의 버전이 있습니까?

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; 
      } 
     } 
    } 
} 

... 사람이 내가 구현하는 방법에 대한 갈 것이라고 알고 있나요 나 혼자서 그런거야?

답변

0

어떨까요? Vector.Delete (i)는 어떻습니까?

0

지금 당장 일반 동등 연산자는 지원되지 않습니다. 따라서 벡터를 반복하고 올바른 것을 제거하는 무언가를 써야합니다.

관련 문제