//左移填满空行 public int[] DoMoveToLeft() { int[] ret = new int[11]; int c; int i; StarsBoard fullBoard = new StarsBoard(); //二值化完整棋盘,用于判定是否为空行 StarsBoard[] tmpBoard = new StarsBoard[5]; //新的棋盘数组 for (c = 0; c <= 4; c++) { fullBoard = fullBoard.Or(_starsBoard[c]); tmpBoard[c] = new StarsBoard(); } //遇到非空行就复制到新的之中 int curidx = 0; for (i = 0; i < 10; i++) { if (!fullBoard.IsEmptyColumn(i)) { for (c = 0; c <= 4; c++) { tmpBoard[c].SetColumn(curidx, System.Convert.ToInt32(_starsBoard[c].GetColumn(i))); } ret[curidx] = i; //记录当前位置存储的是原来的第几列。 curidx++; } } //记录有效个数 ret[10] = curidx; //替换现有引用 _starsBoard = tmpBoard; return(ret); }