move makeMinMaxMove(List<int> vm) { move bestMove = new move (); List<int> validMovesClone = new List<int> (); for (int i = 0; i < vm.Count; i++) { move tempMove = new move(); tempMove.pos = vm[i]; // Make a copy of the old valid moves before doing anything validMovesClone = vm; // Should happen in a split second if(GameObject.Find ("GameController").GetComponent<GameController>().getIsXTurn()) { GameObject.Find ("B"+vm.ToString ()).GetComponentInChildren<Text>().text = "X"; vm.Remove(i); if(GameObject.Find ("GameController").GetComponent<GameController>().CheckWin() == 0) tempMove.rank = 1; else if(GameObject.Find ("GameController").GetComponent<GameController>().CheckWin() == 1) tempMove.rank = -1; else if (GameObject.Find ("GameController").GetComponent<GameController>().getTotalMoves () + 1 == 9) tempMove.rank = 0; else { if (vm.Count>0) tempMove.rank = -makeMinMaxMove (vm).rank; else break; } } else { GameObject.Find ("B"+validMoves[i].ToString()).GetComponentInChildren<Text>().text = "O"; vm.Remove(i); if(GameObject.Find ("GameController").GetComponent<GameController>().CheckWin() == 0) tempMove.rank = -1; else if(GameObject.Find ("GameController").GetComponent<GameController>().CheckWin() == 1) tempMove.rank = 1; else if (GameObject.Find ("GameController").GetComponent<GameController>().getTotalMoves ()+1 == 9) tempMove.rank = 0; else { if (vm.Count>0) tempMove.rank = -makeMinMaxMove (vm).rank; else break; } } // revert board to original state GameObject.Find ("B"+vm.ToString ()).GetComponentInChildren<Text>().text = ""; } Debug.Log (bestMove.pos); return bestMove; }
// Use this for initialization void Start() { player = GameObject.FindGameObjectWithTag (Tags.Player); PlayerController = player.GetComponent<move>(); rotation = Random.onUnitSphere; rotateSpeed = Random.Range (0.2f,3.0f); worldRotateSpeed = Random.Range (-30.0f,50.0f); }
protected void Init() { bf = BattlefieldScript.Instance; //bfc = bf.bf; su = Submarine.Instance; sh = Ship.Instance; //la = LanguageScript.Instance; mo = move.Instance; la = LanguageScript.Instance; }
void Start() { _instance = this; bf = BattlefieldScript.Instance; //bfc = bf.bf; su = Submarine.Instance; sh = Ship.Instance; //la = LanguageScript.Instance; mo = move.Instance; reward = new Reward (false, 2); }
void Start() { Debug.Log ("!!! MULTIPLAYER INITIATED !!!"); _instance = this; bf = BattlefieldScript.Instance; bfc = bf.bf; su = Submarine.Instance; sh = Ship.Instance; la = LanguageScript.Instance; mo = move.Instance; reward = new Reward (false, 5); }
public bool Move(char c) { try { move dc = new move(this.MoveAsync); AsyncCallback cb = new AsyncCallback(this.GetMoveResultsOnCallback); IAsyncResult ar = dc.BeginInvoke(c, cb, null); } catch (Exception ex) { return false; } return true; }
// Use this for initialization void Start() { Move = character.GetComponent <move>(); }
// Use this for initialization void Start() { player = GameObject.FindGameObjectWithTag(Tags.Player); movecs = player.GetComponent <move> (); greenLight = GetComponent <Light> (); }
public move miniMaxBetter(PieceColor [,] currentBoard, int depth, bool maximizingPlayer, int alpha, int beta, int i2, int j2) { //bool breaking = false; //print(depth); if (depth == 0 && maximizingPlayer) { move endMove; //endMove.value = boardPoints[i2, j2]; endMove.value = 0; endMove.i = i2; endMove.j = j2; endMove.points = 0; return(endMove); } if (depth == 0 && !maximizingPlayer) { move endMove; //endMove.value = boardPoints[i2, j2]; endMove.value = 0; endMove.i = i2; endMove.j = j2; endMove.points = 0; return(endMove); } //White Player if (maximizingPlayer) { move bestMove; bestMove.value = -99999; bestMove.i = -1; bestMove.j = -1; bestMove.points = -1; for (int j = 0; j <= BOARD_SIZE; j++) { for (int i = 0; i <= BOARD_SIZE; i++) { DirectionalPieces dPiece = gmScript.isValidMove(i, j, PieceColor.White, currentBoard); if (dPiece.down || dPiece.left || dPiece.up || dPiece.right || dPiece.leftDown || dPiece.leftUp || dPiece.rightDown || dPiece.rightUp) { currentBoard[i, j] = PieceColor.White; move currentMove = miniMaxBetter(currentBoard, depth - 1, false, alpha, beta, i, j); currentMove.value += boardPoints[i, j]; currentMove.points += dPiece.points; if (currentMove.value > bestMove.value) { bestMove.value = currentMove.value; bestMove.i = i; bestMove.j = j; bestMove.points = currentMove.points; } else if (currentMove.value == bestMove.value) { if (currentMove.points > bestMove.points) { bestMove.value = currentMove.value; bestMove.i = i; bestMove.j = j; bestMove.points = currentMove.points; } } else { //currentMove.value -= boardPoints[i, j]; } //undo our moves as we get out of them currentBoard[i, j] = PieceColor.Null; //alpha beta pruning alpha = Mathf.Max(alpha, bestMove.value); if (beta <= alpha) { return(bestMove); //breaking = true; //for double for loop //break; } } } //if (breaking) break; //double for loop } return(bestMove); } //end of if statement //player's turn else { move bestMove; bestMove.value = 99999; bestMove.i = -1; bestMove.j = -1; bestMove.points = -1; for (int j = 0; j <= BOARD_SIZE; j++) { for (int i = 0; i <= BOARD_SIZE; i++) { DirectionalPieces dPiece = gmScript.isValidMove(i, j, PieceColor.Black, currentBoard); if (dPiece.down || dPiece.left || dPiece.up || dPiece.right || dPiece.leftDown || dPiece.leftUp || dPiece.rightDown || dPiece.rightUp) { currentBoard[i, j] = PieceColor.Black; move currentMove = miniMaxBetter(currentBoard, depth - 1, true, alpha, beta, i, j); currentMove.value -= boardPoints[i, j]; currentMove.points -= dPiece.points; if (currentMove.value < bestMove.value) { bestMove.value = currentMove.value; bestMove.i = i; bestMove.j = j; bestMove.points = currentMove.points; } else if (currentMove.value == bestMove.value) { if (currentMove.points < bestMove.points) { bestMove.value = currentMove.value; bestMove.i = i; bestMove.j = j; bestMove.points = currentMove.points; } } else { //currentMove.value += boardPoints[i, j]; } currentBoard[i, j] = PieceColor.Null; //alpha beta pruning beta = Mathf.Min(beta, bestMove.value); if (beta <= alpha) { return(bestMove); //breaking = true; //for double for loop //break; } } } //if (breaking) break; } return(bestMove); } //end of else } //end of minimaxbetter
void Start() { object_script = objectToMove.GetComponent <move>(); animator = this.GetComponent <Animator>(); }
return(ParsePromotion(move, white, false));
void FixedUpdate() { if (isLocalPlayer) { // get current move state move moveState = new move(playerScript.horizAxis, playerScript.vertAxis, Network.time); // buffer move state moveHistory.Insert(0, moveState); // cap history at 200 if (moveHistory.Count > 200) { moveHistory.RemoveAt(moveHistory.Count - 1); } // simulate playerScript.Simulate(); // send state to server CmdProvideMovementToServer(moveState.HorizontalAxis, moveState.VerticalAxis, playerTransform.position); } }
// Start is called before the first frame update void Start() { m = player.GetComponent <move>(); Counter(); }
//this is called when the creator of this object assigns a new move void setMove(move newMove) { Move = newMove; setUp(); }
// Start is called before the first frame update void Start() { powersign.enabled = false; chara = GameObject.Find("chara").GetComponent <move>(); }
private void mode_izimekko() { this.transform.position = new Vector3(this.transform.position.x, 0.5f, this.transform.position.z); float DistanceToTarget = 0.0f; //目標点との距離 Quaternion TargetRotation; //目標点への方向 DistanceToTarget = Vector3.Distance(this.transform.position, TargetPosition); //いじめられっ子への距離を計算 if (izimepower >= 30) { switch (move_mode_izimekko) { case move_izimekko.loitering: //徘徊 //いじめっ子と目標点との距離を求める DistanceToTarget = Vector3.SqrMagnitude(transform.position - TargetPosition); //目標点との距離が近ければ、その場でキョロキョロする動きをする if (DistanceToTarget < CangeTargetDistance) { change_move_time = 0; move_mode_izimekko = move_izimekko.sarchi; break; } //目標点の方を向く TargetRotation = Quaternion.LookRotation(TargetPosition - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, TargetRotation, Time.deltaTime * 2); //前に進む object_move(this.transform.position, Speed); change_move_time--; //いじめられっ子が視界内にいるか if (srachizimerarekko() == true && change_move_time <= 0) { change_move_time = 0; move_mode = move.izimerarekko; break; } float izimekko_Ldis = 0.0f; if (izimekko_Ldis < 20.0f) { //move_mode = move.izimekko_L; break; } break; case move_izimekko.sarchi: //動かずにキョロキョロする overlooking_time++; if (overlooking_time >= 50) { overlooking_time = 0; srach_angle *= -1.0f; } transform.Rotate(new Vector3(0.0f, srach_angle, 0.0f)); change_move_time++; if (change_move_time >= 600) { TargetPosition = GetPosition(); srach_angle = 0; move_mode = move.loitering; break; } //いじめられっ子が視界内にいるか if (srachizimerarekko() == true && change_move_time <= 0) { change_move_time = 0; move_mode = move.izimerarekko; break; } break; case move_izimekko.izimerarekko: //いじめられっ子へ向かう //目標点(いじめられっ子)の方を向く TargetRotation = Quaternion.LookRotation(targetizimerarekko.transform.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, TargetRotation, Time.deltaTime * 10); //目標点(いじめられっ子)に進む object_move(this.transform.position, Speed); //視界からいじめられっ子がいなくなると立ち止まる if (srachizimerarekko() == false) { change_move_time = 0; move_mode_izimekko = move_izimekko.stop; break; } //いじめられっ子に近づくとその場でいじめる if (Vector3.Distance(targetizimerarekko.transform.position, transform.position) <= 2.0f) { izimerarekko m_izimerarekko = targetizimerarekko.GetComponent <izimerarekko>(); m_izimerarekko.izimekko_count(); move_mode_izimekko = move_izimekko.izime; } change_move_time++; if (change_move_time >= 300) { change_move_time = 300; TargetPosition = GetPosition(); move_mode_izimekko = move_izimekko.loitering; //徘徊 break; } break; case move_izimekko.izimekko_L: //いじめっ子リーダーに付きまとう //目標点(いじめっ子リーダー)の方を向く TargetRotation = Quaternion.LookRotation(m_izimekko_l.transform.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, TargetRotation, Time.deltaTime * 2); //目標点(いじめっ子リーダー)に進む object_move(this.transform.position, Speed); break; case move_izimekko.izime: break; case move_izimekko.stop: change_move_time++; if (change_move_time > 120) { change_move_time = 0; move_mode_izimekko = move_izimekko.loitering; break; } //いじめられっ子が視界内にいるか if (srachizimerarekko() == true) { change_move_time = 0; move_mode_izimekko = move_izimekko.izimerarekko; break; } break; default: break; } } else { Destroy(this); } }
private void Awake() { move = GetComponent <move>();//进行角色方向控制时就调用move中的函数 contral = GetComponent <Charactercontral>(); }
private void OnTriggerEnter(Collider other) { if (other.name == "Player") { move playerScript = other.GetComponent <move>(); if (playerScript.invincibilityFrames <= 0) { playerScript.health -= damage; playerScript.invincibilityFrames = 1f; if (playerScript.falconry) { playerScript.movement = true; } //knockback code knockback code knockback code knockback code knockback code knockback code projectile isProjectile = gameObject.GetComponent <projectile>(); if (isProjectile != null) { playerScript.pos = playerScript.transform.position; playerScript.knockbackDirection = isProjectile.direction; playerScript.moveSpaces = 6; } else//not a projectile { //Debug.Log("testing"); if (Mathf.Abs(other.transform.position.x - gameObject.transform.position.x) > Mathf.Abs(other.transform.position.z - gameObject.transform.position.z)) {//on the side playerScript.pos = playerScript.transform.position; if (other.transform.position.x > gameObject.transform.position.x) { playerScript.knockbackDirection = 2; } else { playerScript.knockbackDirection = 4; } playerScript.moveSpaces = 6; } else {//above or below playerScript.pos = playerScript.transform.position; if (other.transform.position.z > gameObject.transform.position.z) { playerScript.knockbackDirection = 1; } else { playerScript.knockbackDirection = 3; } playerScript.moveSpaces = 6; } } } if (GetComponent <projectile>() != null) { Destroy(gameObject); } } }
// Use this for initialization void Start () { _instance = this; }
// Use this for initialization void Start() { player = GetComponentInParent <move>(); }
//Controla los pasos realizados con el Input en pantalla void steps() { mov = input.getInput(); if (src.isPlaying) { anim.enabled = true; } else { anim.enabled = false; if (actualSteps >= normalSteps.Length + grassSteps + woodSteps.Length) { genPhase = 3; playSound(2); //TTS.instance.PlayTTS("Desliza en cualquier dirección para romper las bandas policiales"); } } if (mov == move.pressing || mov == move.help) { if (phase == 0 && !src.isPlaying) { if (actualSteps < normalSteps.Length) { src.clip = normalSteps[actualSteps]; src.Play(); actualSteps++; } else { src.clip = grassStep; phase = 1; } } if (phase == 1 && !src.isPlaying) { if (actualSteps < normalSteps.Length + grassSteps) { src.clip = grassStep; src.Play(); actualSteps++; } else { src.clip = woodSteps[0]; phase = 2; } } if (phase == 2 && !src.isPlaying) { if (actualSteps < normalSteps.Length + grassSteps + woodSteps.Length) { src.clip = woodSteps[actualSteps - normalSteps.Length - grassSteps]; src.Play(); actualSteps++; } else { src.Stop(); genPhase = 3; } } } }
// Use this for initialization void Start() { theplayer = FindObjectOfType <move> (); }
public move ComputeBestMove(int piece) { List<move> moves = new List<move>(); //move currentmove = new move(); // Compute rating for each possible placement of given piece for (int i = 0; i < 4; i++) // Iterate thru 4 rotations { if (piece == 0) // I PIECE { if (i != 0 && i != 1) continue; if (i == 0) // * { for (int j = -5; j < 2; j++) // Iterate thru column translations from leftmost to rightmost { move newmove = new move(); // print("piece: " + piece + ", rot: " + i + ", tran: " + j); newmove = ComputeRowTransitions(piece, i, j); double rating = (-4.5 * newmove.landingheight) + (50 * newmove.rowseliminated) + (-3.2 * newmove.rowtrans) + (-9.3 * newmove.coltrans) + (-40 * newmove.holes) + (-3.4 * newmove.wellsums); moves.Add(new move(piece, i, j, newmove.landingheight, newmove.rowtrans, newmove.coltrans, newmove.rowseliminated, newmove.holes, newmove.wellsums, rating)); //print("piece: " + piece + ", rotation: " + i + ", translation: " + j + ", landingheight: " + newmove.landingheight + ", rowseliminated: " + newmove.rowseliminated + ", rowtrans: " + newmove.rowtrans + ", coltrans: " + newmove.coltrans + ", holes: " + newmove.holes + ", wellsums: " + newmove.wellsums + ", rating: " + rating); } } else if (i == 1) // * { for (int j = -7; j < 3; j++) { move newmove = new move(); //print("piece: "+piece+", rot: "+i+", tran: "+j); newmove = ComputeRowTransitions(piece, i, j); double rating = (-4.5 * newmove.landingheight) + (50 * newmove.rowseliminated) + (-3.2 * newmove.rowtrans) + (-9.3 * newmove.coltrans) + (-40 * newmove.holes) + (-3.4 * newmove.wellsums); moves.Add(new move(piece, i, j, newmove.landingheight, newmove.rowtrans, newmove.coltrans, newmove.rowseliminated, newmove.holes, newmove.wellsums, rating)); //print("piece: " + piece + ", rotation: " + i + ", translation: " + j + ", landingheight: " + newmove.landingheight + ", rowseliminated: " + newmove.rowseliminated + ", rowtrans: " + newmove.rowtrans + ", coltrans: " + newmove.coltrans + ", holes: " + newmove.holes + ", wellsums: " + newmove.wellsums + ", rating: " + rating); } } } else if (piece == 1) // J PIECE { if (i == 0) // * { for (int j = -5; j < 3; j++) { move newmove = new move(); //print("piece: "+piece+", rot: "+i+", tran: "+j); newmove = ComputeRowTransitions(piece, i, j); double rating = (-4.5 * newmove.landingheight) + (50 * newmove.rowseliminated) + (-3.2 * newmove.rowtrans) + (-9.3 * newmove.coltrans) + (-40 * newmove.holes) + (-3.4 * newmove.wellsums); moves.Add(new move(piece, i, j, newmove.landingheight, newmove.rowtrans, newmove.coltrans, newmove.rowseliminated, newmove.holes, newmove.wellsums, rating)); //print("piece: " + piece + ", rotation: " + i + ", translation: " + j + ", landingheight: " + newmove.landingheight + ", rowseliminated: " + newmove.rowseliminated + ", rowtrans: " + newmove.rowtrans + ", coltrans: " + newmove.coltrans + ", holes: " + newmove.holes + ", wellsums: " + newmove.wellsums + ", rating: " + rating); } } else if (i == 1) // * { for (int j = -5; j < 3; j++) { move newmove = new move(); //print("piece: "+piece+", rot: "+i+", tran: "+j); newmove = ComputeRowTransitions(piece, i, j); double rating = (-4.5 * newmove.landingheight) + (50 * newmove.rowseliminated) + (-3.2 * newmove.rowtrans) + (-9.3 * newmove.coltrans) + (-40 * newmove.holes) + (-3.4 * newmove.wellsums); moves.Add(new move(piece, i, j, newmove.landingheight, newmove.rowtrans, newmove.coltrans, newmove.rowseliminated, newmove.holes, newmove.wellsums, rating)); //print("piece: " + piece + ", rotation: " + i + ", translation: " + j + ", landingheight: " + newmove.landingheight + ", rowseliminated: " + newmove.rowseliminated + ", rowtrans: " + newmove.rowtrans + ", coltrans: " + newmove.coltrans + ", holes: " + newmove.holes + ", wellsums: " + newmove.wellsums + ", rating: " + rating); } } else if (i == 2) // * { for (int j = -5; j < 3; j++) { move newmove = new move(); //print("piece: "+piece+", rot: "+i+", tran: "+j); newmove = ComputeRowTransitions(piece, i, j); double rating = (-4.5 * newmove.landingheight) + (50 * newmove.rowseliminated) + (-3.2 * newmove.rowtrans) + (-9.3 * newmove.coltrans) + (-40 * newmove.holes) + (-3.4 * newmove.wellsums); moves.Add(new move(piece, i, j, newmove.landingheight, newmove.rowtrans, newmove.coltrans, newmove.rowseliminated, newmove.holes, newmove.wellsums, rating)); //print("piece: " + piece + ", rotation: " + i + ", translation: " + j + ", landingheight: " + newmove.landingheight + ", rowseliminated: " + newmove.rowseliminated + ", rowtrans: " + newmove.rowtrans + ", coltrans: " + newmove.coltrans + ", holes: " + newmove.holes + ", wellsums: " + newmove.wellsums + ", rating: " + rating); } } else if (i == 3) // * { for (int j = -5; j < 3; j++) { move newmove = new move(); //print("piece: "+piece+", rot: "+i+", tran: "+j); newmove = ComputeRowTransitions(piece, i, j); double rating = (-4.5 * newmove.landingheight) + (50 * newmove.rowseliminated) + (-3.2 * newmove.rowtrans) + (-9.3 * newmove.coltrans) + (-40 * newmove.holes) + (-3.4 * newmove.wellsums); moves.Add(new move(piece, i, j, newmove.landingheight, newmove.rowtrans, newmove.coltrans, newmove.rowseliminated, newmove.holes, newmove.wellsums, rating)); //print("piece: " + piece + ", rotation: " + i + ", translation: " + j + ", landingheight: " + newmove.landingheight + ", rowseliminated: " + newmove.rowseliminated + ", rowtrans: " + newmove.rowtrans + ", coltrans: " + newmove.coltrans + ", holes: " + newmove.holes + ", wellsums: " + newmove.wellsums + ", rating: " + rating); } } } else if (piece == 2) // L PIECE { if (i == 0) // * { for (int j = -5; j < 3; j++) { move newmove = new move(); //print("piece: "+piece+", rot: "+i+", tran: "+j); newmove = ComputeRowTransitions(piece, i, j); double rating = (-4.5 * newmove.landingheight) + (50 * newmove.rowseliminated) + (-3.2 * newmove.rowtrans) + (-9.3 * newmove.coltrans) + (-40 * newmove.holes) + (-3.4 * newmove.wellsums); moves.Add(new move(piece, i, j, newmove.landingheight, newmove.rowtrans, newmove.coltrans, newmove.rowseliminated, newmove.holes, newmove.wellsums, rating)); //print("piece: " + piece + ", rotation: " + i + ", translation: " + j + ", landingheight: " + newmove.landingheight + ", rowseliminated: " + newmove.rowseliminated + ", rowtrans: " + newmove.rowtrans + ", coltrans: " + newmove.coltrans + ", holes: " + newmove.holes + ", wellsums: " + newmove.wellsums + ", rating: " + rating); } } else if (i == 1) // * { for (int j = -6; j < 3; j++) { move newmove = new move(); //print("piece: "+piece+", rot: "+i+", tran: "+j); newmove = ComputeRowTransitions(piece, i, j); double rating = (-4.5 * newmove.landingheight) + (50 * newmove.rowseliminated) + (-3.2 * newmove.rowtrans) + (-9.3 * newmove.coltrans) + (-40 * newmove.holes) + (-3.4 * newmove.wellsums); moves.Add(new move(piece, i, j, newmove.landingheight, newmove.rowtrans, newmove.coltrans, newmove.rowseliminated, newmove.holes, newmove.wellsums, rating)); //print("piece: " + piece + ", rotation: " + i + ", translation: " + j + ", landingheight: " + newmove.landingheight + ", rowseliminated: " + newmove.rowseliminated + ", rowtrans: " + newmove.rowtrans + ", coltrans: " + newmove.coltrans + ", holes: " + newmove.holes + ", wellsums: " + newmove.wellsums + ", rating: " + rating); } } else if (i == 2) // * { for (int j = -5; j < 2; j++) { move newmove = new move(); //print("piece: "+piece+", rot: "+i+", tran: "+j); newmove = ComputeRowTransitions(piece, i, j); double rating = (-4.5 * newmove.landingheight) + (50 * newmove.rowseliminated) + (-3.2 * newmove.rowtrans) + (-9.3 * newmove.coltrans) + (-40 * newmove.holes) + (-3.4 * newmove.wellsums); moves.Add(new move(piece, i, j, newmove.landingheight, newmove.rowtrans, newmove.coltrans, newmove.rowseliminated, newmove.holes, newmove.wellsums, rating)); //print("piece: " + piece + ", rotation: " + i + ", translation: " + j + ", landingheight: " + newmove.landingheight + ", rowseliminated: " + newmove.rowseliminated + ", rowtrans: " + newmove.rowtrans + ", coltrans: " + newmove.coltrans + ", holes: " + newmove.holes + ", wellsums: " + newmove.wellsums + ", rating: " + rating); } } else if (i == 3) // * { for (int j = -6; j < 3; j++) { move newmove = new move(); //print("piece: "+piece+", rot: "+i+", tran: "+j); newmove = ComputeRowTransitions(piece, i, j); double rating = (-4.5 * newmove.landingheight) + (50 * newmove.rowseliminated) + (-3.2 * newmove.rowtrans) + (-9.3 * newmove.coltrans) + (-40 * newmove.holes) + (-3.4 * newmove.wellsums); moves.Add(new move(piece, i, j, newmove.landingheight, newmove.rowtrans, newmove.coltrans, newmove.rowseliminated, newmove.holes, newmove.wellsums, rating)); //print("piece: " + piece + ", rotation: " + i + ", translation: " + j + ", landingheight: " + newmove.landingheight + ", rowseliminated: " + newmove.rowseliminated + ", rowtrans: " + newmove.rowtrans + ", coltrans: " + newmove.coltrans + ", holes: " + newmove.holes + ", wellsums: " + newmove.wellsums + ", rating: " + rating); } } } else if (piece == 3) // O PIECE { if (i != 0) { continue; } for (int j = -5; j < 4; j++) // * { move newmove = new move(); //print("piece: "+piece+", rot: "+i+", tran: "+j); newmove = ComputeRowTransitions(piece, i, j); double rating = (-4.5 * newmove.landingheight) + (50 * newmove.rowseliminated) + (-3.2 * newmove.rowtrans) + (-9.3 * newmove.coltrans) + (-40 * newmove.holes) + (-3.4 * newmove.wellsums); moves.Add(new move(piece, i, j, newmove.landingheight, newmove.rowtrans, newmove.coltrans, newmove.rowseliminated, newmove.holes, newmove.wellsums, rating)); //print("piece: " + piece + ", rotation: " + i + ", translation: " + j + ", landingheight: " + newmove.landingheight + ", rowseliminated: " + newmove.rowseliminated + ", rowtrans: " + newmove.rowtrans + ", coltrans: " + newmove.coltrans + ", holes: " + newmove.holes + ", wellsums: " + newmove.wellsums + ", rating: " + rating); } } else if (piece == 4) // S PIECE { if (i != 0 && i != 1) continue; if (i == 0) // * { for (int j = -5; j < 3; j++) { move newmove = new move(); //print("piece: "+piece+", rot: "+i+", tran: "+j); newmove = ComputeRowTransitions(piece, i, j); double rating = (-4.5 * newmove.landingheight) + (50 * newmove.rowseliminated) + (-3.2 * newmove.rowtrans) + (-9.3 * newmove.coltrans) + (-40 * newmove.holes) + (-3.4 * newmove.wellsums); moves.Add(new move(piece, i, j, newmove.landingheight, newmove.rowtrans, newmove.coltrans, newmove.rowseliminated, newmove.holes, newmove.wellsums, rating)); //print("piece: " + piece + ", rotation: " + i + ", translation: " + j + ", landingheight: " + newmove.landingheight + ", rowseliminated: " + newmove.rowseliminated + ", rowtrans: " + newmove.rowtrans + ", coltrans: " + newmove.coltrans + ", holes: " + newmove.holes + ", wellsums: " + newmove.wellsums + ", rating: " + rating); } } else if (i == 1) // * { for (int j = -6; j < 3; j++) { move newmove = new move(); //print("piece: "+piece+", rot: "+i+", tran: "+j); newmove = ComputeRowTransitions(piece, i, j); double rating = (-4.5 * newmove.landingheight) + (50 * newmove.rowseliminated) + (-3.2 * newmove.rowtrans) + (-9.3 * newmove.coltrans) + (-40 * newmove.holes) + (-3.4 * newmove.wellsums); moves.Add(new move(piece, i, j, newmove.landingheight, newmove.rowtrans, newmove.coltrans, newmove.rowseliminated, newmove.holes, newmove.wellsums, rating)); //print("piece: " + piece + ", rotation: " + i + ", translation: " + j + ", landingheight: " + newmove.landingheight + ", rowseliminated: " + newmove.rowseliminated + ", rowtrans: " + newmove.rowtrans + ", coltrans: " + newmove.coltrans + ", holes: " + newmove.holes + ", wellsums: " + newmove.wellsums + ", rating: " + rating); } } } else if (piece == 5) // T PIECE { if (i == 0) // * { for (int j = -5; j < 3; j++) { move newmove = new move(); //print("piece: "+piece+", rot: "+i+", tran: "+j); newmove = ComputeRowTransitions(piece, i, j); double rating = (-4.5 * newmove.landingheight) + (50 * newmove.rowseliminated) + (-3.2 * newmove.rowtrans) + (-9.3 * newmove.coltrans) + (-40 * newmove.holes) + (-3.4 * newmove.wellsums); moves.Add(new move(piece, i, j, newmove.landingheight, newmove.rowtrans, newmove.coltrans, newmove.rowseliminated, newmove.holes, newmove.wellsums, rating)); //print("piece: " + piece + ", rotation: " + i + ", translation: " + j + ", landingheight: " + newmove.landingheight + ", rowseliminated: " + newmove.rowseliminated + ", rowtrans: " + newmove.rowtrans + ", coltrans: " + newmove.coltrans + ", holes: " + newmove.holes + ", wellsums: " + newmove.wellsums + ", rating: " + rating); } } else if (i == 1) // * { for (int j = -6; j < 3; j++) { move newmove = new move(); //print("piece: "+piece+", rot: "+i+", tran: "+j); newmove = ComputeRowTransitions(piece, i, j); double rating = (-4.5 * newmove.landingheight) + (50 * newmove.rowseliminated) + (-3.2 * newmove.rowtrans) + (-9.3 * newmove.coltrans) + (-40 * newmove.holes) + (-3.4 * newmove.wellsums); moves.Add(new move(piece, i, j, newmove.landingheight, newmove.rowtrans, newmove.coltrans, newmove.rowseliminated, newmove.holes, newmove.wellsums, rating)); //print("piece: " + piece + ", rotation: " + i + ", translation: " + j + ", landingheight: " + newmove.landingheight + ", rowseliminated: " + newmove.rowseliminated + ", rowtrans: " + newmove.rowtrans + ", coltrans: " + newmove.coltrans + ", holes: " + newmove.holes + ", wellsums: " + newmove.wellsums + ", rating: " + rating); } } else if (i == 2) // * { for (int j = -5; j < 3; j++) { move newmove = new move(); //print("piece: "+piece+", rot: "+i+", tran: "+j); newmove = ComputeRowTransitions(piece, i, j); double rating = (-4.5 * newmove.landingheight) + (50 * newmove.rowseliminated) + (-3.2 * newmove.rowtrans) + (-9.3 * newmove.coltrans) + (-40 * newmove.holes) + (-3.4 * newmove.wellsums); moves.Add(new move(piece, i, j, newmove.landingheight, newmove.rowtrans, newmove.coltrans, newmove.rowseliminated, newmove.holes, newmove.wellsums, rating)); //print("piece: " + piece + ", rotation: " + i + ", translation: " + j + ", landingheight: " + newmove.landingheight + ", rowseliminated: " + newmove.rowseliminated + ", rowtrans: " + newmove.rowtrans + ", coltrans: " + newmove.coltrans + ", holes: " + newmove.holes + ", wellsums: " + newmove.wellsums + ", rating: " + rating); } } else if (i == 3) // * { for (int j = -5; j < 3; j++) { move newmove = new move(); //print("piece: "+piece+", rot: "+i+", tran: "+j); newmove = ComputeRowTransitions(piece, i, j); double rating = (-4.5 * newmove.landingheight) + (50 * newmove.rowseliminated) + (-3.2 * newmove.rowtrans) + (-9.3 * newmove.coltrans) + (-40 * newmove.holes) + (-3.4 * newmove.wellsums); moves.Add(new move(piece, i, j, newmove.landingheight, newmove.rowtrans, newmove.coltrans, newmove.rowseliminated, newmove.holes, newmove.wellsums, rating)); //print("piece: " + piece + ", rotation: " + i + ", translation: " + j + ", landingheight: " + newmove.landingheight + ", rowseliminated: " + newmove.rowseliminated + ", rowtrans: " + newmove.rowtrans + ", coltrans: " + newmove.coltrans + ", holes: " + newmove.holes + ", wellsums: " + newmove.wellsums + ", rating: " + rating); } } } else if (piece == 6) // Z PIECE { if (i != 0 && i != 1) continue; if (i == 0) // * { for (int j = -5; j < 3; j++) { move newmove = new move(); //print("piece: "+piece+", rot: "+i+", tran: "+j); newmove = ComputeRowTransitions(piece, i, j); double rating = (-4.5 * newmove.landingheight) + (50 * newmove.rowseliminated) + (-3.2 * newmove.rowtrans) + (-9.3 * newmove.coltrans) + (-40 * newmove.holes) + (-3.4 * newmove.wellsums); moves.Add(new move(piece, i, j, newmove.landingheight, newmove.rowtrans, newmove.coltrans, newmove.rowseliminated, newmove.holes, newmove.wellsums, rating)); //print("piece: " + piece + ", rotation: " + i + ", translation: " + j + ", landingheight: " + newmove.landingheight + ", rowseliminated: " + newmove.rowseliminated + ", rowtrans: " + newmove.rowtrans + ", coltrans: " + newmove.coltrans + ", holes: " + newmove.holes + ", wellsums: " + newmove.wellsums + ", rating: " + rating); } } else if (i == 1) // * { for (int j = -6; j < 3; j++) { move newmove = new move(); //print("piece: "+piece+", rot: "+i+", tran: "+j); newmove = ComputeRowTransitions(piece, i, j); double rating = (-4.5 * newmove.landingheight) + (50 * newmove.rowseliminated) + (-3.2 * newmove.rowtrans) + (-9.3 * newmove.coltrans) + (-40 * newmove.holes) + (-3.4 * newmove.wellsums); moves.Add(new move(piece, i, j, newmove.landingheight, newmove.rowtrans, newmove.coltrans, newmove.rowseliminated, newmove.holes, newmove.wellsums, rating)); //print("piece: " + piece + ", rotation: " + i + ", translation: " + j + ", landingheight: " + newmove.landingheight + ", rowseliminated: " + newmove.rowseliminated + ", rowtrans: " + newmove.rowtrans + ", coltrans: " + newmove.coltrans + ", holes: " + newmove.holes + ", wellsums: " + newmove.wellsums + ", rating: " + rating); } } } } // Get move with highest rating move bestmove; //print("moves.Count: " + moves.Count); moves.Sort((s1, s2) => s1.rating.CompareTo(s2.rating)); bestmove = moves[moves.Count - 1]; return bestmove; }
// Use this for initialization void Start() { player = GameObject.FindGameObjectWithTag(Tags.Player); PlayerController = player.GetComponent <move>(); }
// Update is called once per frame void Update() { if (Group.aimode == false) { // 1P MODE if (Input.GetKeyDown(KeyCode.LeftArrow)) { transform.position += new Vector3(-1, 0, 0); if (isValidGridPos()) updateGrid(); else transform.position += new Vector3(1, 0, 0); } else if (Input.GetKeyDown(KeyCode.RightArrow)) { // Modify position transform.position += new Vector3(1, 0, 0); // See if valid if (isValidGridPos()) // It's valid. Update grid. updateGrid(); else // It's not valid. revert. transform.position += new Vector3(-1, 0, 0); } else if (Input.GetKeyDown(KeyCode.UpArrow)) { int storedCurrent = currentPermutation; if (currentPermutation != 3) currentPermutation++; else currentPermutation = 0; rotateGroup(); //print(transform.name); //transform.Rotate (0, 0, -90); //foreach (Transform child in transform) //{ // //print("Hello"); // child.Rotate(0, 0, 90); //} // See if valid if (isValidGridPos()) // It's valid. Update grid. updateGrid(); else { // It's not valid. revert. if (!kick(storedCurrent, currentPermutation)) { if (currentPermutation != 0) currentPermutation--; else currentPermutation = 3; rotateGroup(); } //transform.Rotate(0, 0, 90); //foreach (Transform child in transform) //{ // child.Rotate(0, 0, -90); //} } } // Fall else if (Input.GetKey(KeyCode.DownArrow) || Time.time - lastFall >= 1) { // Modify position transform.position += new Vector3(0, -1, 0); // See if valid if (isValidGridPos()) { // It's valid. Update grid. updateGrid(); } else { // It's not valid. revert. transform.position += new Vector3(0, 1, 0); // Clear filled horizontal lines Grid.deleteFullRows(); // Spawn next Group FindObjectOfType<Spawner>().spawnNext(); // Disable script enabled = false; } lastFall = Time.time; } } else // AI MODE { /* if(Spawner.nextGroup == 0 || Spawner.nextGroup == 1 || Spawner.nextGroup == 2 || Spawner.nextGroup == 3 || Spawner.nextGroup == 4 || Spawner.nextGroup == 5 || Spawner.nextGroup == 6) { //StartCoroutine(Wait()); move bestmove = 1(Spawner.nextGroup); print("bestmove: " + bestmove.rotation + ", " + bestmove.translation); DoMove(bestmove.rotation, bestmove.translation); } */ if (Spawner.nextGroup == 0 || Spawner.nextGroup == 1 || Spawner.nextGroup == 2 || Spawner.nextGroup == 3 || Spawner.nextGroup == 4 || Spawner.nextGroup == 5 || Spawner.nextGroup == 6) { if (!evaluationdone) { bestmove = ComputeBestMove(Spawner.nextGroup); print("BEST MOVE: piece: " + bestmove.piece + ", rotation: " + bestmove.rotation + ", translation: " + bestmove.translation + ", landingheight: " + bestmove.landingheight + ", rowseliminated: " + bestmove.rowseliminated + ", rowtrans: " + bestmove.rowtrans + ", coltrans: " + bestmove.coltrans + ", holes: " + bestmove.holes + ", wellsums: " + bestmove.wellsums + ", rating: " + bestmove.rating); print("ROWS COMPLETED: " + rowscompleted); rots = bestmove.rotation; trans = bestmove.translation; evaluationdone = true; } if (evaluationdone && Time.time - lastFall >= 0.07) // AI Rotate { if (rots > 0) { /*transform.Rotate(0, 0, -90); foreach (Transform child in transform) { child.Rotate(0, 0, 90); } if (isValidGridPos()) updateGrid(); else { transform.Rotate(0, 0, 90); foreach (Transform child in transform) { child.Rotate(0, 0, -90); } } rots--;*/ int storedCurrent = currentPermutation; if (currentPermutation != 3) currentPermutation++; else currentPermutation = 0; rotateGroup(); if (isValidGridPos()) updateGrid(); else { if (!kick(storedCurrent, currentPermutation)) { if (currentPermutation != 0) currentPermutation--; else currentPermutation = 3; rotateGroup(); } } rots--; lastFall = Time.time; } if (trans != 0) // AI translate { if (trans < 0) { transform.position += new Vector3(-1, 0, 0); if (isValidGridPos()) updateGrid(); else transform.position += new Vector3(1, 0, 0); trans++; lastFall = Time.time; } else { transform.position += new Vector3(1, 0, 0); if (isValidGridPos()) updateGrid(); else transform.position += new Vector3(-1, 0, 0); trans--; lastFall = Time.time; } } if (rots == 0 && trans == 0) // AI Rotated and translated. Ok to drop piece { transform.position += new Vector3(0, -1, 0); if (isValidGridPos()) { updateGrid(); } else { transform.position += new Vector3(0, 1, 0); Grid.deleteFullRows(); FindObjectOfType<Spawner>().spawnNext(); enabled = false; evaluationdone = false; } lastFall = Time.time; } } } else if (Input.GetKeyDown(KeyCode.LeftArrow)) { transform.position += new Vector3(-1, 0, 0); if (isValidGridPos()) updateGrid(); else transform.position += new Vector3(1, 0, 0); } else if (Input.GetKeyDown(KeyCode.RightArrow)) { // Modify position transform.position += new Vector3(1, 0, 0); // See if valid if (isValidGridPos()) // It's valid. Update grid. updateGrid(); else // It's not valid. revert. transform.position += new Vector3(-1, 0, 0); } else if (Input.GetKeyDown(KeyCode.UpArrow)) { int storedCurrent = currentPermutation; if (currentPermutation != 3) currentPermutation++; else currentPermutation = 0; rotateGroup(); //print(transform.name); //transform.Rotate (0, 0, -90); //foreach (Transform child in transform) //{ // //print("Hello"); // child.Rotate(0, 0, 90); //} // See if valid if (isValidGridPos()) // It's valid. Update grid. updateGrid(); else { // It's not valid. revert. if (!kick(storedCurrent, currentPermutation)) { if (currentPermutation != 0) currentPermutation--; else currentPermutation = 3; rotateGroup(); } //transform.Rotate(0, 0, 90); //foreach (Transform child in transform) //{ // child.Rotate(0, 0, -90); //} } } // Fall else if (Input.GetKey(KeyCode.DownArrow) || Time.time - lastFall >= 1) { // Modify position transform.position += new Vector3(0, -1, 0); // See if valid if (isValidGridPos()) { // It's valid. Update grid. updateGrid(); } else { // It's not valid. revert. transform.position += new Vector3(0, 1, 0); // Clear filled horizontal lines Grid.deleteFullRows(); // Spawn next Group FindObjectOfType<Spawner>().spawnNext(); // Disable script enabled = false; } lastFall = Time.time; } } }
/// <summary> /// Вычисляет возможные ходы для данного класса /// </summary> /// <param name="z"> начальная координата по z</param> /// <param name="x"> начальная координата по x</param> public void PossibleMoves(int z, int x) // 28 возможных ходов { Core_object = GameObject.Find("Core"); Core scriptToAccess = Core_object.GetComponent <Core>(); int for_z; int for_x; for_z = z; for_x = x; int myColor = 0; /* if (scriptToAccess.State == 1) * { * * myColor = 1; * } * else * { * myColor = 0; * }*/ for (int i = 1; i < 8; i++) // Вверх { move mv = new move(); mv.x = x; mv.z = z + i; if (mv.x >= 0 & mv.x < 8 & mv.z >= 0 & mv.z < 8) // строчка для ограничения хода в границах 8x8 { if (Can_add) { if (scriptToAccess.board[mv.z, mv.x].figure_name != "empty") { Can_add = false; if (scriptToAccess.board[scriptToAccess.second_z, scriptToAccess.second_x].colors_of_figure != myColor & scriptToAccess.board[scriptToAccess.second_z, scriptToAccess.second_x].figure_name != "empty") { // добавляем ели цвет не наш P_Moves_Up.Add(mv); } } } if (Can_add) { P_Moves_Up.Add(mv); } } } z = for_z; x = for_x; Can_add = true; for (int i = 1; i < 8; i++) // Вниз { move mv = new move(); mv.x = x; mv.z = z - i; if (mv.x >= 0 & mv.x < 8 & mv.z >= 0 & mv.z < 8) // строчка для ограничения хода в границах 8x8 { if (Can_add) { if (scriptToAccess.board[mv.z, mv.x].figure_name != "empty") { Can_add = false; if (scriptToAccess.board[scriptToAccess.second_z, scriptToAccess.second_x].colors_of_figure != myColor & scriptToAccess.board[scriptToAccess.second_z, scriptToAccess.second_x].figure_name != "empty") { // добавляем ели цвет не наш P_Moves_Down.Add(mv); } } } if (Can_add) { P_Moves_Down.Add(mv); } } } z = for_z; x = for_x; Can_add = true; for (int i = 1; i < 8; i++) // Влево { move mv = new move(); mv.x = x - i; mv.z = z; if (mv.x >= 0 & mv.x < 8 & mv.z >= 0 & mv.z < 8) // строчка для ограничения хода в границах 8x8 { if (Can_add) { if (scriptToAccess.board[mv.z, mv.x].figure_name != "empty") { Can_add = false; if (scriptToAccess.board[scriptToAccess.second_z, scriptToAccess.second_x].colors_of_figure != myColor & scriptToAccess.board[scriptToAccess.second_z, scriptToAccess.second_x].figure_name != "empty") { // добавляем ели цвет не наш P_Moves_Left.Add(mv); } } } if (Can_add) { P_Moves_Left.Add(mv); } } } z = for_z; x = for_x; Can_add = true; for (int i = 1; i < 8; i++) // Вправо { move mv = new move(); mv.x = x + i; mv.z = z; if (mv.x >= 0 & mv.x < 8 & mv.z >= 0 & mv.z < 8) // строчка для ограничения хода в границах 8x8 { if (Can_add) { if (scriptToAccess.board[mv.z, mv.x].figure_name != "empty") { Can_add = false; if (scriptToAccess.board[scriptToAccess.second_z, scriptToAccess.second_x].colors_of_figure != myColor & scriptToAccess.board[scriptToAccess.second_z, scriptToAccess.second_x].figure_name != "empty") { // добавляем ели цвет не наш P_Moves_Right.Add(mv); } } } if (Can_add) { P_Moves_Right.Add(mv); } } } z = for_z; x = for_x; Can_add = true; for (int i = 0; i < P_Moves_Up.Count; i++) { All_moves.Add(P_Moves_Up[i]); } for (int i = 0; i < P_Moves_Down.Count; i++) { All_moves.Add(P_Moves_Down[i]); } for (int i = 0; i < P_Moves_Left.Count; i++) { All_moves.Add(P_Moves_Left[i]); } for (int i = 0; i < P_Moves_Right.Count; i++) { All_moves.Add(P_Moves_Right[i]); } for (int i = 0; i < All_moves.Count; i++) { All_moves[i].started_x = for_x; All_moves[i].started_z = for_z; Debug.Log("***********"); Debug.Log(All_moves[i].started_z); Debug.Log(All_moves[i].started_x); Debug.Log("***********"); } }
// Start is called before the first frame update private void Awake() { move = GetComponent <move>();//进行角色方向控制时就调用move中的函数 animator = GetComponent <Animator>(); }
public Node(move move) { this.value = move; }
public Node(move move) { this.value = move; }
static void Main(string[] args) { move mymove = new move(); move computermove = new move(); int[,] gameBoard = new int[9, 9]; string myDirection = "h"; string compDirection = "v"; int round = 1; mymove.OldNumber = 1; mymove.MyPoints = 0; computermove.CompChoice = 1; computermove.OldNumber = 1; computermove.CompPoints = 0; bool keepChecking = true; while (true) { while (keepChecking) { try { PrintMenu(); int action1 = int.Parse(Console.ReadLine()); if (action1 < 0 || action1 > 1) { throw new ArgumentException(); } else { switch (action1) { case 0: Console.WriteLine("Shutting down ..."); Environment.Exit(0); break; case 1: Console.WriteLine("choose your direction: v-vertical, h-horizontal"); myDirection = Console.ReadLine(); if (myDirection == "v") { compDirection = "h"; keepChecking = false; board.boardGeneration(gameBoard); break; } else if (myDirection == "h") { compDirection = "v"; keepChecking = false; board.boardGeneration(gameBoard); } else { throw new ArgumentException(); } break; } } } catch (Exception) { Console.WriteLine("error. use number 0 or 1 and then use letter h or v"); continue; } } //game do { if (computermove.Endcheck1(compDirection, gameBoard) == 0 || mymove.Endcheck1(myDirection, gameBoard) == 0) { Console.WriteLine("end of the game. your points: {0}, computer points: {1}", mymove.MyPoints, computermove.CompPoints); if (mymove.MyPoints > computermove.CompPoints) { Console.WriteLine("you won!"); } else { Console.WriteLine("2nd place"); } break; } if (round % 2 == 1) { Console.Clear(); board.ShowBoard(gameBoard); Console.WriteLine("your points: {0}, computer points: {1}", mymove.MyPoints, computermove.CompPoints); Console.WriteLine("computer chosed: {0}", computermove.OldNumber); PrintGameMenu(myDirection, mymove.OldNumber); mymove.MyMove(myDirection, gameBoard); Console.WriteLine("koniec rundy: {0}", round); Console.WriteLine("{0}", mymove.OldNumber); computermove.OldNumber = mymove.OldNumber; round++; } else { Console.Clear(); board.ShowBoard(gameBoard); Console.WriteLine("your points: {0}, computer points: {1}", mymove.MyPoints, computermove.CompPoints); Console.Write("computer chooses: "); System.Threading.Thread.Sleep(1000); computermove.CompMove(compDirection, gameBoard); Console.WriteLine("{0}", computermove.OldNumber); mymove.OldNumber = computermove.OldNumber; round++; System.Threading.Thread.Sleep(3000); } }while (true); } }
void Start() { pointsScript = GameObject.Find("GameManager").GetComponent <Pontuation>(); powerScript = GameObject.Find("GameManager").GetComponent <PowerManager>(); moveScript = GameObject.Find("Spaceship Galaga white").GetComponent <move>(); }
//开始移动的时候使用 public virtual void OnStartMove(move theMove) { }
public move ComputeRowTransitions(int piece, int rotation, int translation) { move thismove = new move(); int rowtrans = 0, coltrans = 0, holes = 0, wellsums = 0; bool lastfilled = true; bool valid = true; int steps = 0; if (rotation > 0) // 1. Rotate piece { for (int i = 0; i < rotation; i++) { //transform.Rotate(0, 0, -90); int storedCurrent = currentPermutation; if (currentPermutation != 3) currentPermutation++; else currentPermutation = 0; rotateGroup(); if (isValidGridPos()) updateGrid(); else { if (!kick(storedCurrent, currentPermutation)) { if (currentPermutation != 0) currentPermutation--; else currentPermutation = 3; rotateGroup(); } } } } foreach (Transform child in transform) { Vector2 v = Grid.roundVec2(child.position); //print("PRE " + v.x + ", " + v.y); } while (valid) // Get number of steps to fall { foreach (Transform child in transform) { Vector2 v = Grid.roundVec2(child.position); v.x += translation; // v.y -= steps; if ((!Grid.insideBorder(v)) || (Grid.grid[(int)v.x, (int)v.y] != null && Grid.grid[(int)v.x, (int)v.y].parent != transform)) { //child.Rotate(0, 0, -90); valid = false; break; } } if (valid) steps++; else break; } steps--; foreach (Transform child in transform) // Translate and drop piece { Vector2 v = Grid.roundVec2(child.position); v.x += translation; v.y -= steps; //print("DROPPED: "+v.x + "," + v.y); try { Grid.grid[(int)v.x, (int)v.y] = child; } catch (IndexOutOfRangeException e) { Debug.Log("GAME OVER"); print("ROWS COMPLETED: " + rowscompleted); Destroy(gameObject); } // } /* Now that piece is in place, run computations */ int rowseliminated = 0; // Compute number of rows eliminated for (int i = 0; i < 15; i++) { /* bool fullrow = true; for (int j = 0; j < 10; j++) { if (Grid.grid[j, i] == null) fullrow = false; } if (fullrow) rowseliminated++; */ if (Grid.isRowFull(i)) rowseliminated++; } thismove.rowseliminated = rowseliminated; for (int i = 0; i < 15; i++) // Compute number of row transitions { bool emptyrow = true; bool fullrow = true; lastfilled = true; int thisrow = 0; for (int j = 0; j < 10; j++) // Skip row if full { if (Grid.grid[j, i] == null) fullrow = false; } if (fullrow) continue; for (int k = 0; k < 10; k++) // Skip row if empty { if (Grid.grid[k, i] != null) emptyrow = false; } if (emptyrow) break; for (int j = 0; j < 10; j++) { if (lastfilled) { if (Grid.grid[j, i] == null) { thisrow++; lastfilled = false; } else { lastfilled = true; } } else { if (Grid.grid[j, i] == null) { lastfilled = false; } else { thisrow++; lastfilled = true; } } if (thisrow > 0 && j == 9 && Grid.grid[j, i] == null) thisrow++; } //print("row " + i + ": " + thisrow); rowtrans += thisrow; } thismove.rowtrans = rowtrans; //print("rowtrans: " + rowtrans); // 5. Compute number of column transitions for (int i = 0; i < 10; i++) { bool emptycol = true; lastfilled = true; int thiscol = 0; for (int k = 0; k < 15; k++) { if (Grid.grid[i, k] != null) emptycol = false; } if (emptycol) { thiscol++; continue; } for (int j = 0; j < 15; j++) { if (lastfilled) { if (Grid.grid[i, j] == null) { thiscol++; lastfilled = false; } else { lastfilled = true; } } else { if (Grid.grid[i, j] == null) { lastfilled = false; } else { thiscol++; lastfilled = true; } } } //print("col " + i + ": " + thiscol); coltrans += thiscol; } thismove.coltrans = coltrans; bool hol = false; // 6. Compute number of holes for (int i = 0; i < 10; i++) { hol = false; for (int j = 0; j < 18; j++) { //print("i: " + i + " j: " + j); //if (Grid.grid[i, j] == null) hol = true; //if (hol = true && Grid.grid[i, j] != null) holes++; if (Grid.isRowFull(i)) continue; if (Grid.grid[i, j] == null && Grid.grid[i, j + 1] != null) holes++; } hol = false; } thismove.holes = holes; // 7. Compute well sums for (int i = 0; i < 10; i++) { int thiscol = 0; bool well = false; lastfilled = true; for (int j = 0; j < 15; j++) { if (lastfilled) { if (Grid.grid[i, j] == null) { if (i == 0) // Leftmost column { if (Grid.grid[i + 1, j] != null) { if (Grid.grid[i, j + 1] == null) { thiscol++; well = true; lastfilled = false; } else { well = false; lastfilled = false; } } else { if (Grid.grid[i, j + 1] == null) { well = true; lastfilled = false; } else { well = false; lastfilled = false; } } } else if (i == 9) // Rightmost column { if (Grid.grid[i - 1, j] != null) { if (Grid.grid[i, j + 1] == null) { thiscol++; well = true; lastfilled = false; } else { well = false; lastfilled = false; } } else { if (Grid.grid[i, j + 1] == null) { well = true; lastfilled = false; } else { well = false; lastfilled = false; } } } else // In between leftmost and rightmost columns { if (Grid.grid[i - 1, j] != null && Grid.grid[i + 1, j] != null) { if (Grid.grid[i, j + 1] == null) { thiscol++; well = true; lastfilled = false; } else { well = false; lastfilled = false; } } else { if (Grid.grid[i, j + 1] == null) { well = true; lastfilled = false; } else { well = false; lastfilled = false; } } } } else { well = false; lastfilled = true; } } else { if (Grid.grid[i, j] == null) { if (i == 0) // Leftmost column { if (Grid.grid[i + 1, j] != null) { if (Grid.grid[i, j + 1] == null) { thiscol++; well = true; lastfilled = false; } else { well = false; lastfilled = false; } } else { if (Grid.grid[i, j + 1] == null) { well = true; lastfilled = false; } else { well = false; lastfilled = false; } } } else if (i == 9) // Rightmost column { if (Grid.grid[i - 1, j] != null) { if (Grid.grid[i, j + 1] == null) { thiscol++; well = true; lastfilled = false; } else { well = false; lastfilled = false; } } else { if (Grid.grid[i, j + 1] == null) { well = true; lastfilled = false; } else { well = false; lastfilled = false; } } } else // In between leftmost and rightmost columns { if (Grid.grid[i - 1, j] != null && Grid.grid[i + 1, j] != null) { if (Grid.grid[i, j + 1] == null) { thiscol++; well = true; lastfilled = false; } else { well = false; lastfilled = false; } } else { if (Grid.grid[i, j + 1] == null) { well = true; lastfilled = false; } else { well = false; lastfilled = false; } } } } else { well = false; lastfilled = true; } } } if (well) wellsums += thiscol; //print("col" + i + ": " + thiscol); } thismove.wellsums = wellsums; // Get landing height int currentheight = 14 - steps; int landingheight = 0; if (piece == 0) // I { if (rotation == 0 || rotation == 2) landingheight = currentheight + 1; else landingheight = currentheight + 2; } else if (piece == 1 || piece == 2) // J, L { if (rotation == 0 || rotation == 2) landingheight = currentheight + 2; else landingheight = currentheight + 2; } else if (piece == 3) // O { landingheight = currentheight + 2; } else if (piece == 4) // S { if (rotation == 0 || rotation == 2) landingheight = currentheight + 2; else landingheight = currentheight + 2; } else if (piece == 5) // T { if (rotation == 0 || rotation == 2) landingheight = currentheight + 2; else landingheight = currentheight + 4; } else if (piece == 6) // Z { if (rotation == 0 || rotation == 2) landingheight = currentheight + 1; else landingheight = currentheight + 1; } thismove.landingheight = landingheight; // Remove piece foreach (Transform child in transform) { Vector2 v = Grid.roundVec2(child.position); v.x += translation; v.y -= steps; try { Grid.grid[(int)v.x, (int)v.y] = null; } catch (IndexOutOfRangeException e) { print(e.Message); } } // Rotate transform back to initial state if rotated if (rotation == 1 || rotation == 3) { //transform.Rotate(0, 0, -90); for (int i = 0; i < 3; i++) { int storedCurrent = currentPermutation; if (currentPermutation != 3) currentPermutation++; else currentPermutation = 0; rotateGroup(); if (isValidGridPos()) updateGrid(); else { if (!kick(storedCurrent, currentPermutation)) { if (currentPermutation != 0) currentPermutation--; else currentPermutation = 3; rotateGroup(); } } } } // print("DONE piece: " + thismove.piece + ", rotation: " + thismove.rotation + ", translation: " + thismove.translation + ", landingheight: " + thismove.landingheight + ", rowseliminated: " + thismove.rowseliminated + ", rowtrans: " + thismove.rowtrans + ", coltrans: " + thismove.coltrans + ", holes: " + thismove.holes + ", wellsums: " + thismove.wellsums + ", rating: " + thismove.rating); return thismove; }
public override void ExtraUpdate2(move theMove, float value) { theMove.theMoveController.Move(theMove.transform.rotation * new Vector3(0f, 0f, value * 2.25f)); }
public void Move(move pMove) { //legal move Coordinate newPosition; switch (pMove) { case move.LEFT: newPosition = new Coordinate(mPacMansPosition.x - 1, mPacMansPosition.y); break; case move.RIGHT: newPosition = new Coordinate(mPacMansPosition.x + 1, mPacMansPosition.y); break; case move.UP: newPosition = new Coordinate(mPacMansPosition.x, mPacMansPosition.y - 1); break; default: newPosition = new Coordinate(mPacMansPosition.x, mPacMansPosition.y + 1); break; } if (mBoard.GetState(newPosition) == BoardStates.WALL) { // dont move him } else if (mBoard.GetState(newPosition) == BoardStates.TUNNEL) { //find the other end of the tunnel newPosition = new Coordinate(15, 15); mPacMansPosition = newPosition; mBoard.Eat(newPosition); } else { mPacMansPosition = newPosition; mBoard.Eat(newPosition); } if (mPacMansPosition.toString().Equals(mMonsterPosition1.toString())) { mGameOver = true; mWon = false; } //check to see if anymore pills are on the board if (mBoard.AreAllPillsEaten()) { mGameOver = true; mWon = true; } mMonsterPosition1 = MoveMonster(mMonsterPosition1); mMonsterPosition2 = MoveMonster(mMonsterPosition2); mMonsterPosition3 = MoveMonster(mMonsterPosition3); //check all of the monster positions if (mPacMansPosition.toString().Equals(mMonsterPosition1.toString()) || mPacMansPosition.toString().Equals(mMonsterPosition2.toString()) || mPacMansPosition.toString().Equals(mMonsterPosition3.toString())) { mGameOver = true; mWon = false; } //win/loose }
//结束移动的时候使用 public virtual void OnEndMove(move theMove) { }
void Update() { this.transform.position = new Vector3(this.transform.position.x, 0.5f, this.transform.position.z); float DistanceToTarget = 0.0f; //目標点との距離 Quaternion TargetRotation; //目標手への方向 DistanceToTarget = Vector3.Distance(this.transform.position, TargetPosition); //いじめられっ子への距離を計算 OldPosition = this.transform.position; rigid.velocity = Vector3.zero; rigid.angularVelocity = Vector3.zero; if (izimepower >= 0) { switch (move_mode) { case move.loitering: //徘徊 //いじめっ子と目標点との距離を求める DistanceToTarget = Vector3.SqrMagnitude(transform.position - TargetPosition); //目標点との距離が近ければ次の目標点を決める if (DistanceToTarget < CangeTargetDistance) { TargetPosition = GetPosition(); } //目標点の方を向く TargetRotation = Quaternion.LookRotation(TargetPosition - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, TargetRotation, Time.deltaTime * 10); //前に進む transform.Translate(Vector3.forward * Speed * Time.deltaTime); time2--; //いじめられっ子との距離を計算し、近かったらいじめられっ子を目標点にして近寄る for (int i = 0; i < izimerarekko.Length; i++) { DistanceToTarget = Vector3.Distance(this.transform.position, izimerarekko[i].transform.position); if (DistanceToTarget <= 10.0f && time2 <= 0 && 2.0f < DistanceToTarget) { TargetPosition = izimerarekko[i].transform.position; time1 = 0; move_mode = move.izimerarekko;//いじめられっ子へ向かう break; } } break; case move.izimerarekko: //いじめられっ子へ向かう //目標点の方を向く TargetRotation = Quaternion.LookRotation(TargetPosition - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, TargetRotation, Time.deltaTime * 10); //前に進む transform.Translate(Vector3.forward * Speed * Time.deltaTime); //いじめられっ子に近づきすぎたらそれ以上すすめないようにする if (DistanceToTarget <= 5.0f) { this.transform.position = OldPosition; } if (time1 >= 600) { time2 = 600; TargetPosition = GetPosition(); move_mode = move.loitering;//徘徊 break; } break; default: break; } time1++; } else { Destroy(this); } }
public void addPlayerData(GameObject player,move Move,Vector2 position) { players.Add (player); player.GetComponent<playerNetworkMover> ().playerIndex = players.Count - 1; playerMove.Add (Move); print ("current position: " + position); playerPosition.Add (position); }
move step(List <String> BotCard, ClientRoomModel BotaRoom, List <String> PlayerCard, bool flag, int kote) { ClientRoomModel Room = new ClientRoomModel(); List <String> RoomBotCard = new List <string>(); List <String> RoomPlayerCard = new List <string>(); List <String> NewRoomBotCard = new List <string>(); List <String> NewRoomPlayerCard = new List <string>(); //Копирвание карт бота на текущую рекурсию for (int i = 0; i < BotCard.Count; i++) { RoomBotCard.Add(BotCard[i]); } //Копирование карт игрока на текущую рекурсию for (int i = 0; i < PlayerCard.Count; i++) { RoomPlayerCard.Add(PlayerCard[i]); } Room.delayedRound = BotaRoom.delayedRound; Room.firstPLayerActiveCard = BotaRoom.firstPLayerActiveCard; Room.id = BotaRoom.id; Room.idFirstPlayerCad = BotaRoom.idFirstPlayerCad; Room.idSecondPlayerCad = BotaRoom.idSecondPlayerCad; Room.name = BotaRoom.name; Room.nameFirstPlayer = BotaRoom.nameFirstPlayer; Room.nameGod = BotaRoom.nameGod; Room.nameSecondPlayer = BotaRoom.nameSecondPlayer; Room.numberPlayer = BotaRoom.numberPlayer; Room.numberRound = BotaRoom.numberRound; Room.P1bonusGeneral = BotaRoom.P1bonusGeneral; Room.P1bonusLegate = BotaRoom.P1bonusLegate; Room.P1bonusSpook = BotaRoom.P1bonusSpook; Room.P2bonusGeneral = BotaRoom.P2bonusGeneral; Room.P2bonusLegate = BotaRoom.P2bonusLegate; Room.P2bonusSpook = BotaRoom.P2bonusSpook; Room.password = BotaRoom.password; Room.secondPLayerActiveCard = BotaRoom.secondPLayerActiveCard; Room.vPointFerstPlayer = BotaRoom.vPointFerstPlayer; Room.vPointSecondPlayer = BotaRoom.vPointSecondPlayer; //Опеределение конца игры ( Выход из рекурсии) if (flag == true) { switch (BotWinner(Room, kote)) { case 4: return(new move { score = -10 }); case 3: return(new move { score = 10 }); case 5: return(new move { score = 0 }); } } // Создание массива объектов move List <move> moves = new List <move>(); //Цикл до конца игры for (int i = 0; i < RoomBotCard.Count; i++) { move move = new move(); move.index = Int32.Parse(RoomBotCard[i]); for (int j = 0; j < RoomPlayerCard.Count; j++) { Room.firstPLayerActiveCard = true; Room.secondPLayerActiveCard = true; Room.idFirstPlayerCad = Int32.Parse(RoomPlayerCard[j]); Room.idSecondPlayerCad = move.index; NewRoomBotCard.RemoveRange(0, NewRoomBotCard.Count); NewRoomPlayerCard.RemoveRange(0, NewRoomPlayerCard.Count); //Создание новой колоды бота для отправки for (int k = 0; k < RoomBotCard.Count; k++) { if (RoomBotCard[k] == Room.idSecondPlayerCad.ToString()) { continue; } NewRoomBotCard.Add(RoomBotCard[k]); } //Создание новой колоды игрока для отправки for (int k = 0; k < RoomPlayerCard.Count; k++) { if (RoomPlayerCard[k] == Room.idFirstPlayerCad.ToString()) { continue; } NewRoomPlayerCard.Add(RoomPlayerCard[k]); } int kotik = BotRoom.numberRound + 2; if (kotik >= 8) { kotik = 8; } var result = step(NewRoomBotCard, Room, NewRoomPlayerCard, true, kotik); move.score = move.score + result.score; } moves.Add(move); } int bestMove = 0; var bestScore = -10000; for (var i = 0; i < moves.Count; i++) { if (moves[i].score > bestScore) { bestScore = moves[i].score; bestMove = i; } } return(moves[bestMove]); }
// Use this for initialization void Start() { player = GameObject.FindGameObjectWithTag(Tags.Player); PlayerController = player.GetComponent<move>(); }
move makeRandomMove() { move rm = new move (); rm.pos = validMoves[Random.Range (0, validMoves.Count-1)]; rm.rank = 1; return rm; }
public void setMove(move) {
//技能额外计算(二段动作) public virtual void ExtraUpdate2(move theMove, float value) { }
void Awake() { moveScript = GetComponent <move>(); healthScript = GetComponent <health>(); }
public lineAndScore(move[] newLine, int newFinalScore, BoardScorer scorer) { line = newLine; finalScore = newFinalScore; _scorer = scorer; }
//二段操作的收尾都动作 public virtual void ExtraUpdate2End(move theMove) { }
public void setTarget(GameObject inObj, move inButScript) { // Debug.Log ("New target."); target = inObj; butScript = inButScript; }
public override void ExtraUpdate2(move theMove, float value) { theMove.theMoveController.Move(new Vector3(0f, value, 0f)); OnMove(theMove.theMoveController, 2f); }
// Use this for initialization void Start() { player = GameObject.FindGameObjectWithTag (Tags.Player); movecs = player.GetComponent<move> (); greenLight = GetComponent<Light> (); }
void Awake() { moveScript = GetComponent<move>(); healthScript = GetComponent<health>(); }