public void NotifyTurn() { if (OnTurn != null) { OnTurn.Invoke(this, new TurnNotificationArgs(this)); } }
/// <summary> /// OnPlayerPlayChess回调 /// </summary> /// <param name="obj"></param> private void ChessBoard_OnPlayerPlayChess(Vector2Int index, ChessState chessState) { //TODO判定是否是否胜利 if (JudeWinOrContinue(index, chessState) == true) { Debug.Log(chessState + "Win"); if (OnWin != null) { OnWin.Invoke();//执行结束的事件 剔除棋盘格子的射线事件 } UIManager.Instance.chessState = chessState; UIManager.Instance.gameStatus = GameStatus.Over; return; } playerIndex++;//增加回合 #region 轮询逻辑 if (OnTurn != null) { OnTurn.Invoke(playerIndex);//暂停事件 } #endregion //TODO增加栈 来储存10步内的悔棋。 }
public void OnClickButton(string message) { if (message == "move") { if (OnAttack != null) { OnMove.Invoke(Actor); } } else if (message == "attack") { if (OnAttack != null) { OnAttack.Invoke(Actor); } } else if (message == "turn") { if (OnTurn != null) { OnTurn.Invoke(Actor); } } else if (message == "finish") { if (OnFinish != null) { OnFinish.Invoke(Actor); } } }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hashCode = 41; // Suitable nullity checks etc, of course :) hashCode = hashCode * 59 + EnergyCubes.GetHashCode(); hashCode = hashCode * 59 + Health.GetHashCode(); hashCode = hashCode * 59 + Active.GetHashCode(); hashCode = hashCode * 59 + Virtual.GetHashCode(); hashCode = hashCode * 59 + Priority.GetHashCode(); hashCode = hashCode * 59 + OnTurn.GetHashCode(); hashCode = hashCode * 59 + IsMine.GetHashCode(); hashCode = hashCode * 59 + HandCards.GetHashCode(); hashCode = hashCode * 59 + Attitude.GetHashCode(); hashCode = hashCode * 59 + Type.GetHashCode(); return(hashCode); } }
private void Turn(CommandTypes type) { if (Type != type) { // Send command to server OnTurn?.Invoke(type); } }
private void MakeTurnInner(Position position, Player player) { GameField.Turn(position.Column, position.Row, WhoseTurn.Id); OnTurn?.Invoke(this, new TurnEventArgs { Column = position.Column, Row = position.Row, Player = player }); }
/// <summary> /// Returns true if RobotInfoAllOf instances are equal /// </summary> /// <param name="other">Instance of RobotInfoAllOf to be compared</param> /// <returns>Boolean</returns> public bool Equals(RobotInfoAllOf other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( EnergyCubes == other.EnergyCubes || EnergyCubes.Equals(other.EnergyCubes) ) && ( Health == other.Health || Health.Equals(other.Health) ) && ( Active == other.Active || Active.Equals(other.Active) ) && ( Virtual == other.Virtual || Virtual.Equals(other.Virtual) ) && ( Priority == other.Priority || Priority.Equals(other.Priority) ) && ( OnTurn == other.OnTurn || OnTurn.Equals(other.OnTurn) ) && ( IsMine == other.IsMine || IsMine.Equals(other.IsMine) ) && ( HandCards == other.HandCards || HandCards.Equals(other.HandCards) ) && ( Attitude == other.Attitude || Attitude.Equals(other.Attitude) ) && ( Type == other.Type || Type.Equals(other.Type) )); }
public Resulter MakeTurn(Movement move) { var resulter = map[playerPosition.X, playerPosition.Y].OnCell.Act(this, playerPosition, move); if (resulter.IsSuccess) { if (resulter.InnerRequest != null) { MoveObject(resulter.InnerRequest.OldPosition, resulter.InnerRequest.NewPosition); } this.playerPosition = resulter.NewPosition; MoveObject(resulter.OldPosition, resulter.NewPosition); turnsHistory.Push(resulter); OnTurn?.Invoke(); } return(resulter); }
private void Update() { if (isStunned) { ChangeState(5); return; } if (isGrounded) { if (Mathf.Abs(movementAxes.x) > 0.1f) { ChangeState(1); } else if (Mathf.Abs(movementAxes.x) < 0.1f) { ChangeState(0); } } if (isOnLedge) { ChangeState(4); } if (!isOnLedge && !isWallSliding) { if (isFacingRight && movementAxes.x < -0.1f) { isFacingRight = false; OnTurn?.Invoke(); } if (!isFacingRight && movementAxes.x > 0.1f) { isFacingRight = true; OnTurn?.Invoke(); } } }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hashCode = 41; // Suitable nullity checks etc, of course :) hashCode = hashCode * 59 + Id.GetHashCode(); if (ControlledEntities != null) { hashCode = hashCode * 59 + ControlledEntities.GetHashCode(); } hashCode = hashCode * 59 + OnTurn.GetHashCode(); hashCode = hashCode * 59 + Active.GetHashCode(); if (DisplayName != null) { hashCode = hashCode * 59 + DisplayName.GetHashCode(); } return(hashCode); } }
/// <summary> /// Returns true if Player instances are equal /// </summary> /// <param name="other">Instance of Player to be compared</param> /// <returns>Boolean</returns> public bool Equals(Player other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Id == other.Id || Id.Equals(other.Id) ) && ( ControlledEntities == other.ControlledEntities || ControlledEntities != null && other.ControlledEntities != null && ControlledEntities.SequenceEqual(other.ControlledEntities) ) && ( OnTurn == other.OnTurn || OnTurn.Equals(other.OnTurn) ) && ( Active == other.Active || Active.Equals(other.Active) ) && ( DisplayName == other.DisplayName || DisplayName != null && DisplayName.Equals(other.DisplayName) )); }
public void OnTurnAction() { OnTurn?.Invoke(this, new EventArgs()); }
static Move Minimax(ref Tile[][] mockBoard, Point[] humanFigures, Point[] aiFigures, OnTurn onTurn, int treeDepth) { //TODO: kultiviši malo ovu funkciju, prevelika je Point[] figures = (onTurn == OnTurn.AIPlayer ? aiFigures : humanFigures); Point[] enemyFigures = (onTurn == OnTurn.AIPlayer ? humanFigures : aiFigures); List <Move> moves = new List <Move>(); for (int i = 0; i < figures.Length; i++) //move deo poteza { Point figure = figures[i]; Point prevPos = new Point(figure.row, figure.col); Tile currentTile = mockBoard[figure.row][figure.col]; Point[] neighbouringTiles = GetNeighbouringTiles(mockBoard, figure.row, figure.col); for (int j = 0; j < neighbouringTiles.Length; j++) { Point indices = neighbouringTiles[j]; Tile neighbouringTile = mockBoard[indices.row][indices.col]; if (currentTile.CanMoveOnTo(neighbouringTile) == true) { //Move on to tile mockBoard[figure.row][figure.col].isOccupied = false; mockBoard[indices.row][indices.col].isOccupied = true; figure.row = indices.row; figure.col = indices.col; Tile buildCurrentTile = mockBoard[figure.row][figure.col]; Point[] buildNeighbouringTiles = GetNeighbouringTiles(mockBoard, figure.row, figure.col); for (int k = 0; k < buildNeighbouringTiles.Length; k++) { Point buildIndices = buildNeighbouringTiles[k]; Tile buildNeighbouringTile = mockBoard[buildIndices.row][buildIndices.col]; if (buildCurrentTile.CanBuildOn(buildNeighbouringTile) == true) { Move move = new Move(i, indices, buildIndices); //Build on tile buildNeighbouringTile.currentLevel++; minimaxDuration = DateTime.Now.Ticks * 100 - minimaxStart; if (minimaxDuration > MaxMinimaxDuration) { move.treeDepth = treeDepth; move.result = Evaluate(ref mockBoard, aiFigures, humanFigures, indices, buildIndices); } else if (IsGameOver(mockBoard, enemyFigures) == true || mockBoard[figure.row][figure.col].currentLevel >= 3) { move.treeDepth = treeDepth; move.result = (onTurn == OnTurn.AIPlayer ? Int32.MaxValue : Int32.MinValue); //trebao bih da imam u vidu treeDepth //Reverse build buildNeighbouringTile.currentLevel--; //Reverse move mockBoard[figure.row][figure.col].isOccupied = false; figure.row = prevPos.row; figure.col = prevPos.col; mockBoard[figure.row][figure.col].isOccupied = true; return(move); } else { Move tempMove = Minimax(ref mockBoard, humanFigures, aiFigures, onTurn == OnTurn.AIPlayer ? OnTurn.HumanPlayer : OnTurn.AIPlayer, treeDepth + 1); move.treeDepth = tempMove.treeDepth; move.result = tempMove.result; } moves.Add(move); //Reverse build buildNeighbouringTile.currentLevel--; //uslov za break if (minimaxDuration > MaxMinimaxDuration) { break; } } } //Reverse move mockBoard[figure.row][figure.col].isOccupied = false; figure.row = prevPos.row; figure.col = prevPos.col; mockBoard[figure.row][figure.col].isOccupied = true; //uslov za break if (minimaxDuration > MaxMinimaxDuration) { break; } } } } //ovde treba da se prodje kroz listu poteza i da se odabere najbolji u zavisnosti od toga da li je trenutno na potezu AI ili human Move bestMove = moves[0]; foreach (Move move in moves) { //tražim if (onTurn == OnTurn.AIPlayer) { //tražim move sa maksimalnim result-om if (move.result > bestMove.result) { bestMove = move; } else if (move.result == bestMove.result && move.treeDepth < bestMove.treeDepth) { bestMove = move; } } else if (onTurn == OnTurn.HumanPlayer) { //tražim move sa minimalnim result-om if (move.result < bestMove.result) { bestMove = move; } else if (move.result == bestMove.result && move.treeDepth < bestMove.treeDepth) { bestMove = move; } } } return(bestMove); }
/// <summary> /// Returns true if RobotInfo instances are equal /// </summary> /// <param name="other">Instance of RobotInfo to be compared</param> /// <returns>Boolean</returns> public bool Equals(RobotInfo other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Direction == other.Direction || Direction.Equals(other.Direction) ) && ( Name == other.Name || Name != null && Name.Equals(other.Name) ) && ( Id == other.Id || Id.Equals(other.Id) ) && ( Location == other.Location || Location != null && Location.Equals(other.Location) ) && ( EnergyCubes == other.EnergyCubes || EnergyCubes.Equals(other.EnergyCubes) ) && ( Health == other.Health || Health.Equals(other.Health) ) && ( Active == other.Active || Active.Equals(other.Active) ) && ( Virtual == other.Virtual || Virtual.Equals(other.Virtual) ) && ( Priority == other.Priority || Priority.Equals(other.Priority) ) && ( OnTurn == other.OnTurn || OnTurn.Equals(other.OnTurn) ) && ( IsMine == other.IsMine || IsMine.Equals(other.IsMine) ) && ( HandCards == other.HandCards || HandCards.Equals(other.HandCards) ) && ( Attitude == other.Attitude || Attitude.Equals(other.Attitude) ) && ( Type == other.Type || Type.Equals(other.Type) )); }