public GameRules.MoveOutcomes applyMove(Move m, GameRules rules) // move must be legal { // apply the movement m.movingPiece.pos = m.ToCoord; this.PiecesLayout[m.FromCoord.X, m.FromCoord.Y] = null; this.PiecesLayout[m.ToCoord.X, m.ToCoord.Y] = null; // using a single battle function allows for easier customization // if a battle took place at all, reveal the pieces if (m.movingPiece != null && m.opponentPiece != null) { m.movingPiece.turnRevealed = TurnNumber; } if (m.opponentPiece != null) { m.opponentPiece.turnRevealed = TurnNumber; } m.outcome = rules.BattleFunction(m.movingPiece, m.opponentPiece); switch (m.outcome) { case GameRules.MoveOutcomes.Move: this.PiecesLayout[m.ToCoord.X, m.ToCoord.Y] = m.movingPiece; break; case GameRules.MoveOutcomes.Win: this.PiecesLayout[m.ToCoord.X, m.ToCoord.Y] = m.movingPiece; // remove the opponent m.opponentPiece.pos = Piece.removedPos; PieceSet.Remove(m.opponentPiece); break; case GameRules.MoveOutcomes.Lose: this.PiecesLayout[m.ToCoord.X, m.ToCoord.Y] = m.opponentPiece; // remove our piece m.movingPiece.pos = Piece.removedPos; PieceSet.Remove(m.movingPiece); break; case GameRules.MoveOutcomes.Tie: // remove the opponent m.opponentPiece.pos = Piece.removedPos; PieceSet.Remove(m.opponentPiece); // remove our piece m.movingPiece.pos = Piece.removedPos; PieceSet.Remove(m.movingPiece); break; } return(m.outcome); }
/// <summary> /// Wraps the piece type's check for winner and adds if the piece is revealed /// </summary> /// <param name="opponent"></param> /// <returns></returns> public GameRules.MoveOutcomes PredictWinner(Piece opponent, GameRules rules) { if (opponent == null) { return(GameRules.MoveOutcomes.Move); } if (opponent.IsRevealed) { return(rules.BattleFunction(this, opponent)); } // TODO CHANGE winner determiniation function according to controller // according to minimax rules, if we dont know we should assume a loss return(GameRules.MoveOutcomes.Lose); }