/// <summary> /// 一手戻る /// </summary> /// <returns></returns> public bool Back() { // 置ける場所を変更する _possiblePoints1 = null; _possiblePoints2 = null; if (Count > 0) { // Listの最後を除去 _boardList.Remove(_boardList.Last()); Count--; Turn *= -1; var points = GetPossiblePoints(Turn); if (points.Count == 0) //また置ける場所が0だったら { OnPassEvent(this, Turn); } else { Condition = OthelloCondition.Wait; } return(true); } else { return(false); } }
/// <summary> /// 置かずにパスする(置ける場合も実行可能) /// </summary> //フィールドにパスカウントやっといて、2回連続なら判定するように //パスしなければ0に戻すようなかんじ public void Pass() { // 置ける場所を変更する _possiblePoints1 = null; _possiblePoints2 = null; _boardList.Add(Board.Clone() as int[, ]); Count++; Turn *= -1; Condition = OthelloCondition.Wait; }
/// <summary> /// 石を置く /// </summary> /// <param name="point"></param> /// <returns></returns> public bool Put(Point point) { if (Board[point.x, point.y] != 0) //空じゃないなら { return(false); //おけない } // 置ける場所を変更する _possiblePoints1 = null; _possiblePoints2 = null; _boardList.Add(Board.Clone() as int[, ]); Count++; bool putFlag = false; for (int i = 0; i < 8; i++) { if (point.x + Dir[i].x < 0 || point.x + Dir[i].x > 7 || point.y + Dir[i].y < 0 || point.y + Dir[i].y > 7) { continue; } if (Board[point.x + Dir[i].x, point.y + Dir[i].y] == -Turn) //一つ隣が相手の色なら { int k = 1; //ベクトルの係数 while (true) { k++; if (point.x + k * Dir[i].x < 0 || point.x + k * Dir[i].x > 7 || point.y + k * Dir[i].y < 0 || point.y + k * Dir[i].y > 7) { break; } if (Board[point.x + k * Dir[i].x, point.y + k * Dir[i].y] == 0) { break; } if (Board[point.x + k * Dir[i].x, point.y + k * Dir[i].y] == Turn) { putFlag = true; for (; k >= 1; k--) { Board[point.x + k * Dir[i].x, point.y + k * Dir[i].y] = Turn; } break; } } } } if (putFlag) { Board[point.x, point.y] = Turn; Turn *= -1; if (GetPossiblePoints(Turn).Count == 0) { if (GetPossiblePoints(-Turn).Count() == 0) { var bnum = GetDiscNumber(-1); var wnum = GetDiscNumber(1); if (bnum == wnum) { OnEndEvent(this, 0); } else if (wnum < bnum) { OnEndEvent(this, -1); } else { OnEndEvent(this, 1); } } else { OnPassEvent(this, Turn); } } else { Condition = OthelloCondition.Wait; } return(true); } else { _boardList.RemoveAt(_boardList.Count - 1); Count--; return(false); } }