protected override List <BoardIndex> GetMovesInternal(Checker checker, BoardIndex begin, List <BoardIndex> moves)
        {
            Stack <Checker> checkersThatCanBeat = new Stack <Checker>();

            for (int i = 0; i < board.Rows; i++)
            {
                for (int j = 0; j < board.Cols; j++)
                {
                    Checker toTest = board[i, j];
                    if (toTest == null || toTest.PlayerType != checker.PlayerType)
                    {
                        continue;
                    }

                    var otherMoves = beatHandler.GetMoves(new BoardIndex(i, j));
                    if (otherMoves.Count > 0)
                    {
                        checkersThatCanBeat.Push(toTest);
                    }
                }
            }
            if (checkersThatCanBeat.Count == 0 || checkersThatCanBeat.Contains(checker))
            {
                return(Next?.GetMoves(begin, moves) ?? new List <BoardIndex>());
            }
            return(new List <BoardIndex>());
        }
Пример #2
0
        protected override List <BoardIndex> GetMovesInternal(Checker checker, BoardIndex begin, List <BoardIndex> moves)
        {
            if (moves.Count <= 1)
            {
                return(Next?.GetMoves(begin, moves) ?? new List <BoardIndex>());
            }

            if (moves.Count > 1 && HasOpponentInBetween(checker.PlayerType, moves[moves.Count - 2], moves[moves.Count - 1]))
            {
                var beatMoves = beatHandler.GetMoves(begin, moves);
                if (beatMoves.Count == 0)
                {
                    return(new List <BoardIndex>());
                }
                else
                {
                    var from  = moves[moves.Count - 2];
                    var to    = moves[moves.Count - 1];
                    int diffX = to.Row - from.Row;
                    int diffY = to.Col - from.Col;
                    int dx    = Math.Sign(diffX);
                    int dy    = Math.Sign(diffY);
                    int x     = from.Row;
                    int y     = from.Col;
                    while (x != to.Row && y != to.Col)
                    {
                        BoardIndex index = new BoardIndex(x, y);
                        beatMoves.Remove(index);
                        x += dx;
                        y += dy;
                    }
                    return(beatMoves);
                }
            }
            return(new List <BoardIndex>());
        }