public void NextActionAI() { //保证游戏状态是游戏中 if (userGUI.gameState == -1 || userGUI.gameState == 1) { return; } //得到当前状态 //计算所有在左边的牧师/恶魔 int numDevilLeft = leftBank.getNumDevil(), numPriestLeft = leftBank.getNumPriest(); int numDevilBoat = boat.getNumDevil(), numPriestBoat = boat.getNumPriest(); if (boat.getState() == 1) { numDevilLeft += numDevilBoat; numPriestLeft += numPriestBoat; } Debug.Log("numDevilLeft " + numDevilLeft); Debug.Log("numPriestLeft " + numPriestLeft); int boatPos = boat.getState(); //获取下一个状态 int[] next = ai.getNextAction(numDevilLeft, numPriestLeft, boat.getState()); Debug.Log("next[0] " + next[0]); Debug.Log("next[1] " + next[1]); //其实next就表示要放在船上的人 //转换到下一个状态 /* * numDveilToBoat = 0, numPriestToBoat = 0 要变得和next一样 * 先boat -> 岸 * 第一个是P * next[0] > 0 留着 numPriestToBoat++ * next[0] = 0 放回去 * 第一个是D * next[1] 同上 numDveilToBoat++ * 第二个是P * next[0] = 2 且 numPriestToBoat = 1 留着 * next[0] = 1 放回去 * 第二个是D * 同上 * 再 岸 -> boat * 看一下 num和next没满足的,放岸上的去船上即可 */ int numPriestToBoat = 0, numDevilToBoat = 0; int[] personOnBoat = boat.getPersonOnBoat(); if (personOnBoat[0] >= 3 && personOnBoat[0] <= 6) //第一个是P { if (next[0] > 0) //P保持不动 { numPriestToBoat++; } else if (next[0] == 0) //把这个P放去岸上 { clickACharacter(characters[personOnBoat[0]]); } } else if (personOnBoat[0] >= 0 && personOnBoat[0] <= 2) //第一个是D { if (next[1] > 0) { numDevilToBoat++; } else if (next[1] == 0) { clickACharacter(characters[personOnBoat[0]]); } } if (personOnBoat[1] >= 3 && personOnBoat[1] <= 6) //第二个是P { if (next[0] == 2 || (next[0] == 1 && numPriestToBoat == 0)) //P不用动 { numPriestToBoat++; } else if (next[0] == 0 || (next[0] == 1 && numPriestToBoat == 1)) //把这个P放去岸上 { clickACharacter(characters[personOnBoat[1]]); } } else if (personOnBoat[1] >= 0 && personOnBoat[1] <= 2) //第二个是D { if (next[1] == 2 || (next[1] == 1 && numDevilToBoat == 0)) { numDevilToBoat++; } else if (next[1] == 0 || (next[1] == 1 && numDevilToBoat == 1)) { clickACharacter(characters[personOnBoat[1]]); } } /* * 岸 -> 船 */ for (int i = 0; i < next[0] - numPriestToBoat; i++) // P { int index = -1; if (boatPos == 1) { index = leftBank.getAPriestIndex(); } else if (boatPos == 2) { index = rightBank.getAPriestIndex(); } clickACharacter(characters[index]); } for (int i = 0; i < next[1] - numDevilToBoat; i++) // P { int index = -1; if (boatPos == 1) { index = leftBank.getADevilIndex(); } else if (boatPos == 2) { index = rightBank.getADevilIndex(); } clickACharacter(characters[index]); } //移动船 Invoke("moveBoat", (float)0.6); }
public void NextActionAI() { //保证游戏状态是游戏中 int flag = judge.check(); if (flag == 1 || flag == 2) { return; } //得到当前状态 //计算所有在左边的牧师/恶魔 int numDevilLeft = judge.from_devil, numPriestLeft = judge.from_priest; Debug.Log("numDevilLeft " + numDevilLeft); Debug.Log("numPriestLeft " + numPriestLeft); int boatPos = judge.Boat.get_is_from(); //获取下一个状态 Debug.Log("State:" + numDevilLeft + numPriestLeft + judge.Boat.get_is_from()); int[] next = ai.getNextAction(numDevilLeft, numPriestLeft, judge.Boat.get_is_from()); Debug.Log("next[0] " + next[0]); Debug.Log("next[1] " + next[1]); //其实next就表示要放在船上的人 //转换到下一个状态 /* * numDveilToBoat = 0, numPriestToBoat = 0 要变得和next一样 * 先boat -> 岸 * 第一个是P * next[0] > 0 留着 numPriestToBoat++ * next[0] = 0 放回去 * 第一个是D * next[1] 同上 numDveilToBoat++ * 第二个是P * next[0] = 2 且 numPriestToBoat = 1 留着 * next[0] = 1 放回去 * 第二个是D * 同上 * 再 岸 -> boat * 看一下 num和next没满足的,放岸上的去船上即可 */ int numPriestToBoat = 0, numDevilToBoat = 0; int[] personOnBoat = judge.Boat.getPersonOnBoat(); Debug.Log("******************Boat0 " + personOnBoat[0] + "*******************boat1" + personOnBoat[1]); if (personOnBoat[0] >= 3 && personOnBoat[0] <= 6) //第一个是P { if (next[0] > 0) //P保持不动 { numPriestToBoat++; } else if (next[0] == 0) //把这个P放去岸上 { Debug.Log("**********************************getoff P" + personOnBoat[0]); moveCharacter(characters[personOnBoat[0]]); } } else if (personOnBoat[0] >= 0 && personOnBoat[0] <= 2) //第一个是D { if (next[1] > 0) { numDevilToBoat++; } else if (next[1] == 0) { Debug.Log("**********************************getoff D" + personOnBoat[0]); moveCharacter(characters[personOnBoat[0]]); } } if (personOnBoat[1] >= 3 && personOnBoat[1] <= 6) //第二个是P { if (next[0] == 2 || (next[0] == 1 && numPriestToBoat == 0)) //P不用动 { numPriestToBoat++; } else if (next[0] == 0 || (next[0] == 1 && numPriestToBoat == 1)) //把这个P放去岸上 { Debug.Log("**********************************getoff P" + personOnBoat[1]); moveCharacter(characters[personOnBoat[1]]); } } else if (personOnBoat[1] >= 0 && personOnBoat[1] <= 2) //第二个是D { if (next[1] == 2 || (next[1] == 1 && numDevilToBoat == 0)) { numDevilToBoat++; } else if (next[1] == 0 || (next[1] == 1 && numDevilToBoat == 1)) { Debug.Log("**********************************getoff D" + personOnBoat[1]); moveCharacter(characters[personOnBoat[1]]); } } /* * 岸 -> 船 */ for (int i = 0; i < next[0] - numPriestToBoat; i++) // P { int index = -1; if (boatPos == 1) { index = fromCoast.getAPriestIndex(); } else if (boatPos == -1) { index = toCoast.getAPriestIndex(); } Debug.Log("**********************************geton P" + index); moveCharacter(characters[index]); } for (int i = 0; i < next[1] - numDevilToBoat; i++) // D { int index = -1; if (boatPos == 1) { index = fromCoast.getADevilIndex(); } else if (boatPos == -1) { index = toCoast.getADevilIndex(); } Debug.Log("**********************************geton D" + index); moveCharacter(characters[index]); } //移动船 Invoke("moveBoat", (float)0.6); Debug.Log("------------------------------------------------------"); }