예제 #1
0
        private void OnPartialTurnAdded(PartialTurn partialTurn)
        {
            ClockManager.IncrementTime();
            ClockManager.NextClock();

            Player PlayerForNextPartialTurn = null;

            if (partialTurn.Player == WhitePlayer)
            {
                PlayerForNextPartialTurn = BlackPlayer;
            }
            else if (partialTurn.Player == BlackPlayer)
            {
                PlayerForNextPartialTurn = WhitePlayer;
            }
            EnPassantManager.DisableEnPassantables(PlayerForNextPartialTurn.Alliance);
            Board.SaveBoardState();
        }
예제 #2
0
        public PartialTurnTracker AddPartialTurn(PartialTurn partialTurn)
        {
            Alliance alliance = partialTurn.Player.Alliance;

            if (turns.Count > 0)
            {
                if (alliance == Alliance.White)
                {
                    turns.Add(new Turn(turns.Count + 1, partialTurn));
                }
                else if (alliance == Alliance.Black)
                {
                    turns[turns.Count - 1].BlackTurn = partialTurn;
                }
            }
            else if (turns.Count == 0)
            {
                if (alliance == Alliance.White)
                {
                    FirstWhiteTurn = partialTurn;
                }
                else if (alliance == Alliance.Black)
                {
                    turns.Add(new Turn(turns.Count + 1, FirstWhiteTurn, partialTurn));
                }
            }
            OnPartialTurnAdded(partialTurn);

            Player PlayerForNextPartialTurn = null;

            if (partialTurn.Player == WhitePlayer)
            {
                PlayerForNextPartialTurn = BlackPlayer;
            }
            else if (partialTurn.Player == BlackPlayer)
            {
                PlayerForNextPartialTurn = WhitePlayer;
            }

            return(new PartialTurnTracker(PlayerForNextPartialTurn, ClockManager.GetCurrentClock(), Board.CurrentState));
        }
예제 #3
0
파일: Turn.cs 프로젝트: Beeboh/Chess
 public Turn(int number, PartialTurn whiteTurn, PartialTurn blackTurn)
 {
     Number    = number;
     WhiteTurn = whiteTurn;
     BlackTurn = blackTurn;
 }
예제 #4
0
        public void SelectTile(Tile selectedtile)
        {
            if (selectedtile != null)
            {
                if (!selectedtile.IsVacant && selectedtile.Piece.Alliance == Player.Alliance)
                {
                    if (SelectedPiece != null)
                    {
                        BoardState[SelectedPiece.Row, SelectedPiece.Column].SetTint(Color.White);
                    }
                    SelectedPiece = selectedtile.Piece;
                    selectedtile.SetTint(Color.LightBlue);
                }
                else if (SelectedPiece != null)
                {
                    ReadOnlyCollection <Move> CandidateMoves = SelectedPiece.GetCandidateMoves(BoardState);
                    BoardState CopiedBoard         = BoardState.GetCopy();
                    ChessPiece CopiedSelectedPiece = CopiedBoard[SelectedPiece.Row, SelectedPiece.Column].Piece;
                    ReadOnlyCollection <Move> CopiedCandidateMoves = CopiedSelectedPiece.GetCandidateMoves(CopiedBoard);

                    List <Move> CopiedNonLegalMoves = new List <Move>();
                    foreach (Move CopiedCandidateMove in CopiedCandidateMoves)
                    {
                        CopiedCandidateMove.Execute();
                        bool LegalMove = true;
                        List <ChessPiece> OpponentPieces = new List <ChessPiece>();
                        foreach (Tile tile in CopiedBoard.Tiles)
                        {
                            if (!tile.IsVacant)
                            {
                                if (tile.Piece.Alliance != CopiedSelectedPiece.Alliance)
                                {
                                    OpponentPieces.Add(tile.Piece);
                                }
                            }
                        }
                        foreach (ChessPiece OpponentPiece in OpponentPieces)
                        {
                            ReadOnlyCollection <Move> OpponentCandidateMoves = OpponentPiece.GetCandidateMoves(CopiedBoard);
                            foreach (Move OpponentCandidateMove in OpponentCandidateMoves)
                            {
                                if (OpponentCandidateMove is BasicCaptureMove)
                                {
                                    BasicCaptureMove captureMove = OpponentCandidateMove as BasicCaptureMove;
                                    if (captureMove.CapturedPiece is King)
                                    {
                                        LegalMove = false;
                                    }
                                }
                                if (!LegalMove)
                                {
                                    break;
                                }
                            }
                            if (!LegalMove)
                            {
                                break;
                            }
                        }
                        if (!LegalMove)
                        {
                            CopiedNonLegalMoves.Add(CopiedCandidateMove);
                        }
                        CopiedCandidateMove.Undo();
                    }
                    List <Move> LegalMoves = CandidateMoves.ToList();
                    foreach (Move CopiedNonLegalMove in CopiedNonLegalMoves)
                    {
                        Move NonLegalMove = CandidateMoves.Where(m => m.TargetTile.Row == CopiedNonLegalMove.TargetTile.Row && m.TargetTile.Column == CopiedNonLegalMove.TargetTile.Column).FirstOrDefault();
                        LegalMoves.Remove(NonLegalMove);
                    }

                    Move SelectedMove = LegalMoves.Where(m => m.Piece == SelectedPiece && m.TargetTile == selectedtile).FirstOrDefault();
                    if (SelectedMove != null)
                    {
                        BoardState[SelectedPiece.Row, SelectedPiece.Column].SetTint(Color.White);
                        SelectedMove.Execute();
                        PartialTurn = new PartialTurn(Player, SelectedMove, StartTime, Clock.Time);
                    }
                    else
                    {
                        BoardState[SelectedPiece.Row, SelectedPiece.Column].SetTint(Color.White);
                        SelectedPiece = null;
                    }
                }
            }
        }
예제 #5
0
파일: Turn.cs 프로젝트: Beeboh/Chess
 public Turn(int number, PartialTurn whiteTurn)
 {
     Number    = number;
     WhiteTurn = whiteTurn;
 }