예제 #1
0
    void BuildCriticalMove(ChessBoard board)
    {
        var tempBuild = new BuildedData();


        for (int i = 0; i < SequenceCount; ++i)
        {
            var single = this[i];
            for (int j = 0; j < single.Count; ++j)
            {
                var action = owner.MoveTo(single[j]);


                tempBuild.Rebuild(board);


                if (tempBuild.IsChecked(owner.Team))
                {
                    single.RemoveAt(j);
                    j -= 1;
                }

                action.Undo();
            }
        }
    }
예제 #2
0
    void GenericAction()
    {
        Func <MoveSequence, int> getMovableCount = (seq) => {
            int count = 0;

            for (int i = 0; i < seq.SequenceCount; ++i)
            {
                var single = seq[i];
                count += single.Count;
            }

            return(count);
        };

        SwitchActionTeam();
        buildedData.Rebuild(board);

        var currentTeams = from Pieces p in board.GetPieces()
                           where p.Team == actionTeam
                           select p;

        int movableCount = 0;

        foreach (var p in board.GetPieces())
        {
            if (p?.Team == actionTeam)
            {
                var seq = p.QueryMovable(MoveType.StandardMove);
                seq.Build(board, MoveType.StandardMove);
                movableCount += getMovableCount(seq);

                seq = p.QueryMovable(MoveType.Attack);
                seq.Build(board, MoveType.Attack);
                movableCount += getMovableCount(seq);

                if (p is Pawn k)
                {
                    seq           = k.QueryEnpassant(board);
                    movableCount += getMovableCount(seq);
                }
            }
        }

        if (movableCount == 0)
        {
            if (buildedData.IsChecked(actionTeam))
            {
                GameoverEvent?.Invoke(this, GameoverType.Checkmate);
            }
            else
            {
                GameoverEvent?.Invoke(this, GameoverType.Stalemate);
            }
        }
    }