예제 #1
0
파일: Reversi.cs 프로젝트: Xeltica/reversi
    public void Place(VectorInt location)
    {
        var turnables = GetTurnableStones(location);

        if (turnables.Count == 0)
        {
            throw new ArgumentException(null, nameof(location));
        }

        Board[location.X, location.Y]          = CurrentStone;
        turnables.ForEach(l => Board[l.X, l.Y] = CurrentStone);

        CurrentStone = CurrentStone.Invert();
        Update();
        if (PlaceableLocations.Length == 0)
        {
            // パス
            CurrentStone = CurrentStone.Invert();
            Update();
            if (PlaceableLocations.Length == 0)
            {
                // ゲームセット
                IsGameSet = true;
            }
        }
    }
예제 #2
0
파일: Reversi.cs 프로젝트: Xeltica/reversi
    private IEnumerable <VectorInt> GetTurnableStones(VectorInt location, VectorInt way)
    {
        var t   = new List <VectorInt>();
        var cur = location;

        cur += way;

        var yourStone       = CurrentStone.Invert();
        var endsWithMyStone = false;

        while (0 <= cur.X && 0 <= cur.Y && cur.X <= 7 && cur.Y <= 7)
        {
            var s = Board[cur.X, cur.Y];
            endsWithMyStone = s == CurrentStone;
            if (s == yourStone)
            {
                t.Add(cur);
            }
            else
            {
                break;
            }

            cur += way;
        }

        return(endsWithMyStone ? t : Array.Empty <VectorInt>());
    }