//駒をrotate辺回転する ex)rotateが-1で10角形なら-36度 public void RotatePiece(int pieceId, int rotate) { Pieces piece = GetPieceById(pieceId); int rotationAmount = (360 / piece.GetShape()) * rotate; Quaternion rot = Quaternion.AngleAxis(rotationAmount, Vector3.up); Quaternion q = piece.transform.rotation; piece.transform.rotation = q * rot; int forwardFaceId = fieldManager.ConvertRelative2AbsId(piece.GetFaceId(), 0, piece.GetForwardDirection()); piece.SetForwardFaceId(forwardFaceId); }
// return circle faceId private List <int> circleFaceIdCheck(FieldManager field, Pieces piece) { //何角形のますにいるかをint型で返す int faceShape = piece.GetShape(); List <int> circleFaceIdCheck = new List <int>(); //辞書型配列で受け取る Dictionary <int, List <int> > MovableRange = GameManager.ManagerStore.piecesManager.GetMoveRange(piece.GetKind()); //辞書型配列で受け取った稼働範囲からforeachでそれぞれ検証 List <int> movableFaces = MovableRange[faceShape]; foreach (int movableFace in movableFaces) { //候補の面の相対idを絶対idに変換 circleFaceIdCheck.Add(field.ConvertRelative2AbsId(piece.GetFaceId(), movableFace, piece.GetForwardDirection())); } return(circleFaceIdCheck); }
//面の絶対Idを指定するとそこに駒が移動する public void MovePiece(int pieceId, int faceId) { Pieces piece = GetPieceById(pieceId); GameObject pieceObject = piece.gameObject; int FaceId = piece.GetFaceId(); fieldManager.DeleteFieldInfo(pieceId); fieldManager.SetPieceAsChild(faceId, pieceObject); fieldManager.WriteFieldInfo(pieceId, faceId); GameObject surfacObj = fieldManager.GetFace2Face(faceId, FaceId); piece.transform.LookAt(surfacObj.transform); fieldManager.AligmentObject(piece.gameObject); int forwardFaceId = surfacObj.GetComponent <Field.SurfaceInfo>().FaceId; piece.SetFaceId(faceId); piece.SetForwardFaceId(forwardFaceId); }
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); }
// rotate selected piece private void rotatePiece(FieldManager field, Pieces piece, int degree) { piece.RotatePiece(degree); preDecision.SetMovePieceId(piece.GetPieceId()); preDecision.SetMoveFaceId(piece.GetFaceId()); }