Beispiel #1
0
        public Move?GetMove(UserPlayer player, Board board, PiecesColor turnColor)
        {
            var move = player.OnMoveRequest(board, turnColor);

            if (move != null)
            {
                var validationResult = _moveValidationService.Validate(board, turnColor, move);
                player.OnMoveValidated(move, validationResult);

                return(validationResult switch
                {
                    MoveValidationResult.Valid => move,
                    _ => GetMove(player, board, turnColor)
                });
        public List <CpuMove> GetValidCpuMoves(Board board, PiecesColor turnColor)
        {
            var validMoves = new List <CpuMove>();

            foreach (var(piece, srcPos) in board.PiecesPositions[turnColor])
            {
                foreach (var move in GetPotentialDestinations(piece, srcPos)
                         .Select(dstPos => new CpuMove(srcPos, dstPos))
                         .Where(move =>
                                _moveValidationService.Validate(board, turnColor, move)
                                == MoveValidationResult.Valid))
                {
                    move.Value = EvaluateMoveValue(board, move);
                    validMoves.Add(move);
                }
            }

            return(validMoves);
        }