public void startBfsAlgorithm(int missionary, int cannibal, int boatNumber) { this.maxMissionary = missionary; this.maxCannibal = cannibal; this.maxBoatNumber = boatNumber; var initState = new MAC.State(missionary, cannibal, MAC.Solve.LEFT_BOAT_STATE); var root = new MAC.Node(0, 0, null, initState); resultNodeList = new MAC.Solve(missionary, cannibal, boatNumber).findAndReturnResultList(root); totalText.text = "총 경우의 수 : " + resultNodeList.Count.ToString(); resultNumberSelecter.GetComponent <NumberSelecterScript> ().minNumber = 1; resultNumberSelecter.GetComponent <NumberSelecterScript> ().maxNumber = resultNodeList.Count; //foreach(ArrayList nodelist in resultNodeList) { // foreach(MAC.Node node in nodelist) { // Debug.Log (node); // } // break; //} }
private void makeGameState(ArrayList nodeList) { List <GameState> gameStateList = new List <GameState> (); for (var i = 0; i < nodeList.Count; i++) { if (i + 1 < nodeList.Count) { MAC.State state = ((MAC.Node)nodeList [i]).state; MAC.State nextState = ((MAC.Node)nodeList [i + 1]).state; // Ready // 노드 자체의 상태 gameStateList.Add(new GameState( state.missionary, state.cannibal, maxMissionary - state.missionary, maxCannibal - state.cannibal, state.boatMove ? State.Boat.LEFT_R : State.Boat.RIGHT_L)); // Move // 노드 - 다음 노드 사이의 상태 if (state.boatMove) { // 오른쪽에서 왼쪽 // RIGHT_RIDDEN_BOAT gameStateList.Add(new GameState( State.People.RIGHT_RIDDEN_BOAT, state.missionary, state.cannibal, nextState.missionary - state.missionary, nextState.cannibal - state.cannibal, maxMissionary - nextState.missionary, maxCannibal - nextState.cannibal, State.Boat.RIGHT_L)); // MOVING_FROM_RIGHT_TO_LEFT gameStateList.Add(new GameState( State.People.MOVING_FROM_RIGHT_TO_LEFT, state.missionary, state.cannibal, nextState.missionary - state.missionary, nextState.cannibal - state.cannibal, maxMissionary - nextState.missionary, maxCannibal - nextState.cannibal, State.Boat.FROM_RIGHT_TO_LEFT_L)); } else { // 왼쪽에서 오른쪽 // LEFT_RIDDEN_BOAT gameStateList.Add(new GameState( State.People.LEFT_RIDDEN_BOAT, nextState.missionary, nextState.cannibal, state.missionary - nextState.missionary, state.cannibal - nextState.cannibal, maxMissionary - state.missionary, maxCannibal - state.cannibal, State.Boat.LEFT_R)); // MOVING_FROM_LEFT_TO_RIGHT gameStateList.Add(new GameState( State.People.MOVING_FROM_LEFT_TO_RIGHT, nextState.missionary, nextState.cannibal, state.missionary - nextState.missionary, state.cannibal - nextState.cannibal, maxMissionary - state.missionary, maxCannibal - state.cannibal, State.Boat.FROM_LEFT_TO_RIGHT_R)); } } else { MAC.State lastState = ((MAC.Node)nodeList [i]).state; gameStateList.Add(new GameState( lastState.missionary, lastState.cannibal, maxMissionary - lastState.missionary, maxCannibal - lastState.cannibal, State.Boat.RIGHT_L)); } } //foreach(GameState gameState in gameStateList) { // Debug.Log(gameState); //} //Debug.Log ("----------------------------"); proceedList.Add(gameStateList); }