예제 #1
0
파일: Board.cs 프로젝트: rudskoy/kontur_old
		public Move(Board board, Location from, Location to, CellContent oldDestinationCell)
		{
			this.board = board;
			this.from = from;
			this.to = to;
			this.oldDestinationCell = oldDestinationCell;
		}
예제 #2
0
        // Определяет мат, шах или пат белым.
        public string GetStringForWhiteKing(StreamReader reader)
        {
            _board = new Board(reader);

            var isWhiteKingUnderAttack = IsWhiteKingUnderAttack();
            var whiteKingHasMoves = WhiteKingSafeMone();
            return GetStrinForWhiteKingResult(isWhiteKingUnderAttack, whiteKingHasMoves);
        }
예제 #3
0
        public string GetWhiteKingStatus(Board board)
        {
            var whiteKingHasCheck = WhiteKingHasCheck(board);
            var whiteHasSafeMoves = WhiteHasSafeMoves(board);

            if (whiteKingHasCheck)
                return whiteHasSafeMoves ? "check" : "mate";

            return whiteHasSafeMoves ? "ok" : "stalemate";
        }
예제 #4
0
        private bool WhiteHasSafeMoves(Board board)
        {
            foreach (var pieceLocation in board.GetPieces(PieceColor.White))
            {
                if (board.Get(pieceLocation).Piece.GetMoves(pieceLocation, board).Any(moveTo => IsSafeMove(board, pieceLocation, moveTo)))
                {
                    return true;
                }
            }

            return false;
        }
예제 #5
0
 private bool WhiteKingHasCheck(Board board)
 {
     foreach (var location in board.GetPieces(PieceColor.Black))
     {
         var cell = board.Get(location);
         var moves = cell.Piece.GetMoves(location, board);
         if (moves.Any(destination => board.Get(destination).Is(PieceColor.White, Piece.King)))
         {
             return true;
         }
     }
     return false;
 }
예제 #6
0
파일: Piece.cs 프로젝트: rudskoy/kontur_old
		private static IEnumerable<Location> MovesInOneDirection(Location from, Board board, Location dir, bool infinit)
		{
			CellContent fromCellContent = board.Get(from);
			for (int i = 1; i < (infinit ? 8 : 2); i++)
			{
				var to = new Location(from.X + dir.X*i, from.Y + dir.Y*i);
				if (!to.InBoard) break;
				CellContent toCellContent = board.Get(to);
				if (toCellContent.Piece == null) yield return to;
				else
				{
					if (toCellContent.Color != fromCellContent.Color) yield return to;
					yield break;
				}
			}
		}
예제 #7
0
        private bool IsSafeMove(Board board, Location pieceLocation, Location moveTo)
        {
            var oldLocation = board.Get(moveTo);

            try
            {
                board.Set(moveTo, board.Get(pieceLocation));
                board.Set(pieceLocation, CellContent.Empty);
                return !WhiteKingHasCheck(board);
            }
            finally
            {
                board.Set(pieceLocation, board.Get(moveTo));
                board.Set(moveTo, oldLocation);
            }
        }
예제 #8
0
파일: Chess.cs 프로젝트: rudskoy/kontur_old
		public static void LoadFrom(StreamReader reader)
		{
			board = new Board(reader);
		}
예제 #9
0
 public void Load(StreamReader reader)
 {
     board = new Board(reader);
 }
예제 #10
0
파일: Piece.cs 프로젝트: rudskoy/kontur_old
		public IEnumerable<Location> GetMoves(Location location, Board board)
		{
			return ds.SelectMany(d => MovesInOneDirection(location, board, d, infinit));
		}
예제 #11
0
파일: Chess.cs 프로젝트: Vedmax/01-quality
 public Chess(StreamReader reader)
 {
     board = new Board(reader);
 }