//局面を戻す public void MoveBack(IReversibleMove move) { int movePieceId = fieldManager.IsPieceOnFace(move.GetMoveToFaceId()); PlayerBase myPlayer, enemyPlayer; if (player[0].HasPiece(movePieceId)) { myPlayer = player[0]; enemyPlayer = player[1]; } else { myPlayer = player[1]; enemyPlayer = player[0]; } if (move.IsMove())//動きの場合 { Pieces movePiece = myPlayer.GetPieceById(movePieceId); myPlayer.MovePiece(movePieceId, move.GetMoveFromFaceId());//駒をもとの位置へ int rotationNum = 0; while (movePiece.GetForwardFaceId() != move.GetMoveFromForwardFaceId()) { myPlayer.RotatePiece(movePieceId, 1);//向きが合うまで回転させて駒の向き修正 rotationNum++; if (rotationNum > 20) {//20回転以上で中断 Debug.Log("エラー 向きを戻せませんでした"); break; } } if (move.IsCaptured())//駒を取っていた場合 { enemyPlayer.AddMyPieces (move.GetCapturedPieceKind(), move.GetMoveToFaceId() , move.GetCapturedPieceForwardFaceId(), false);//取った敵の駒を復活させる } } else//回転の場合 { myPlayer.RotatePiece(movePieceId, -move.GetRotateDirection()); } }
public void SetInfo(PlayerBase cp, FieldManager field) { //TestStrategy(cp, field); //maybe can't use // makeOrder(cp, field); // it has some bugs. //choiceOrder(); /* check all pieces * foreach (Pieces check in cpList) * { * checkPieceProperty(field, check); * } * */ //int num1 = 0; //moving //int num2 = 2; //purpose //int result = 0; //List<Pieces> cpList = cp.GetMyPieces(); //foreach(Pieces piece in cpList) //{ // num1++; // if(num1 == num2) // { // Debug.Log("Rotate!!"); // rotatePiece(field, piece, 1); // if (result!=0) // { // num2++; // } // } //} /* * foreach (Pieces piece in cpList) * { * result = 0; * result = circleChainCheck(piece.GetFaceId()); * Debug.Log("aaaaaaa"); * Debug.Log(piece.GetPieceId()); * Debug.Log(result); * Debug.Log("bbbbbbbb"); * * if (result != 0) * { * if (piece.GetKind().ToString().Equals("King")) * { * Debug.Log("KING"); * } * debugPiecesInfo(piece); * Debug.Log("uruboros"); * Debug.Log(result); * Debug.Log("-------"); * } * * } */ /*--- Set Observation ---*/ var cp_player = ManagerStore.cp; var player = ManagerStore.humanPlayer; var fieldManager = ManagerStore.fieldManager; var info = new List <float>(); /*Set Info as [持ち駒数, 動いた駒のId,動いた駒の向いているマスのId,敵の持ち駒,敵の動いた駒のId,敵の駒の向いているマス]*/ //テストようにランダムに動かす if (true || player == null || cp_player == null || p_movedpieces == null || cp_movedpieces == null) { var cp__ = cp_player.GetMyPieces(); var piece__ = cp__[UnityEngine.Random.Range(0, cp__.Count())]; var piece_vFace = ManagerStore.piecesManager.GetMoveRange(piece__.GetKind())[piece__.GetShape()]; var face__ = UnityEngine.Random.Range(0, piece_vFace.Count()); var absFaceId_ = GameManager.ManagerStore.fieldManager.ConvertRelative2AbsId(piece__.GetFaceId(), piece_vFace[face__], piece__.GetForwardDirection()); //Queenの二週目の挙動を無理やり矯正(kisuke) if (piece__.GetKind() == PieceKind.Queen && face__ == (piece__.GetShape())) { var fFaceId_ = piece__.GetForwardFaceId(); var ffFace_ = ManagerStore.fieldManager.GetFace2Face(fFaceId_, piece__.GetFaceId()); absFaceId_ = ffFace_.GetComponent <Field.SurfaceInfo>().FaceId; } FinalSet(absFaceId_, piece__.GetPieceId(), 0); return; } info.Add(player.GetMyPieces().Count); info.Add(p_movedpieces.GetFaceId()); info.Add(p_movedpieces.GetForwardFaceId()); info.Add(cp_player.GetMyPieces().Count); info.Add(cp_movedpieces.GetFaceId()); info.Add(cp_movedpieces.GetForwardFaceId()); agent.SetObserVation(info); /*--- Get Action ---*/ var act = agent.GetActionVector(); int controlPieceId = (int)(Mathf.Clamp(act[0] * 11f, 0, player.GetMyPieces().Count - 1)); int isRotate = (int)Mathf.Clamp(act[1], 0, 2); int movableFaceId = (int)(Mathf.Clamp(act[2] * 10f, 0, 9)); var piece = cp_player.GetMyPieces()[controlPieceId]; var pieceId = piece.GetPieceId(); var absFaceId = fieldManager.ConvertRelative2AbsId(piece.GetFaceId(), movableFaceId, piece.GetForwardDirection()); if (isRotate == 1) { isRotate = 1; } else if (isRotate == 2) { isRotate = -1; } Debug.Log("安全確認、ヨシ!"); // Debug.Log(faceSaferyCheck(1,preDecision.GetMoveFaceId(), cp, field)); p_movedpieces = piece; FinalSet(absFaceId, pieceId, isRotate); }