コード例 #1
0
ファイル: Simulator.cs プロジェクト: Puddler/Chess
 public Simulator(Move move)
 {
     this.Move = move;
     this.OldPiece = move.EndPosition.Piece;
     This.Game.MakeMove(move);
     This.Board.ResetLegalMoves();
 }
コード例 #2
0
ファイル: Player.cs プロジェクト: Puddler/Chess
 public void SetCurrentMove(Move move)
 {
     this._manualUpdate = false;
     this.CurrentMove = move;
     this._manualUpdate = true;
 }
コード例 #3
0
ファイル: Player.cs プロジェクト: Puddler/Chess
        public void GoToMove(Move gotoMove)
        {
            this._manualUpdate = false;
            Move currentMove = this.CurrentMove != null ? this.CurrentMove : this.PreviousMove;
            if (this.Moves.IndexOf(currentMove) >= this.Moves.IndexOf(gotoMove))
            {
                while (true)
                {
                    Move move = This.Game.OppositePlayer.CurrentMove;
                    if (move == gotoMove) break;

                    This.Game.TempMoves.Add(move);
                    Move oppositeMove = move.OppositeMove();
                    This.Game.MakeMove(oppositeMove);
                    This.Game.OppositePlayer.SetCurrentMove(null);
                    This.Board[oppositeMove.StartPosition.File][oppositeMove.StartPosition.Rank].Piece = oppositeMove.StartPosition.Piece;
                    if (oppositeMove.StartPosition.Piece != null) This.Game.CurrentPlayer.Materials.Add(This.Board[oppositeMove.StartPosition.File][oppositeMove.StartPosition.Rank].Piece);
                    if (This.Game.CurrentPlayer.PreviousMove != null)
                    {
                        This.Game.CurrentPlayer.SetCurrentMove(This.Game.CurrentPlayer.PreviousMove);
                        int index = This.Game.CurrentPlayer.Moves.IndexOf(This.Game.CurrentPlayer.PreviousMove);
                        if (index > 0) This.Game.CurrentPlayer.PreviousMove = This.Game.CurrentPlayer.Moves[index - 1];
                        else This.Game.CurrentPlayer.PreviousMove = null;
                    }
                    This.Game.CurrentPlayer = This.Game.OppositePlayer;
                    This.Board.ResetLegalMoves();
                    This.Board.ResetBoardColors();
                    This.Board.StartSquare = null;
                }
            }
            else
            {
                while(true)
                {
                    Move move = This.Game.TempMoves[This.Game.TempMoves.Count - 1];
                    This.Game.TempMoves.Remove(move);
                    This.Game.MakeMove(move);
                    if (move.EndPosition.Piece != null)
                    {
                        This.Game.OppositePlayer.CapturedMaterials.Add(move.EndPosition.Piece);
                        This.Game.OppositePlayer.Materials.Remove(move.EndPosition.Piece);
                    }
                    This.Game.CurrentPlayer.SetCurrentMove(move);
                    This.Game.CurrentPlayer = This.Game.OppositePlayer;
                    This.Game.CurrentPlayer.PreviousMove = This.Game.CurrentPlayer.CurrentMove;
                    This.Game.CurrentPlayer.SetCurrentMove(null);
                    This.Board.ResetLegalMoves();
                    This.Board.ResetBoardColors();
                    This.Board.StartSquare = null;

                    if (move == gotoMove) break;
                }
            }
            this._manualUpdate = true;
        }
コード例 #4
0
ファイル: Player.cs プロジェクト: Puddler/Chess
 public void RemoveMove(Move move)
 {
     this._manualUpdate = false;
     this.Moves.Remove(move);
     this._manualUpdate = true;
 }
コード例 #5
0
ファイル: BoardSquareVM.cs プロジェクト: Puddler/Chess
        private void ClickExecute()
        {
            if (This.Bot == null) return;
            if (This.Game.CurrentPlayer == null || This.Game.CurrentPlayer.KingStatus == KingStatus.Mate || This.Game.OppositePlayer.KingStatus == KingStatus.Mate) return;
            if (This.Board.StartSquare == null || (this.Piece != null && This.Board.StartSquare.Piece != null && This.Board.StartSquare.Piece.Material.MatchesColor(this.Piece.Material)))
            {
                if (this.Piece != null && this.Piece.Material.CorrectPiece(This.Game.CurrentPlayer))
                {
                    This.Board.ResetBoardColors();
                    foreach (Move move in this.Piece.LegalMoves)
                    {
                        if (move.EndPosition.Piece == null) move.EndPosition.Color = System.Windows.Media.Brushes.Yellow;
                        else move.EndPosition.Color = System.Windows.Media.Brushes.Red;
                    }
                    This.Board.StartSquare = this;
                }
            }
            else if (This.Board.StartSquare != this)
            {
                if (This.Board.StartSquare.Piece.LegalMoves.FirstOrDefault(m => m.EndPosition.Rank == this.Rank && m.EndPosition.File == this.File) != null)
                {
                    This.Game.ClearUnusedMoves();
                    Move move = new Move(This.Board.StartSquare, this);
                    Move clone = move.Clone();
                    This.Game.OppositePlayer.PreviousMove = This.Game.OppositePlayer.CurrentMove;
                    This.Game.OppositePlayer.SetCurrentMove(null);
                    This.Game.CurrentPlayer.SetCurrentMove(clone);
                    if (move.EndPosition.Piece != null)
                    {
                        This.Game.OppositePlayer.CapturedMaterials.Add(move.EndPosition.Piece);
                        This.Game.OppositePlayer.Materials.Remove(move.EndPosition.Piece);
                    }
                    This.Game.CurrentPlayer.Moves.Add(clone);
                    This.Game.MakeMove(move);
                    This.Game.TempMoves.Clear();
                    This.Game.CurrentPlayer = This.Game.OppositePlayer;
                    This.Board.ResetLegalMoves();
                    This.Board.ResetBoardColors();
                    This.Board.StartSquare = null;

                    if (This.Game.CurrentPlayer.Team == Team.Black && This.Game.CurrentPlayer.KingStatus != KingStatus.Mate)
                    {
                        Dispatcher.CurrentDispatcher.Invoke(new Action(() => Thread.Sleep(1)), DispatcherPriority.Render, null);
                        Move nextMove = This.Bot.SelectNextMove();
                        DateTime start = DateTime.Now;
                        TimeSpan span = DateTime.Now.Subtract(start);
                        while (DateTime.Now.Subtract(start).TotalMilliseconds < 1000) Dispatcher.CurrentDispatcher.Invoke(new Action(() => Thread.Sleep(1)), DispatcherPriority.Render, null);
                        This.Board[nextMove.StartPosition.File][nextMove.StartPosition.Rank].ClickCommand.Execute(null);
                        This.Board[nextMove.EndPosition.File][nextMove.EndPosition.Rank].ClickCommand.Execute(null);
                    }
                }
                else
                {
                    This.Board.StartSquare = null;
                    This.Board.ResetBoardColors();
                }
            }
        }