예제 #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 Move PerformMove(Location from, Location to)
 {
     Cell old = Get(to);
     Set(to, Get(from));
     Set(from, Cell.Empty);
     return new Move(this, from, to, old);
 }
예제 #3
0
파일: Chess.cs 프로젝트: Vedmax/01-quality
 private bool HasMoves(Location to, Location @from, Cell old)
 {
     var hasMoves = false;
     board.Set(to, board.Get(@from));
     board.Set(@from, Cell.Empty);
     if (!IsCheck())
         hasMoves = true;
     board.Set(@from, board.Get(to));
     board.Set(to, old);
     return hasMoves;
 }
예제 #4
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;
				}
			}
		}
예제 #5
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);
            }
        }
예제 #6
0
 public void Set(Location location, Cell cell)
 {
     cells[location.X, location.Y] = cell;
 }
예제 #7
0
 public Cell Get(Location location)
 {
     return !location.InBoard ? Cell.Empty : cells[location.X, location.Y];
 }
예제 #8
0
파일: Piece.cs 프로젝트: rudskoy/kontur_old
		public IEnumerable<Location> GetMoves(Location location, Board board)
		{
			return ds.SelectMany(d => MovesInOneDirection(location, board, d, infinit));
		}