/// <summary> /// The event handler for OnPieceMove. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void Board_OnPieceMove(object sender, PieceMovedEventArgs e) { var move = Bitboard.Moves.FirstOrDefault(p => p.From == e.From && p.To == e.To); switch (move) { case null: { CalculateBitboard(new QuietMove(e.From, e.To, e.Piece.Type, e.Piece.Color), _quiescenceSearch); break; } case PromotionMove _: { var promotionMoves = Bitboard.Moves.OfType <PromotionMove>().Where(p => p.From == move.From && p.To == move.To); PromotionWindow.Display(move.Color, promotionMoves); break; } default: { CalculateBitboard(move, _quiescenceSearch); break; } } }
/// <summary> /// Processes all events related to mouse and keyboard. /// </summary> /// <param name="inputManager">InputManager instance.</param> public virtual void Input(InputManager inputManager) { if (!PromotionWindow.Active) { VisualBoard.Input(inputManager); } PromotionWindow.Input(inputManager); }
/// <summary> /// Initializes a new instance of the <see cref="GameModeBase"/> class. /// </summary> /// <param name="consoleManager">The console manager instance</param> /// <param name="commandsManager">The commands manager instance</param> protected GameModeBase(ConsoleManager consoleManager, CommandsManager commandsManager) { ConsoleManager = consoleManager; CommandsManager = commandsManager; PiecesProvider = new PiecesProvider(); VisualBoard = new VisualBoard(PiecesProvider); PromotionWindow = new PromotionWindow(PiecesProvider); SetCommandHandlers(); }
/// <summary> /// The event handler for OnPieceMove. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void Board_OnPieceMove(object sender, PieceMovedEventArgs e) { if (!_done && _currentColor == _playerColor && e.Piece != null && e.Piece.Color == _currentColor) { var enemyColor = ColorOperations.Invert(_currentColor); var move = Bitboard.Moves.FirstOrDefault(p => p.From == e.From && p.To == e.To); if (move == null) { return; } var testBitboard = Bitboard.Move(move); testBitboard.Calculate(false); if (testBitboard.IsCheck(_currentColor)) { ConsoleManager.WriteLine("$RInvalid move"); return; } switch (move) { case PromotionMove _: { var promotionMoves = Bitboard.Moves.OfType <PromotionMove>().Where(p => p.From == move.From && p.To == move.To); PromotionWindow.Display(move.Color, promotionMoves); break; } default: { CalculateBitboard(move, false); break; } } CheckIfGameHasEnded(Bitboard); _currentColor = ColorOperations.Invert(_currentColor); _history.Add(move); MoveAI(); } }
public static PromotionWindow Show() { if (instance != null) return null; Debug.Log ("PromotionWindowShow"); Transform canvas = GameObject.Find ("Canvas").transform; GameObject prefab = Resources.Load<GameObject> ("PromotionWindow"); GameObject go = Instantiate (prefab) as GameObject; go.transform.SetParent (canvas, false); instance = go.GetComponent<PromotionWindow> (); go.SetActive (false); return instance; }
public static PromotionWindow Show() { if (instance != null) { return(null); } Debug.Log("PromotionWindowShow"); Transform canvas = GameObject.Find("Canvas").transform; GameObject prefab = Resources.Load <GameObject> ("PromotionWindow"); GameObject go = Instantiate(prefab) as GameObject; go.transform.SetParent(canvas, false); instance = go.GetComponent <PromotionWindow> (); go.SetActive(false); return(instance); }
IEnumerator PromotionCoroutine(Piece get) { //Vector2 pos = this.Tile; PromotionWindow window = PromotionWindow.Show(); window.Init(this); while (PromotionWindow.IsShowing) { yield return(null); } //yield return null; //if (Tile != pos) { // Move(pos, false); //} ShogiNetwork.Instance.UpdatePieces(this, get); History history = History.Instance; List <Piece> eq = PieceController.Instance.FindMyEqualPieces(this); //bool isExistPieceMoveableSamePlace = false; List <Piece> same = null; if (eq != null) { foreach (Piece p in eq) { if (p.IsMoveable(this.Tile)) { //isExistPieceMoveableSamePlace = true; if (same == null) { same = new List <Piece>(); } same.Add(p); } } } history.Add(this, same); Owner.Act(); }
/// <summary> /// Makes a move on chess board /// </summary> /// <returns></returns> public void MakeMove(int index, bool useLog) { if (CurrentPiece != null) { AssignCellBlackBorder(); PiecePossibleMove move = CurrentPiecePossibleMoves.Where(m => (int)(m.MoveToPosition.Y * 8 + m.MoveToPosition.X) == index).Single(); BasePiece promotionPiece = null; if (CurrentPiece is Pawn && (Board[index].Position.Y == 0 || Board[index].Position.Y == 7)) { PromotionWindow dialog = new PromotionWindow(CurrentPiece.IsWhite); if (dialog.ShowDialog() == true) { promotionPiece = dialog.SelectedPiece; } } Move madeMove = new Move(move, CurrentPiece, Board[index].Piece, promotionPiece); HistoryOfMoves.Add(madeMove); madeMove.MakeMove(ref Board); LastMadeMove = madeMove.CopyMove(); if (madeMove.IsCastlingMove) { hasCastled[madeMove.IsWhiteMove] = true; } bool isWhite = CurrentPiece.IsWhite; CurrentPiece = null; bool isGameOver = IsGameOver(!isWhite); bool isChecked = IsAttacked((Point)FindKingLocation(!isWhite), !isWhite); if (isGameOver) { MessageBox.Show("Game over! " + (isWhite ? "White" : "Black") + " wins!"); GameFinished = true; } if (useLog) { WriteLogMove(isGameOver, isChecked); } } }
/// <summary> /// Loads the resources. Must be called before first use of any other class method. /// </summary> /// <param name="contentManager">Monogame content manager.</param> public virtual void LoadContent(ContentManager contentManager) { PiecesProvider.LoadContent(contentManager); VisualBoard.LoadContent(contentManager); PromotionWindow.LoadContent(contentManager); }
/// <summary> /// Draws board and promotion window (optionally). /// </summary> /// <param name="spriteBatch">Monogame sprite batch.</param> public virtual void Draw(SpriteBatch spriteBatch) { VisualBoard.Draw(spriteBatch); PromotionWindow.Draw(spriteBatch); }
/// <summary> /// Processes all logic related to the base game mode. /// </summary> public virtual void Logic() { VisualBoard.Logic(); PromotionWindow.Logic(); }
/// <summary> /// The event handler for OnPromotionSelection. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void PromotionWindow_OnPromotionSelection(object sender, PromotionSelectedEventArgs e) { CalculateBitboard(e.Move, _quiescenceSearch); PromotionWindow.Hide(); }
public void Close() { Destroy (instance.gameObject); instance = null; }
public void Close() { Destroy(instance.gameObject); instance = null; }