private void CalculateMove() { moveChosen = false; selectedMove = 0; selectedSpot = 0; //Find move that leads to most opponent players off board List <PieceContainerControl> spots = moveCont.GetAvailableSpots(); MoveStruct bestMove = new MoveStruct(); foreach (PieceContainerControl init in spots) { foreach (int end in init.actualPossibleMoves) { //Decide if this is the move we want GameState gs = new GameState(moveCont.gameMaster); MoveStruct ms = new MoveStruct(); ms.initPosition = init.position; ms.endPosition = end; ms.isBlack = moveCont.isBlack; ms.moveUps = selectedMove; ms.spotUps = selectedSpot; ms.score = gs.MakeMove(ms); if (ms.score > bestMove.score) { bestMove = ms; } selectedMove++; } selectedMove = 0; selectedSpot++; } selectedSpot = bestMove.spotUps; selectedMove = bestMove.moveUps; moveChosen = true; }
public void AddMove(MoveAction moveAction, ObjectInteractionController oicCaller, Collider other) { MoveStruct MStructToAdd = new MoveStruct { moveAction = moveAction, oicCaller = oicCaller, other = other }; moveList.Add(MStructToAdd); }
public int MakeMove(MoveStruct ms) { GameObject currentPiece; //Remove from initial Spot if (ms.initPosition >= 0 && ms.initPosition < allSpots.Length) { currentPiece = allSpots[ms.initPosition].pieces[0]; allSpots[ms.initPosition].RemovePiece(currentPiece); } else { if (ms.isBlack) { currentPiece = blackJail.pieces[0]; blackJail.RemovePiece(currentPiece); } else { currentPiece = whiteJail.pieces[0]; whiteJail.RemovePiece(currentPiece); } } //Add to end spot if (ms.endPosition >= 0 && ms.endPosition < allSpots.Length) { allSpots[ms.endPosition].AddPiece(currentPiece); } else { if (ms.isBlack) { blackBase.AddPiece(currentPiece); } else { whiteBase.AddPiece(currentPiece); } } return(GetScore(ms.isBlack)); }
public void RemoveMove(MoveAction moveAction, ObjectInteractionController oicCaller, Collider other) { MoveStruct MStructToAdd = new MoveStruct { moveAction = moveAction, oicCaller = oicCaller, other = other }; if (moveList != null) { for (int i = 0; i < moveList.Count; i++) { if (moveAction == moveList[i].moveAction && oicCaller == moveList[i].oicCaller && other == moveList[i].other) { moveList.Remove(moveList[i]); break; } } } }
// Перемещение кошки public void Go(MoveStruct MoveAngle) { Vector3 Move = MoveAngle.Move; float current_angle = MoveAngle.Angle; float Angle_Rotation_Speed = 5.0f; float Rotation_Variable; //------------------------------------------------------------------ //-------NOT USED CODE . ATTEMPT OF AUTOMATIZATION //------------------------------------------------------------------ // float Left_Angle = 180f; // float Right_Angle = 0f; // float Down_Angle = 90f; // float Up_Angle = 270f; // // float Up_Right_Angle = 315f; float Down_Right_Angle = 45f; // float Down_Left_Angle = 135f; // float Up_Left_Angle = 225f; float Rotation_Angle_Steps = 0; float [] Angle_Steps = new float[361]; float [] Angle_Steps_Difference_with_Angle_Left_Side = new float[361]; float [] Angle_Steps_Difference_with_Angle_Right_Side = new float[361]; float Angle_Steps_Difference_with_Angle_Left_Side_MIN = 0; float Angle_Steps_Difference_with_Angle_Right_Side_MIN = 0; for (int Counter = 0; Counter < 361; Counter++) { Angle_Steps [Counter] = Rotation_Angle_Steps + Angle_Rotation_Speed; Angle_Steps_Difference_with_Angle_Left_Side [Counter] = Down_Right_Angle - Angle_Steps [Counter]; Angle_Steps_Difference_with_Angle_Right_Side [Counter] = Angle_Steps [Counter] - Down_Right_Angle; } Angle_Steps_Difference_with_Angle_Left_Side_MIN = Angle_Steps_Difference_with_Angle_Left_Side [0]; Angle_Steps_Difference_with_Angle_Right_Side_MIN = Angle_Steps_Difference_with_Angle_Right_Side [0]; for (int Counter = 0; Counter < 361; Counter++) { if (Angle_Steps_Difference_with_Angle_Left_Side [Counter] < Angle_Steps_Difference_with_Angle_Left_Side_MIN) { Angle_Steps_Difference_with_Angle_Left_Side_MIN = Angle_Steps_Difference_with_Angle_Left_Side[Counter]; } if (Angle_Steps_Difference_with_Angle_Right_Side [Counter] < Angle_Steps_Difference_with_Angle_Right_Side_MIN) { Angle_Steps_Difference_with_Angle_Right_Side_MIN = Angle_Steps_Difference_with_Angle_Right_Side [Counter]; } } //------------------------------------------------------------------ //-------NOT USED CODE . ATTEMPT OF AUTOMATIZATION //------------------------------------------------------------------ Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y; //----------------------------------------------------------------- // ------------------------- Go DOWN ----------------------------- //----------------------------------------------------------------- if ((MoveVertical < 0) && (MoveHorizontal == 0)) { //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, 90.0f, 0.0f); if ((current_angle < 270.0f) && (current_angle > 90.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y - Angle_Rotation_Speed; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if ((current_angle >= 270.0f) && (current_angle < 360.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y + Angle_Rotation_Speed; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if (current_angle == 360.0f) { Rotation_Variable = 0.0f; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if ((current_angle >= 0.0f) && (current_angle < 90.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y + Angle_Rotation_Speed; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if ((current_angle >= 90.0f - Angle_Rotation_Speed) && (current_angle <= 90.0f + Angle_Rotation_Speed)) { Rotation_Variable = 90.0f; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } //----------------------------------------------------------------- // ------------------------- Go DOWN ----------------------------- //----------------------------------------------------------------- //----------------------------------------------------------------- // ------------------------- Go UP ----------------------------- //----------------------------------------------------------------- if ((MoveVertical > 0) && (MoveHorizontal == 0)) { // HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, 270.0f, 0.0f); if ((current_angle >= 90.0f) && (current_angle < 270.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y + Angle_Rotation_Speed; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if ((current_angle < 90.0f) && (current_angle > 0.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y - Angle_Rotation_Speed; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if (current_angle <= 00.0f) { Rotation_Variable = 360; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if ((current_angle <= 360.0f) && (current_angle > 270.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y - Angle_Rotation_Speed; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if ((current_angle <= 270.0f + Angle_Rotation_Speed) && (current_angle >= 270.0f - Angle_Rotation_Speed)) { Rotation_Variable = 270.0f; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } //----------------------------------------------------------------- // ------------------------- Go UP ----------------------------- //----------------------------------------------------------------- //----------------------------------------------------------------- // ------------------------- Go LEFT ----------------------------- //----------------------------------------------------------------- if ((MoveVertical == 0) && (MoveHorizontal < 0)) { //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, 180.0f, 0.0f); if ((current_angle <= 360.0f) && (current_angle > 180.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y - Angle_Rotation_Speed; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if ((current_angle >= 0.0f) && (current_angle < 180.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y + Angle_Rotation_Speed; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if ((current_angle >= 180.0f - Angle_Rotation_Speed) && (current_angle <= 180.0f + Angle_Rotation_Speed)) { Rotation_Variable = 180.0f; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } //----------------------------------------------------------------- // ------------------------- Go LEFT ----------------------------- //----------------------------------------------------------------- //----------------------------------------------------------------- // ------------------------- Go RIGHT ----------------------------- //----------------------------------------------------------------- if ((MoveVertical == 0) && (MoveHorizontal > 0)) { //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, 360.0f, 0.0f); if ((current_angle >= 180.0f) && (current_angle < 360.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y + Angle_Rotation_Speed; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if ((current_angle < 180.0f) && (current_angle > 0.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y - Angle_Rotation_Speed; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if ((current_angle >= 360.0f - Angle_Rotation_Speed) && (current_angle <= 360.0f + Angle_Rotation_Speed)) { Rotation_Variable = 0.0f; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if ((current_angle >= 0.0f - Angle_Rotation_Speed) && (current_angle <= 0.0f + Angle_Rotation_Speed)) { Rotation_Variable = 0.0f; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } //----------------------------------------------------------------- // ------------------------- Go RIGHT ----------------------------- //----------------------------------------------------------------- //----------------------------------------------------------------- // ------------------------- Go LEFT-DOWM ----------------------------- //----------------------------------------------------------------- if ((MoveVertical < 0) && (MoveHorizontal < 0)) { //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, 135.0f, 0.0f); if ((current_angle <= 315.0f) && (current_angle > 135.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y - Angle_Rotation_Speed; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if ((current_angle > 315.0f) && (current_angle <= 360.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y + Angle_Rotation_Speed; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if (current_angle >= 360.0f) { current_angle = 0.0f; } if ((current_angle >= 0.0f) && (current_angle < 135.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y + Angle_Rotation_Speed; // HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if ((current_angle >= 135.0f - Angle_Rotation_Speed) && (current_angle <= 135.0f + Angle_Rotation_Speed)) { Rotation_Variable = 135.0f; // HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } // HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f) } //----------------------------------------------------------------- // ------------------------- Go LEFT-DOWM ----------------------------- //----------------------------------------------------------------- //----------------------------------------------------------------- // ------------------------- Go RIGHT-UP ----------------------------- //----------------------------------------------------------------- if ((MoveVertical > 0) && (MoveHorizontal > 0)) { //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, 315.0f, 0.0f); if ((current_angle >= 135.0f) && (current_angle < 315.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y + Angle_Rotation_Speed; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if ((current_angle < 135.0f) && (current_angle > 0.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y - Angle_Rotation_Speed; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if (current_angle == 0.0f) { current_angle = 360.0f; } if ((current_angle <= 360.0f) && (current_angle > 315.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y - Angle_Rotation_Speed; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if ((current_angle >= 315.0f - Angle_Rotation_Speed) && (current_angle <= 315.0f + Angle_Rotation_Speed)) { Rotation_Variable = 315.0f; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } //----------------------------------------------------------------- // ------------------------- Go RIGHT-UP ----------------------------- //----------------------------------------------------------------- //----------------------------------------------------------------- // ------------------------- Go LEFT-UP ----------------------------- //----------------------------------------------------------------- if ((MoveVertical > 0) && (MoveHorizontal < 0)) { //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, 225.0f, 0.0f); if ((current_angle <= 360.0f) && (current_angle > 225.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y - Angle_Rotation_Speed; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if ((current_angle <= 45.0f) && (current_angle > 0.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y - Angle_Rotation_Speed; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if (current_angle == 0.0f) { current_angle = 360.0f; } if ((current_angle < 225.0f) && (current_angle > 45.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y + Angle_Rotation_Speed; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if ((current_angle >= 225.0f - Angle_Rotation_Speed) && (current_angle <= 225.0f + Angle_Rotation_Speed)) { Rotation_Variable = 225.0f; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } // HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } //----------------------------------------------------------------- // ------------------------- Go LEFT-UP ----------------------------- //----------------------------------------------------------------- //----------------------------------------------------------------- // ------------------------- Go RIGHT-DOWN ----------------------------- //----------------------------------------------------------------- if ((MoveVertical < 0) && (MoveHorizontal > 0)) { //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, 45.0f, 0.0f); if ((current_angle >= 225.0f) && (current_angle < 360.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y + Angle_Rotation_Speed; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if (current_angle == 360.0f) { current_angle = 0.0f; } if ((current_angle >= 0.0f) && (current_angle < 45.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y + Angle_Rotation_Speed; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if ((current_angle < 225.0f) && (current_angle > 45.0f)) { Rotation_Variable = HellCat_Object.GetComponent <Rigidbody>().rotation.eulerAngles.y - Angle_Rotation_Speed; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } if ((current_angle >= 45.0f - Angle_Rotation_Speed) && (current_angle <= 45.0f + Angle_Rotation_Speed)) { Rotation_Variable = 45.0f; //HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } // HellCat_Object.GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, Rotation_Variable, 0.0f); } //----------------------------------------------------------------- // ------------------------- Go RIGHT-DOWN ----------------------------- //----------------------------------------------------------------- HellCat_Object.GetComponent <Rigidbody>().rotation = Quaternion.Euler(0.0f, Rotation_Variable, 0.0f); // Формирование движения кошки if (Level_Borders_Check(HellCat_Object.GetComponent <Rigidbody>().position + Move / Speed) == true) { if (Hellcat_Mode == false) { //кошка над землей HellCat_Object.GetComponent <Rigidbody>().position = HellCat_Object.GetComponent <Rigidbody>().position + Move / Speed; } else { //кошка под землей (быстрее двигается чем над землей) HellCat_Object.GetComponent <Rigidbody>().position = HellCat_Object.GetComponent <Rigidbody>().position + Move / (Speed / 2); } } }